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