#!/bin/sh # Source shlib _root="$(dirname "${0}")/.."; . "${_root}/lib/sh/env.sh" want ansi log . /etc/rc.subr load_rc_config 'XXX' pebkac() { log "Usage: $(basename "${0}") [rcscript]" log "" log " can be one of:" log " list - List all available rcscripts" log " status - Show status for all rcscripts" log "" log " started" log " running" log " on - List all currently running scripts" log "" log " stopped" log " off - List all currently stopped scripts" log "" log "You can also send a command to any rcscript with the following form:" log " $(basename "${0}") [rcscript]" log "" log "For example, the following is equivalent to running '/etc/rc.d/ppp stop':" log " $(basename "${0}") stop ppp" log "" exit 1 } # All startup directories rc_dirs() { for dir in /etc/rc.d ${local_startup} do [ -d "${dir}" ] && echo "${dir}"'/*' done } # List all available rc scripts rc_list() { ls -1 $(rc_dirs) | egrep -v '/(DAEMON|FILESYSTEMS|LOGIN|NETWORKING|SERVERS)$' | sort } # Get the status of one script rc_status() { # 1: script [ -x "${file}" ] && "${file}" status > /dev/null 2>&1 } # Get the status of all scripts rc_statii() { # 1: command # Parse action case "${1}" in list) rc_list | sed -e 's/^.*\///'; return ;; started|running|on) want="1" ;; stopped|off) want="0" ;; *) ;; esac # List scripts rc_list | while read file do name="$(basename "${file}")" if rc_status "${file}" then [ ! "${want}" -o "${want}" = "1" ] && log "${a_green}running${a_normal}: ${name}" else [ ! "${want}" -o "${want}" = "0" ] && log "${a_red}stopped${a_normal}: ${name}" fi done } # Perform an action on the script rc_action() { # 1: action # 2: nameglob want root rc_list | grep "/${2}$" | while read rcd; do "${rcd}" "${1}"; done } case "${#}" in 1) rc_statii "${1}" ;; 2) rc_action "${1}" "${2}" ;; *) pebkac ;; esac