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