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