]> CyberLeo.Net >> Repos - CDN/.attic/freebsd-rc.git/blob - bin/rc
Initial import
[CDN/.attic/freebsd-rc.git] / bin / rc
1 #!/bin/sh
2
3 # Source shlib
4 _root="$(dirname "${0}")/.."; . "${_root}/lib/sh/env.sh"
5 want root ansi log
6
7 . /etc/rc.subr
8
9 load_rc_config 'XXX'
10
11 pebkac() {
12   log "Usage: $(basename "${0}") <command> [rcscript]"
13   log ""
14   log "<command> can be one of:"
15   log " list    - List all available rcscripts"
16   log " status  - Show status for all rcscripts"
17   log ""
18   log " started"
19   log " running"
20   log " on      - List all currently running scripts"
21   log ""
22   log " stopped"
23   log " off     - List all currently stopped scripts"
24   log ""
25   log "You can also send a command to any rcscript with the following form:"
26   log " $(basename "${0}") <command> [rcscript]"
27   log ""
28   log "For example, the following is equivalent to running '/etc/rc.d/ppp stop':"
29   log " $(basename "${0}") stop ppp"
30   log ""
31   exit 1
32 }
33
34 # List all available rc scripts
35 rc_list() {
36   ls -1 /etc/rc.d/* "${local_startup}"/* | egrep -v '/(DAEMON|FILESYSTEMS|LOGIN|NETWORKING|SERVERS)$' | sort
37 }
38
39 # Get the status of one script
40 rc_status() {
41   # 1: script
42   [ -x "${file}" ] && "${file}" status > /dev/null 2>&1
43 }
44
45 # Get the status of all scripts
46 rc_statii() {
47   # 1: command
48   
49   # Parse action
50   case "${1}" in
51   list) rc_list | sed -e 's/^.*\///'; return ;;
52   started|running|on) want="1" ;;
53   stopped|off) want="0" ;;
54   *) ;;
55   esac
56   
57   # List scripts
58   rc_list | while read file
59   do
60     name="$(basename "${file}")"
61     if rc_status "${file}"
62     then
63       [ ! "${want}" -o "${want}" = "1" ] && log "${a_green}running${a_normal}: ${name}"
64     else
65       [ ! "${want}" -o "${want}" = "0" ] && log "${a_red}stopped${a_normal}: ${name}"
66     fi
67   done
68 }
69
70 # Perform an action on the script
71 rc_action() {
72   # 1: action
73   # 2: nameglob
74   rc_list | grep "/${2}$" | while read rcd; do "${rcd}" "${1}"; done
75 }
76
77 case "${#}" in
78 1) rc_statii "${1}" ;;
79 2) rc_action "${1}" "${2}" ;;
80 *) pebkac ;;
81 esac