dot

packages and services management
Log | Files | Refs | README

commit 9b91fb8c54b09b9f48d00fd534c06487e201a48a
parent 421e87301870455cd9706f705a4872995219c2c9
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Mon,  5 Jun 2017 18:11:42 +0200

testing ./service

Diffstat:
Mbin/io | 31++++++++++++++-----------------
Mbin/io-url | 6+-----
Angircd/start | 2++
Mprofile | 17++++-------------
Mservice | 42++++++++++++++++++++++++++++++++++++------
Athd/url | 0
6 files changed, 57 insertions(+), 41 deletions(-)

diff --git a/bin/io b/bin/io @@ -2,31 +2,29 @@ [ "$ABDUCO" ] && exit 1 -mkdir -p "$HOME/.cache/io" -touch "$HOME/.abduco/names" - -# --- cache -------------------------------------------------------------------- +# --- find --------------------------------------------------------------------- nohup find "$HOME" \ - -path "$HOME/.*" -prune -o \ - -path "*/.git/*" -prune -o \ - -path "*/.hg/*" -prune -o \ - -path "*/v" -prune -o \ - -path "${MAIL%/*}/*/*" -prune -o \ + -path "$HOME/.*" -prune -o \ + -path "*/.git/*" -prune -o \ + -path "*/.hg/*" -prune -o \ + -path "*/v" -prune -o \ + -path "${MAIL%/*}/*/*" -prune -o \ -type d -exec printf '%s/\n' {} + -o \ - -print 2> /dev/null | sort -o "/tmp/find" & + -print 2> /dev/null | +sort -o "/tmp/find" & -# --- selection ---------------------------------------------------------------- +# --- select ------------------------------------------------------------------- selection=$({ printf '# %s\n' abduco io-abduco - awk -v IRC="$IRC" -v MAIL="${MAIL%/*}" -v MUSIC="$MUSIC" ' + awk -v VAR="$VAR" -v MAIL="${MAIL%/*}" ' -$0 ~ IRC "/.*/$" { +$0 ~ VAR "/irc/.*/$" { ircv[ircc++] = $0; } @@ -38,12 +36,11 @@ $0 ~ "/[.]git/$" || $0 ~ "/src/[^/]*/$" && $0 !~ "/git/.*/src/" && $0 !~ "/src/.*/src/" { - sub("/[.]git/$", "/"); searchv[searchc++] = $0; } -$0 ~ MUSIC { +$0 ~ VAR "/music" { musicv[musicc++] = $0; } @@ -79,16 +76,16 @@ END { printf '# %s\n' url cat "$HOME"/var/url/* "$ETC/var/url" cut -d ' ' -f 1 "$HOME/.ssh/known_hosts" | sed -r 's|^|ssh://root@|' + } | iomenu -p io -s -h | cut -c 3-) command="io-${selection%% *}" path="${selection#* }" -#wait mv /tmp/find "$HOME/.cache/find" -# --- attach ------------------------------------------------------------------- +# --- run ---------------------------------------------------------------------- printf '\033[H\033[2J' diff --git a/bin/io-url b/bin/io-url @@ -19,10 +19,6 @@ case "$1" in esac url=${url%:*} - exec ii -i "${IRC:-$HOME/var/irc}" \ - -n "${NICK:-$USER}" \ - -f "$NAME" \ - -s "$url" \ - $port + exec ii -i "$VAR/irc" -n "${NICK:-$USER}" -f "$NAME" -s "$url" $port ;; esac diff --git a/ngircd/start b/ngircd/start @@ -0,0 +1,2 @@ +echo "yes" +read line diff --git a/profile b/profile @@ -1,17 +1,9 @@ -export ETC="$HOME/etc" -export OPT="$HOME/opt" -export SRC="$HOME/src" -export GIT="$HOME/git" - - +export ETC="$HOME/etc" +export OPT="$HOME/opt" +export SRC="$HOME/src" +export GIT="$HOME/git" export VAR="$HOME/var" -export PID="$VAR/pid" -export IRC="$VAR/irc" -export MAIL="$VAR/mail/INBOX" -export MUSIC="$VAR/music" - - export ROOT="$HOME/.local" export PATH="$ROOT/bin:$ETC/bin:$PATH" @@ -20,7 +12,6 @@ export MANPATH="$ROOT/man:$MANPATH" export LD_RUN_PATH="$ROOT/lib:$LD_RUN_PATH" export LD_LIBRARY_PATH="$ROOT/lib:$LD_LIBRARY_PATH" - for profile in "$ETC"/*/profile do . "$profile" done diff --git a/service b/service @@ -1,37 +1,67 @@ -# simplistic service(1)-like script +# service manager + + +die() +{ + printf '%s\n' "$*" 1>&2 + exit +} + + +check() +{ + [ -f "$ETC/$1/pid" ] && read pid < "$VAR/$1/pid" || pid='' + + ps "$pid" > /dev/null +} + start() { - exec sh "$ETC/$2/start" + [ -f "$ETC/$1/start" ] || die "no start script in $ETC/$1" + + printf %s $$ > "$VAR/pid/$1" + + service="$1" + shift + + exec nohup sh "$ETC/$service/start" "$@" > "$VAR/log/$service" & } stop() { + [ -f "$ETC/$1/stop" ] || echo "no stop script in $ETC/$1" && exit 1 + + [ -f "$ETC/$1/pid" ] && read pid < "$VAR/$1/pid" || pid='' + sh "$ETC/$2/stop" } + status() { : } + usage() { - echo 'service { start | stop | restart | status } name' + echo 'service start|stop|restart|status [name]' exit 1 } # --- main --------------------------------------------------------------------- +mkdir -p "$VAR/pid" "$VAR/log" + [ $# -lt 2 ] && usage -[ -f "$ETC/$2/$1" ] || echo "service script $ETC/$2/$1 not found" -cd "$2" || exit 1 command=$1 +shift -case "$1" in +case "$command" in ( start ) start "$@" ;; ( stop ) stop "$@" ;; ( restart ) stop "$@" && start "$@" ;; diff --git a/thd/url b/thd/url