rndctl revision 1.2
11.1Sapb#!/bin/sh
21.1Sapb#
31.2Sapb# $NetBSD: rndctl,v 1.2 2009/02/02 09:24:47 apb Exp $
41.1Sapb#
51.1Sapb
61.1Sapb# PROVIDE: rndctl
71.1Sapb# BEFORE: disks ike ipsec sshd
81.1Sapb
91.1Sapb$_rc_subr_loaded . /etc/rc.subr
101.1Sapb
111.1Sapbname="rndctl"
121.1Sapbrcvar=$name
131.1Sapbcommand="/sbin/${name}"
141.1Sapb
151.1Sapbstart_cmd="rndctl_startcmd"
161.1Sapb
171.1Sapbrndctl_startcmd()
181.1Sapb{
191.1Sapb	# $rndctl_flags can contain multiple semicolon-separated
201.1Sapb	# segments in which each segment contains optional flags
211.1Sapb	# followed by one or more device or type names.  If none of the
221.1Sapb	# -c/-C/-e/-E flags is specified, then "-c -e" is used.  If
231.1Sapb	# neither of the -d/-t flags is specified, then "-d" is used.
241.1Sapb	#
251.1Sapb	# For example, given
261.1Sapb	#	rndctl_flags="wd0 wd1; -t tty; -c -t net"
271.1Sapb	# we will perform the following commands:
281.1Sapb	#	rndctl -c -e -d wd0
291.1Sapb	#	rndctl -c -e -d wd1
301.1Sapb	#	rndctl -c -e -t tty
311.1Sapb	#	rndctl -c -t net
321.1Sapb
331.1Sapb	local args arg flags
341.1Sapb
351.1Sapb	# Split $rndctl_flags on semicolons
361.1Sapb	oIFS="$IFS"
371.1Sapb	IFS=';'
381.1Sapb	set -- $rndctl_flags
391.1Sapb	IFS="$oIFS"
401.1Sapb	# The outer "for args" loop cycles once per semicolon-separated
411.1Sapb	# segment; the inner "for arg" loop cycles once per word in a
421.1Sapb	# segment.
431.1Sapb	for args in "$@"; do
441.1Sapb		#echo >&2 "${name} DEBUG: Parsing segment: $args";
451.1Sapb		flags=''
461.1Sapb		for arg in ${args}; do
471.1Sapb			case "${arg}" in
481.1Sapb				-*)
491.1Sapb					flags="${flags} ${arg}"
501.1Sapb					;;
511.1Sapb				*)
521.1Sapb					# We have a device or type name.
531.1Sapb					# If none of -c/-C/-e/-E flags was
541.1Sapb					# specified, add "-c -e".  If neither
551.1Sapb					# of -d/-t was specified, add "-d".
561.1Sapb					# Then perform the command with the
571.1Sapb					# specified device or type name.
581.1Sapb					#
591.2Sapb					# Note that -d/-t flag must be last.
601.2Sapb					#
611.1Sapb					case "${flags}" in
621.1Sapb					*[cCeE]*) ;;
631.2Sapb					*)	flags="-c -e ${flags}" ;;
641.1Sapb					esac
651.1Sapb					case "${flags}" in
661.1Sapb					*[dt]*) ;;
671.1Sapb					*)	flags="${flags} -d" ;;
681.1Sapb					esac
691.1Sapb					#echo >&2 "${name} DEBUG: running:" \
701.1Sapb					#    "$command $flags $arg"
711.1Sapb					$command ${flags} ${arg}
721.1Sapb					;;
731.1Sapb			esac
741.1Sapb		done
751.1Sapb	done
761.1Sapb}
771.1Sapb
781.1Sapbload_rc_config $name
791.1Sapbrun_rc_command "$1"
80