aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2015-06-30 22:09:01 +0200
committerDuncaen <mail@duncano.de>2015-06-30 22:09:01 +0200
commit84845f8b1d8586cf89d4fee271248144f90c057d (patch)
treeea79bb17e583e1299a706b7baf27971556aa9c3b
parentc4f8f34092c19e0dd8659c3f64d4c5d12ed9f6df (diff)
downloaddotfiles-84845f8b1d8586cf89d4fee271248144f90c057d.tar.gz
add 's' a small service helper
-rwxr-xr-xbin/s54
1 files changed, 54 insertions, 0 deletions
diff --git a/bin/s b/bin/s
new file mode 100755
index 0000000..a109f6c
--- /dev/null
+++ 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