dotfiles

configuration files
git clone https://pi.duncano.de/git/dotfiles.git
Log | Files | Refs | README

commit 84845f8b1d8586cf89d4fee271248144f90c057d
parent c4f8f34092c19e0dd8659c3f64d4c5d12ed9f6df
Author: Duncaen <mail@duncano.de>
Date:   Tue, 30 Jun 2015 22:09:01 +0200

add 's' a small service helper

Diffstat:
bin/s | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 54 insertions(+), 0 deletions(-)

diff --git a/bin/s b/bin/s @@ -0,0 +1,54 @@ +#!/usr/bin/mksh + +fatal() { + msg "FATAL: $1" + exit 1 +} + +msg() { + printf "$1\n" +} + +sv_enable() { + [ ! -e "${SVDIR}${1}" ] && fatal "service '${1}' not found." + [ -e "${SERVICEDIR}${1}" ] && fatal "service '${1}' already enabled." + ln -sfv "${SVDIR}${1}" "${SERVICEDIR}${1}" +} + +sv_disable() { + [ ! -e "${SVDIR}${1}" ] && fatal "service '${1}' not found." + [ ! -e "${SERVICEDIR}${1}" ] && fatal "service '${1}' already disabled." + rm -rfv "${SERVICEDIR}${1}" +} + +sv_list() { + sv s "${SERVICEDIR}"* +} + +while getopts "u:v" opt; do + case "$opt" in + u) SVUSER="$OPTARG" ;; + esac +done +shift $(($OPTIND - 1)) + +: ${SVUSER:=$USER} + +case "$SVUSER" in + root) + SVDIR="/etc/sv/" + SERVICEDIR="/var/service/" + ;; + *) + HOMEDIR=$(getent passwd "$SVUSER" | cut -d':' -f6) + SVDIR="${HOMEDIR}/sv/" + SERVICEDIR="${HOMEDIR}/service/" + ;; +esac + +case "$1" in + ls|list) sv_list "$2" ;; + enable) sv_enable "$2" ;; + disable) sv_disable "$2" ;; + *) SVDIR="$SVDIR" sv "$@" ;; +esac