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