From bdcf3c4adcde369555247089539894d18dd88c27 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Sat, 20 Feb 2010 11:18:57 -0600 Subject: [PATCH] Initial import --- bin/rc | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 bin/rc diff --git a/bin/rc b/bin/rc new file mode 100755 index 0000000..e97d70a --- /dev/null +++ b/bin/rc @@ -0,0 +1,81 @@ +#!/bin/sh + +# Source shlib +_root="$(dirname "${0}")/.."; . "${_root}/lib/sh/env.sh" +want root 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 +} + +# List all available rc scripts +rc_list() { + ls -1 /etc/rc.d/* "${local_startup}"/* | 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 + rc_list | grep "/${2}$" | while read rcd; do "${rcd}" "${1}"; done +} + +case "${#}" in +1) rc_statii "${1}" ;; +2) rc_action "${1}" "${2}" ;; +*) pebkac ;; +esac -- 2.42.0