rndctl revision 1.1
11.1Sapb#!/bin/sh 21.1Sapb# 31.1Sapb# $NetBSD: rndctl,v 1.1 2009/01/04 12:10:30 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.1Sapb case "${flags}" in 601.1Sapb *[cCeE]*) ;; 611.1Sapb *) flags="${flags} -c -e" ;; 621.1Sapb esac 631.1Sapb case "${flags}" in 641.1Sapb *[dt]*) ;; 651.1Sapb *) flags="${flags} -d" ;; 661.1Sapb esac 671.1Sapb #echo >&2 "${name} DEBUG: running:" \ 681.1Sapb # "$command $flags $arg" 691.1Sapb $command ${flags} ${arg} 701.1Sapb ;; 711.1Sapb esac 721.1Sapb done 731.1Sapb done 741.1Sapb} 751.1Sapb 761.1Sapbload_rc_config $name 771.1Sapbrun_rc_command "$1" 78