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