2020-06-12 21:33:58 +02:00
|
|
|
|
#!/bin/sh
|
|
|
|
|
|
2022-07-04 15:12:41 +02:00
|
|
|
|
## DEFINITIONS
|
2022-07-04 13:51:24 +02:00
|
|
|
|
name="$(basename "$0")"
|
|
|
|
|
home="$(find "$INSTALEE_HOME" "${XDG_CONFIG_HOME:-$HOME/.config}/$name" "$HOME/.$name" "$PWD" -maxdepth 0 2>/dev/null | head -1)"
|
2020-06-12 21:33:58 +02:00
|
|
|
|
|
2022-07-05 11:24:56 +02:00
|
|
|
|
highlight() { echo "[4m[1m$1[0m"; }
|
2022-07-04 15:12:41 +02:00
|
|
|
|
destress() { echo "[2m$1[0m"; }
|
2020-06-12 21:33:58 +02:00
|
|
|
|
|
2022-02-08 15:57:42 +01:00
|
|
|
|
# Get the content of a file or the output of its execution
|
|
|
|
|
getcontent() { test -x "$1" && "$1" || cat "$1"; }
|
|
|
|
|
|
|
|
|
|
# Get available package entries for given package
|
2022-07-04 21:39:34 +02:00
|
|
|
|
getentries() {
|
2022-07-04 13:51:24 +02:00
|
|
|
|
cat "$home/handlers.available" | while read handler
|
2022-07-05 11:24:56 +02:00
|
|
|
|
do find "$home/packages/$1/" -type f -name "$handler*" 2>/dev/null
|
2022-07-04 13:51:24 +02:00
|
|
|
|
done
|
2020-06-12 21:33:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 19:13:34 +02:00
|
|
|
|
# Install a package by name
|
|
|
|
|
installpkg() {
|
2022-07-04 21:39:34 +02:00
|
|
|
|
test "$1" = "--quiet" && local quiet=true && shift
|
|
|
|
|
local pkgs=$(getentries "$1")
|
|
|
|
|
if test -z "$pkgs"; then
|
2022-07-05 11:24:56 +02:00
|
|
|
|
local handlers=$(find "$home/packages/$1/" -type f -printf "%f\n" 2>/dev/null)
|
2022-07-04 21:39:34 +02:00
|
|
|
|
for handler in $handlers
|
|
|
|
|
do installpkg --quiet "$handler" &&
|
|
|
|
|
echo "$handler" >> "$home/handlers.available" &&
|
|
|
|
|
installpkg "$1" &&
|
|
|
|
|
return $?
|
|
|
|
|
done
|
|
|
|
|
test "$quiet" ||
|
|
|
|
|
echo "No handler available for package '$1'" >&2
|
2022-07-04 19:13:34 +02:00
|
|
|
|
return 2
|
|
|
|
|
fi
|
2022-07-04 21:39:34 +02:00
|
|
|
|
for pkg in $pkgs
|
|
|
|
|
do highlight "$pkg"
|
|
|
|
|
local name="$(basename $pkg)"
|
|
|
|
|
local base="${name%_*}"
|
2022-07-04 19:13:34 +02:00
|
|
|
|
|
2022-07-04 21:39:34 +02:00
|
|
|
|
local ext="${name#$base}"
|
|
|
|
|
local handler="$home/handlers/$base"
|
2022-07-04 19:13:34 +02:00
|
|
|
|
if test -d "$handler"
|
|
|
|
|
then
|
2022-07-04 21:39:34 +02:00
|
|
|
|
local args="$(getcontent "$pkg" | grep . || echo "$1")"
|
|
|
|
|
local install="$(find "$handler" -name "install$ext" | head -1)" &&
|
2022-07-04 19:13:34 +02:00
|
|
|
|
destress " $install $args" &&
|
|
|
|
|
$install $args
|
|
|
|
|
else
|
|
|
|
|
destress " running unhandled $pkg"
|
|
|
|
|
$pkg
|
|
|
|
|
fi
|
|
|
|
|
break
|
|
|
|
|
done
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 15:12:41 +02:00
|
|
|
|
## EXECUTION
|
|
|
|
|
chmod +rx "$home/handlers" -R
|
|
|
|
|
|
2022-02-08 15:57:42 +01:00
|
|
|
|
case "$1" in
|
2022-07-04 19:13:34 +02:00
|
|
|
|
(-V|--version|"")
|
2022-07-04 13:51:24 +02:00
|
|
|
|
printf "$0 r%s.%s\n" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
|
|
|
|
|
echo "Try '$0 --help' or 'man $name' for usage info"
|
2022-02-08 15:57:42 +01:00
|
|
|
|
# TODO license https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
|
2022-07-04 15:12:41 +02:00
|
|
|
|
exit 0
|
2022-02-08 15:57:42 +01:00
|
|
|
|
;;
|
2022-07-04 19:13:34 +02:00
|
|
|
|
(-h|--help)
|
2022-07-04 15:12:41 +02:00
|
|
|
|
man $name 2>/dev/null || man "$home/$name.1"
|
|
|
|
|
exit $?
|
|
|
|
|
;;
|
2022-02-08 15:57:42 +01:00
|
|
|
|
(-a|--add)
|
2020-06-12 21:33:58 +02:00
|
|
|
|
dir="$home/packages/$2"
|
|
|
|
|
mkdir -p "$dir"
|
2020-06-21 16:19:54 +02:00
|
|
|
|
test $# -gt 3 && echo "$4">"$dir/$3" || $EDITOR "$dir/$3"
|
2022-07-04 15:12:41 +02:00
|
|
|
|
exit $?
|
2020-06-21 16:19:54 +02:00
|
|
|
|
;;
|
2022-07-04 15:12:41 +02:00
|
|
|
|
(-v|--verbose)
|
|
|
|
|
set -x
|
|
|
|
|
shift
|
2020-06-21 16:19:54 +02:00
|
|
|
|
;;
|
2020-06-12 21:33:58 +02:00
|
|
|
|
esac
|
2022-07-04 15:12:41 +02:00
|
|
|
|
|
2022-07-04 23:09:58 +02:00
|
|
|
|
runinstalee() {
|
2022-07-04 19:13:34 +02:00
|
|
|
|
groupfile="$home/groups/$1"
|
|
|
|
|
if test -f "$groupfile"
|
|
|
|
|
then for pkg in $(getcontent "$groupfile")
|
2022-07-04 23:09:58 +02:00
|
|
|
|
do runinstalee "$pkg" ||
|
|
|
|
|
"$home/handlers/$(head -1 handlers.available)/install" "$pkg"
|
|
|
|
|
done
|
2022-07-04 19:13:34 +02:00
|
|
|
|
else installpkg "$1"
|
2022-07-04 15:12:41 +02:00
|
|
|
|
fi
|
2022-07-04 23:09:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exitcode=0
|
|
|
|
|
while test $# -gt 0; do
|
|
|
|
|
runinstalee "$1"
|
|
|
|
|
exitcode=$(expr $exitcode \| $?)
|
2022-07-04 15:12:41 +02:00
|
|
|
|
shift
|
|
|
|
|
done
|
2022-07-04 21:39:34 +02:00
|
|
|
|
exit $exitcode
|