instalee/instalee

74 lines
1.7 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
## DEFINITIONS
name="$(basename "$0")"
home="$(find "$INSTALEE_HOME" "${XDG_CONFIG_HOME:-$HOME/.config}/$name" "$HOME/.$name" "$PWD" -maxdepth 0 2>/dev/null | head -1)"
highlight() { echo "$1"; }
destress() { echo "$1"; }
# 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
get() {
cat "$home/handlers.available" | while read handler
do find "$home/packages/$1" -name "$handler*" 2>/dev/null
done
}
## EXECUTION
chmod +rx "$home/handlers" -R
case "$1" in
(-v|--version|"")
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"
# TODO license https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
exit 0
;;
(-?|-h|--help)
man $name 2>/dev/null || man "$home/$name.1"
exit $?
;;
(-a|--add)
dir="$home/packages/$2"
mkdir -p "$dir"
test $# -gt 3 && echo "$4">"$dir/$3" || $EDITOR "$dir/$3"
exit $?
;;
(-v|--verbose)
set -x
shift
;;
esac
while test $# -gt 0; do
pkgs=$(get "$1")
if test -z "$pkgs"
then
printf "No handler available for package '%s'\n" "$1" >&2
exit 2
fi
for pkg in $pkgs; do
highlight "$pkg"
name="$(basename $pkg)"
base="${name%_*}"
test "$base" = "custom" && $pkg && exit 0
ext="${name#$base}"
mgr="$home/handlers/$base"
if test -d "$mgr"
then
args="$(getcontent "$pkg")"
install="$(find "$mgr" -name "install$ext" | head -1)" &&
destress " $install $args" &&
$install $args
else
destress " running unhandled $pkg"
$pkg
fi
break
done
shift
done