Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # This script aims to offer a friendly interface to manage runit services
- # Requires:
- # * dialog
- # * find
- # * $SVDIR which indicates the supervision folder
- # * $SVKNOWN which indicates a colon-separated list of places to search for
- # existing services (duplicated services are *not* supported... yet?)
- # * $ACTION indicates how to manipulate services
- #
- # Currently supported $ACTION values:
- # * install: allows to register/unregister known services;
- #
- # Planned to support $ACTION values:
- # * enable: allows to enable/disable known services;
- # * toggle: same, via down file;
- printf "SVDIR=%s\nSVKNOWN=%s\n" ${SVDIR:="/etc/service"} ${SVKNOWN:="/etc/sv/"} >&2
- ACTION="enable"
- SV_LIST=""
- FINDOPT="-mindepth 1 -maxdepth 2 -name run "
- for SOURCE in $(printf ${SVKNOWN} | tr ':' '\t')
- do
- SV_LIST="$SV_LIST $(find -H $SOURCE $FINDOPT -exec sh -c \
- 'printf "%s %s off\n" $(dirname {}) $(dirname {})' \; | sort)"
- done
- SV_ENABLED=$(find -L ${SVDIR} $FINDOPT -exec sh -c \
- 'printf " -e '\''/%s off$/ s/off$/on/g'\'' " $(basename $(dirname {}))' \;)
- SV_CURRENT=$(printf "%s %s %s\n" $SV_LIST | eval sed $SV_ENABLED)
- DIALOG=$(mktemp -d)
- dialog --no-tags --checklist "List of service to $ACTION:" 0 0 0 $SV_CURRENT 2> $DIALOG/out
- SV_NEW_ENABLED=$(tr ' ' '\n' < $DIALOG/out | awk -F/ '{printf " -e '\''/%s off$/ s/off$/on/g'\'' \n", $NF}END{printf "\n"}')
- SV_NEXT=$(printf "%s %s %s\n" $SV_LIST | eval sed $SV_NEW_ENABLED)
- printf "%s\n" "$SV_CURRENT" > $DIALOG/curr
- printf "%s\n" "$SV_NEXT" > $DIALOG/next
- AWKPROG='
- {
- if( $2 != $3 )
- {
- if( $2 == "on" )
- {
- last = split( $1, elem, "/" );
- printf "rm %s/%s\n", svdir, elem[last];
- }
- else
- {
- printf "ln -s %s %s/\n", $1, svdir;
- }
- }
- }
- '
- paste -d ' ' $DIALOG/curr $DIALOG/next | cut -f1,3,6 -d ' ' | awk -F' ' -v svdir="$SVDIR" "$AWKPROG"
- rm -r $DIALOG
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement