dot

packages and services management
Log | Files | Refs | README

commit a33aaf111b6853d4cd2a3a00886449e460e17d4b
parent 7636f5c346bce3a28e6e7c7805fdda0a48865dc5
Author: Josuah Demangeon <josuah.demangeon@gandi.net>
Date:   Sat, 29 Jul 2017 19:57:20 +0200

bin/pkg-*: do not source profile to be stateless

Diffstat:
Abin/pkg-build | 19+++++++++++++++++++
Abin/pkg-configure | 7+++++++
Abin/pkg-download | 19+++++++++++++++++++
Abin/pkg-git | 3+++
Abin/pkg-install | 9+++++++++
Abin/pkg-remove | 2++
Abin/pkg-service | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dpkg-build | 21---------------------
Dpkg-configure | 9---------
Dpkg-download | 21---------------------
Dpkg-install | 11-----------
Dpkg-profile | 20--------------------
Dpkg-remove | 4----
Dpkg-service | 70----------------------------------------------------------------------
14 files changed, 126 insertions(+), 156 deletions(-)

diff --git a/bin/pkg-build b/bin/pkg-build @@ -0,0 +1,19 @@ +mkdir -p "$OPT/$1" && cd "$OPT/$1" || exit 1 +export PREFIX="$PWD" +mkdir -p bin etc include lib share/man +ln -s bin sbin + +cd "$SRC/$1" || exit 1 + +if [ -f "$ETC/$1/build" ] +then + sh "$ETC/$1/build" +else + find "$ETC/${PWD##*/}" -name '*.diff' -exec patch -N -p 1 -i {} ';' + find "$ETC/${PWD##*/}" -name 'config.*' -exec cp -f {} . ';' + [ -f ./configure ] && ./configure --prefix="$PREFIX" + make && make PREFIX="$PREFIX" install clean +fi + +rm "$PREFIX/sbin" +rmdir "$PREFIX/share/man" "$PREFIX"/* 2> /dev/null || true diff --git a/bin/pkg-configure b/bin/pkg-configure @@ -0,0 +1,7 @@ +find "$ETC" -path "$ETC/*/.*" | while IFS='' read -r path +do + [ -d "$path" ] && mkdir -p "$HOME/${path#$ETC/*/}" + [ -f "$path" ] && ln -sf "$path" "$HOME/${path#$ETC/*/}" +done + +find -L "$HOME" -type l -exec rm {} + diff --git a/bin/pkg-download b/bin/pkg-download @@ -0,0 +1,19 @@ +read tar < "$ETC/$1/tar" + +[ -e "$SRC/$1" ] && exit 1 + +mkdir -p "$SRC/$1" && cd "$SRC/$1" + +wget -O - "$tar" | case "$tar" in +(*.tar.bz2 | *.tbz2) bunzip2 -d ;; +(*.tar.gz | *.tgz ) gzip -d ;; +(*.tar.xz | *.txz ) xz -d ;; +(*.tar ) tee ;; +esac | tar -xf - + +if [ $(ls "$SRC/$1" | wc -l) = 1 ] +then + dir=$(ls "$SRC/$1") + find "$SRC/$1" -mindepth 2 -maxdepth 2 -exec mv {} "$SRC/$1" ';' + rmdir "$SRC/$1/$dir" +fi diff --git a/bin/pkg-git b/bin/pkg-git @@ -0,0 +1,3 @@ +IFS='' read -r git < "$ETC/$1/git" +mkdir -p "$SRC" +git clone "$git" "$SRC/$1" diff --git a/bin/pkg-install b/bin/pkg-install @@ -0,0 +1,9 @@ +exit=0 + +find "$OPT/$1" | tee /dev/stderr | while IFS='' read -r path +do + [ -d "$path" ] && mkdir -p "$ROOT/${path#$OPT/$1}" || exit=1 + [ -f "$path" ] && ln -sf "$path" "$ROOT/${path#$OPT/$1}" || exit=1 +done + +exit "$exit" diff --git a/bin/pkg-remove b/bin/pkg-remove @@ -0,0 +1,2 @@ +rm -rf "${OPT:?}/$1" "${SRC:?}/$1" +find -L "$ROOT" -type l -exec rm {} + diff --git a/bin/pkg-service b/bin/pkg-service @@ -0,0 +1,67 @@ +usage() +{ + echo 'service start|stop|restart|status name' + exit 1 +} + + +# --- arguments ---------------------------------------------------------------- + +[ $# -lt 2 ] && usage + +cmd=$1 srv=${2%/} +shift 2 + +case "$cmd" in ( start | stop | restart | status ) : ;; ( * ) usage ;; esac + +[ ! -f "$ETC/$srv/start" ] && echo "no start script in $ETC/$1" && exit 1 + + +# --- main --------------------------------------------------------------------- + +mkdir -p "$VAR/pid" "$VAR/log" + +run=0 act=0 + +[ -d "$VAR/pid/$srv" ] && for pid in $(ls "$VAR/pid/$srv") +do + for arg in "$@" + do grep -q -F "$arg" "$VAR/pid/$srv/$pid" || continue 2 + done + + if cmp "$VAR/pid/$srv/$pid" "/proc/$pid/cmdline" 2> /dev/null + then + act=1 cmdline="$(tr '\0' ' ' < "$VAR/pid/$srv/$pid")" + + if [ "$cmd" = stop ] || [ "$cmd" = restart ] + then + kill "$pid" && + printf '%-15s [stopped] %s\n' "$srv" "$cmdline" + else + run=1 + printf '%-15s [running] %s\n' "$srv" "$cmdline" + fi + fi +done + +[ "$act""$cmd" = '0''status' ] && printf '%-15s [stopped]\n' "$srv" + +if [ "$run" = 0 ] && [ "$cmd" = start ] || [ "$cmd" = restart ] +then + mkdir -p "$VAR/pid/$srv" + . "$ETC/$srv/start" "$@" >> "$VAR/log/$srv" 2>&1 && + cp "/proc/$PID/cmdline" "$VAR/pid/$srv/$PID" + + printf '%-15s [started] ' "$srv" + tr '\0' ' ' < "$VAR/pid/$srv/$PID" + printf '\n' +fi + + +# --- wipe --------------------------------------------------------------------- + +find "$VAR/pid" -type f | while IFS='' read path +do cmp "$path" "/proc/${path##*/}/cmdline" 2> /dev/null || rm -f "$path" +done + +find "$VAR/pid" -depth -type d | xargs rmdir 2> /dev/null || true diff --git a/pkg-build b/pkg-build @@ -1,21 +0,0 @@ -. "${0%/*}/0-profile" - -mkdir -p "$OPT/$1" && cd "$OPT/$1" || exit 1 -export PREFIX="$PWD" -mkdir -p bin etc include lib share/man -ln -s bin sbin - -cd "$SRC/$1" || exit 1 - -if [ -f "$ETC/$1/build" ] -then - sh "$ETC/$1/build" -else - find "$ETC/${PWD##*/}" -name '*.diff' -exec patch -N -p 1 -i {} ';' - find "$ETC/${PWD##*/}" -name 'config.*' -exec cp -f {} . ';' - [ -f ./configure ] && ./configure --prefix="$PREFIX" - make && make PREFIX="$PREFIX" install clean -fi - -rm "$PREFIX/sbin" -rmdir "$PREFIX/share/man" "$PREFIX"/* 2> /dev/null || true diff --git a/pkg-configure b/pkg-configure @@ -1,9 +0,0 @@ -. "${0%/*}/0-profile" - -find "$ETC" -path "$ETC/*/.*" | while IFS='' read -r path -do - [ -d "$path" ] && mkdir -p "$HOME/${path#$ETC/*/}" - [ -f "$path" ] && ln -sf "$path" "$HOME/${path#$ETC/*/}" -done - -find -L "$HOME" -type l -exec rm {} + diff --git a/pkg-download b/pkg-download @@ -1,21 +0,0 @@ -. "${0%/*}/0-profile" - -read tar < "$ETC/$1/tar" - -[ -e "$SRC/$1" ] && exit 1 - -mkdir -p "$SRC/$1" && cd "$SRC/$1" - -wget -O - "$tar" | case "$tar" in -(*.tar.bz2 | *.tbz2) bunzip2 -d ;; -(*.tar.gz | *.tgz ) gzip -d ;; -(*.tar.xz | *.txz ) xz -d ;; -(*.tar ) tee ;; -esac | tar -xf - - -if [ $(ls "$SRC/$1" | wc -l) = 1 ] -then - dir=$(ls "$SRC/$1") - find "$SRC/$1" -mindepth 2 -maxdepth 2 -exec mv {} "$SRC/$1" ';' - rmdir "$SRC/$1/$dir" -fi diff --git a/pkg-install b/pkg-install @@ -1,11 +0,0 @@ -. "${0%/*}/0-profile" - -exit=0 - -find "$OPT/$1" | tee /dev/stderr | while IFS='' read -r path -do - [ -d "$path" ] && mkdir -p "$ROOT/${path#$OPT/$1}" || exit=1 - [ -f "$path" ] && ln -sf "$path" "$ROOT/${path#$OPT/$1}" || exit=1 -done - -exit "$exit" diff --git a/pkg-profile b/pkg-profile @@ -1,20 +0,0 @@ -export ETC="$HOME/etc" -export OPT="$HOME/opt" -export SRC="$HOME/src" -export GIT="$HOME/git" -export VAR="$HOME/var" - -export ROOT="$HOME/.local" - -export MANPATH="$ROOT/man:$MANPATH" -export C_INCLUDE_PATH="$ROOT/include" -export LIBRARY_PATH="$ROOT/.local/lib" -export LD_LIBRARY_PATH="$ROOT/lib:$LD_LIBRARY_PATH" - -for bin in "$ETC/bin" "$ETC"/*/bin "$OPT"/*/bin -do [ -d "$bin" ] && export PATH="$bin:$PATH" -done - -for profile in "$ETC"/*/profile -do [ -f "$ETC"/*/profile ] && . "$profile" -done diff --git a/pkg-remove b/pkg-remove @@ -1,4 +0,0 @@ -. "${0%/*}/0-profile" - -rm -rf "${OPT:?}/$1" "${SRC:?}/$1" -find -L "$ROOT" -type l -exec rm {} + diff --git a/pkg-service b/pkg-service @@ -1,70 +0,0 @@ -. "${0%/*}/0-profile" - - -usage() -{ - echo 'service start|stop|restart|status name' - exit 1 -} - - -# --- arguments ---------------------------------------------------------------- - -[ $# -lt 2 ] && usage - -cmd=$1 srv=${2%/} -shift 2 - -case "$cmd" in ( start | stop | restart | status ) : ;; ( * ) usage ;; esac - -[ ! -f "$ETC/$srv/start" ] && echo "no start script in $ETC/$1" && exit 1 - - -# --- main --------------------------------------------------------------------- - -mkdir -p "$VAR/pid" "$VAR/log" - -run=0 act=0 - -[ -d "$VAR/pid/$srv" ] && for pid in $(ls "$VAR/pid/$srv") -do - for arg in "$@" - do grep -q -F "$@" "$VAR/pid/$srv/$pid" || continue 2 - done - - if cmp "$VAR/pid/$srv/$pid" "/proc/$pid/cmdline" 2> /dev/null - then - act=1 cmdline="$(tr '\0' ' ' < "$VAR/pid/$srv/$pid")" - - if [ "$cmd" = stop ] || [ "$cmd" = restart ] - then - kill "$pid" && - printf '%-15s [stopped] %s\n' "$srv" "$cmdline" - else - run=1 - printf '%-15s [running] %s\n' "$srv" "$cmdline" - fi - fi -done - -[ "$act""$cmd" = '0''status' ] && printf '%-15s [stopped]\n' "$srv" - -if [ "$run" = 0 ] && [ "$cmd" = start ] || [ "$cmd" = restart ] -then - mkdir -p "$VAR/pid/$srv" - . "$ETC/$srv/start" "$@" >> "$VAR/log/$srv" 2>&1 && - cp "/proc/$PID/cmdline" "$VAR/pid/$srv/$PID" - - printf '%-15s [started] ' "$srv" - tr '\0' ' ' < "$VAR/pid/$srv/$PID" - printf '\n' -fi - - -# --- wipe --------------------------------------------------------------------- - -find "$VAR/pid" -type f | while IFS='' read path -do cmp "$path" "/proc/${path##*/}/cmdline" 2> /dev/null || rm -f "$path" -done - -find "$VAR/pid" -depth -type d | xargs rmdir 2> /dev/null || true