rndctl revision 1.1 1 #!/bin/sh
2 #
3 # $NetBSD: rndctl,v 1.1 2009/01/04 12:10:30 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 case "${flags}" in
60 *[cCeE]*) ;;
61 *) flags="${flags} -c -e" ;;
62 esac
63 case "${flags}" in
64 *[dt]*) ;;
65 *) flags="${flags} -d" ;;
66 esac
67 #echo >&2 "${name} DEBUG: running:" \
68 # "$command $flags $arg"
69 $command ${flags} ${arg}
70 ;;
71 esac
72 done
73 done
74 }
75
76 load_rc_config $name
77 run_rc_command "$1"
78