]> CyberLeo.Net >> Repos - CDN/.attic/freebsd-rc.git/blob - rc
Want root only for commanding rcscripts; don't force it
[CDN/.attic/freebsd-rc.git] / rc
1 #!/bin/sh
2
3 # Source shlib
4 _root="$(dirname "${0}")/.."; . "${_root}/lib/sh/env.sh"
5 want 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 # All startup directories
35 rc_dirs() {
36   for dir in /etc/rc.d ${local_startup}
37   do
38     [ -d "${dir}" ] && echo "${dir}"'/*'
39   done
40 }
41
42 # List all available rc scripts
43 rc_list() {
44   ls -1 $(rc_dirs) | egrep -v '/(DAEMON|FILESYSTEMS|LOGIN|NETWORKING|SERVERS)$' | sort
45 }
46
47 # Get the status of one script
48 rc_status() {
49   # 1: script
50   [ -x "${file}" ] && "${file}" status > /dev/null 2>&1
51 }
52
53 # Get the status of all scripts
54 rc_statii() {
55   # 1: command
56   
57   # Parse action
58   case "${1}" in
59   list) rc_list | sed -e 's/^.*\///'; return ;;
60   started|running|on) want="1" ;;
61   stopped|off) want="0" ;;
62   *) ;;
63   esac
64   
65   # List scripts
66   rc_list | while read file
67   do
68     name="$(basename "${file}")"
69     if rc_status "${file}"
70     then
71       [ ! "${want}" -o "${want}" = "1" ] && log "${a_green}running${a_normal}: ${name}"
72     else
73       [ ! "${want}" -o "${want}" = "0" ] && log "${a_red}stopped${a_normal}: ${name}"
74     fi
75   done
76 }
77
78 # Perform an action on the script
79 rc_action() {
80   # 1: action
81   # 2: nameglob
82   want root
83   rc_list | grep "/${2}$" | while read rcd; do "${rcd}" "${1}"; done
84 }
85
86 case "${#}" in
87 1) rc_statii "${1}" ;;
88 2) rc_action "${1}" "${2}" ;;
89 *) pebkac ;;
90 esac