Ah, I was just procrastinating about not having updated the patch to add a manpage for rc.d that I sent a while back. Now it seems I'll have to extend/rewrite it a bit anyway ;) I'll do that as soon as I can, a bit busy finishing up my gsoc work atm. Cheers, Elvis 2011/8/9 Sebastien Luttringer <seblu@seblu.net>:
list command can take new arguments auto/noauto. list command can take a list of daemon to list.
All kind of arguments can be mixed to obtain the proper output.
zsh and bash completion are updated
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- bash-completion | 2 +- rc.d | 65 +++++++++++++++++++++++++++++++++++++----------------- zsh-completion | 2 +- 3 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/bash-completion b/bash-completion index d78484e..718df6d 100644 --- a/bash-completion +++ b/bash-completion @@ -10,7 +10,7 @@ _rc_d() elif [[ "$prev" == help ]]; then COMPREPLY=() elif [[ "$prev" == list ]]; then - ((COMP_CWORD == 2)) && COMPREPLY=($(compgen -W "started stopped" -- "$cur")) || COMPREPLY=() + COMPREPLY=($(compgen -W "started stopped auto noauto $(cd /etc/rc.d && compgen -f -X 'functions*')" -- "$cur")) elif [[ "$prev" == start ]]; then COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort))) elif [[ "$prev" =~ stop|restart|reload ]]; then diff --git a/rc.d b/rc.d index 3d34edf..bb44ae1 100755 --- a/rc.d +++ b/rc.d @@ -4,11 +4,12 @@ NEED_ROOT=0 # this script can be run without be root . /etc/rc.conf . /etc/rc.d/functions
+# print usage and exit usage() { local name=${0##*/} cat >&2 << EOF usage: $name <action> <daemon> [daemon] ... - $name list [started|stopped] + $name list [started|stopped|auto|noauto|daemon] $name help
<daemon> is the name of a script in /etc/rc.d @@ -17,40 +18,62 @@ WARNING: initscripts are free to implement or not the above actions.
e.g: $name list $name list started + $name list sshd gpm $name help $name start sshd gpm EOF exit 1 }
+# list action +list() { + local mode daemons s_status s_auto + # parse arguments + for p; do + case "$p" in + started) mode=started;; + stopped) mode=stopped;; + auto) mode=auto;; + noauto) mode=noauto;; + *) daemons="$daemons $p";; + esac + done + # if no daemon are specified take all + [[ $daemons ]] || daemons=$(cd /etc/rc.d/ && echo *) + # building string to display + for d in $daemons; do + # check if d is a valid daemon name + have_daemon "$d" || continue + # print running / stopped satus + if ! ck_daemon "$d"; then + [[ $mode == stopped ]] && continue + s_status="${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" + else + [[ $mode == started ]] && continue + s_status="${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" + fi + # print auto / manual status + if ! ck_autostart "$d"; then + [[ $mode == noauto ]] && continue + s_auto="${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" + else + [[ $mode == auto ]] && continue + s_auto="${C_OTHER}[${C_FAIL} ${C_OTHER}]" + fi + printf "$s_status$s_auto${C_CLEAR} $d\n" + done +} + (( $# < 1 )) && usage
declare -i ret=0 case $1 in help) 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 - if ! ck_autostart "$d"; then - printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" - else - printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]" - fi - printf " ${C_CLEAR}$d\n" - done + list "$@" ;; *) # check min args count diff --git a/zsh-completion b/zsh-completion index e5c2850..b324e5c 100644 --- a/zsh-completion +++ b/zsh-completion @@ -19,7 +19,7 @@ _rc.d () { _arguments "*: :" ;; list) - _arguments "2: :(started stopped)" + _arguments "*: :(started stopped auto noauto $(echo /etc/rc.d/*(N-*:t)))" ;; start) _arguments "*: :($(comm -23 <(echo /etc/rc.d/*(N-*:t)|tr ' ' '\n') <(echo /run/daemons/*(N:t)|tr ' ' '\n')))" -- Sebastien "Seblu" Luttringer