1#!/bin/sh 2# 3# $NetBSD: rndctl,v 1.3 2009/04/21 16:08:57 joerg Exp $ 4# 5 6# PROVIDE: rndctl 7# BEFORE: DISKS ike ipsec sshd 8# REQUIRE: wdogctl 9 10$_rc_subr_loaded . /etc/rc.subr 11 12name="rndctl" 13rcvar=$name 14command="/sbin/${name}" 15 16start_cmd="rndctl_startcmd" 17 18rndctl_startcmd() 19{ 20 # $rndctl_flags can contain multiple semicolon-separated 21 # segments in which each segment contains optional flags 22 # followed by one or more device or type names. If none of the 23 # -c/-C/-e/-E flags is specified, then "-c -e" is used. If 24 # neither of the -d/-t flags is specified, then "-d" is used. 25 # 26 # For example, given 27 # rndctl_flags="wd0 wd1; -t tty; -c -t net" 28 # we will perform the following commands: 29 # rndctl -c -e -d wd0 30 # rndctl -c -e -d wd1 31 # rndctl -c -e -t tty 32 # rndctl -c -t net 33 34 local args arg flags 35 36 # Split $rndctl_flags on semicolons 37 oIFS="$IFS" 38 IFS=';' 39 set -- $rndctl_flags 40 IFS="$oIFS" 41 # The outer "for args" loop cycles once per semicolon-separated 42 # segment; the inner "for arg" loop cycles once per word in a 43 # segment. 44 for args in "$@"; do 45 #echo >&2 "${name} DEBUG: Parsing segment: $args"; 46 flags='' 47 for arg in ${args}; do 48 case "${arg}" in 49 -*) 50 flags="${flags} ${arg}" 51 ;; 52 *) 53 # We have a device or type name. 54 # If none of -c/-C/-e/-E flags was 55 # specified, add "-c -e". If neither 56 # of -d/-t was specified, add "-d". 57 # Then perform the command with the 58 # specified device or type name. 59 # 60 # Note that -d/-t flag must be last. 61 # 62 case "${flags}" in 63 *[cCeE]*) ;; 64 *) flags="-c -e ${flags}" ;; 65 esac 66 case "${flags}" in 67 *[dt]*) ;; 68 *) flags="${flags} -d" ;; 69 esac 70 #echo >&2 "${name} DEBUG: running:" \ 71 # "$command $flags $arg" 72 $command ${flags} ${arg} 73 ;; 74 esac 75 done 76 done 77} 78 79load_rc_config $name 80run_rc_command "$1" 81