diff options
author | Tom Gundersen <teg@jklm.no> | 2011-06-18 22:30:22 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2011-06-18 22:30:22 +0200 |
commit | f5d571110b9cfe45ecb32602510c924409e52d63 (patch) | |
tree | f7738f1b652c909eb6b27103b6b9393e5af563a6 | |
parent | 4cad51425325abf13b7a8772ff09f852238423c2 (diff) | |
parent | 042d197b4d989ec6461204b9d897054e5f5dd492 (diff) | |
download | initscripts-f5d571110b9cfe45ecb32602510c924409e52d63.tar.xz |
Merge remote-tracking branch 'seblu/master'
-rw-r--r-- | bash-completion | 8 | ||||
-rw-r--r-- | functions | 10 | ||||
-rwxr-xr-x | rc.d | 16 | ||||
-rw-r--r-- | zsh-completion | 5 |
4 files changed, 33 insertions, 6 deletions
diff --git a/bash-completion b/bash-completion index 5151972..489b5dc 100644 --- a/bash-completion +++ b/bash-completion @@ -5,15 +5,17 @@ _rc.d () local action="help list start stop reload restart" local cur="${COMP_WORDS[COMP_CWORD]}" local caction="${COMP_WORDS[1]}" - if ((${COMP_CWORD} == 1)); then + if ((COMP_CWORD == 1)); then COMPREPLY=($(compgen -W "${action}" -- "$cur")) - elif [[ "$caction" =~ help|list ]]; then + elif [[ "$caction" == help ]]; then COMPREPLY=() + elif [[ "$caction" == list ]]; then + ((COMP_CWORD == 2)) && COMPREPLY=($(compgen -W "started stopped" -- "$cur")) || COMPREPLY=() elif [[ "$caction" == start ]]; then COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort))) elif [[ "$caction" =~ stop|restart|reload ]]; then COMPREPLY=($(cd /run/daemons/ && compgen -f "$cur"|sort)) - elif ((${COMP_CWORD} > 1)); then + elif ((COMP_CWORD > 1)); then COMPREPLY=($(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort)) fi } @@ -394,5 +394,15 @@ for f in /etc/rc.d/functions.d/*; do [[ -e $f ]] && . "$f" done +# Exit current shell if user is not root +need_root() { + (( $EUID != 0 )) && printf 'You need to be root.\n' && exit 1 +} + +# Quit script if it's not running by root +# This can be disabled in scripts sourcing functions by setting NEED_ROOT=0 +# A local call to need_root can be done to ensure part of script need root privilege +(( ${NEED_ROOT:-1} == 1 )) && need_root + # End of file # vim: set ts=2 sw=2 noet: @@ -1,14 +1,22 @@ #!/bin/bash +NEED_ROOT=0 # this script can be run without be root . /etc/rc.conf . /etc/rc.d/functions usage() { local name=${0##*/} cat >&2 << EOF -usage: $name action daemon ... +usage: $name <action> <daemon> [daemon] ... + $name list [started|stopped] + $name help + +<daemon> is the name of a script in /etc/rc.d +<action> can be a start, stop, restart, reload, status, ... +WARNING: initscripts are free to implement or not the above actions. e.g: $name list + $name list started $name help $name start sshd gpm EOF @@ -23,13 +31,16 @@ case $1 in usage ;; list) + shift cd /etc/rc.d/ for d in *; do have_daemon "$d" || continue # print running / stopped satus if ! ck_daemon "$d"; then + [[ "$1" == stopped ]] && continue printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" else + [[ "$1" == started ]] && continue printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" fi # print auto / manual status @@ -40,7 +51,7 @@ case $1 in fi printf " ${C_CLEAR}$d\n" done - ;; + ;; *) # check min args count (( $# < 2 )) && usage @@ -62,6 +73,7 @@ case $1 in fi (( ret += !! $? )) # clamp exit value to 0/1 done + ;; esac exit $ret diff --git a/zsh-completion b/zsh-completion index f1b7165..e5c2850 100644 --- a/zsh-completion +++ b/zsh-completion @@ -15,9 +15,12 @@ _rc.d () { curcontext="${curcontext%:*:*}:rc.d-${action}:" case $action in - list|help) + help) _arguments "*: :" ;; + list) + _arguments "2: :(started stopped)" + ;; start) _arguments "*: :($(comm -23 <(echo /etc/rc.d/*(N-*:t)|tr ' ' '\n') <(echo /run/daemons/*(N:t)|tr ' ' '\n')))" ;; |