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