feat: properly handle custom handlers and extra CLI flags
This commit is contained in:
parent
b6d398e795
commit
5cbb007651
9 changed files with 60 additions and 37 deletions
|
@ -4,4 +4,5 @@ snap
|
|||
flatpak
|
||||
script
|
||||
make
|
||||
custom
|
||||
zsh
|
||||
linux
|
||||
|
|
|
@ -4,4 +4,4 @@ snap
|
|||
flatpak
|
||||
script
|
||||
make
|
||||
custom
|
||||
linux
|
||||
|
|
66
instalee
66
instalee
|
@ -1,9 +1,11 @@
|
|||
#!/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)"
|
||||
|
||||
underline() { echo "[4m$1[0m"; }
|
||||
highlight() { echo "[1m$1[0m"; }
|
||||
destress() { echo "[2m$1[0m"; }
|
||||
|
||||
# Get the content of a file or the output of its execution
|
||||
getcontent() { test -x "$1" && "$1" || cat "$1"; }
|
||||
|
@ -15,36 +17,58 @@ get() {
|
|||
done
|
||||
}
|
||||
|
||||
## EXECUTION
|
||||
chmod +rx "$home/handlers" -R
|
||||
|
||||
case "$1" in
|
||||
(--version|"")
|
||||
(-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";;
|
||||
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 $?
|
||||
;;
|
||||
(*) pkgs=$(get "$1")
|
||||
if test -z "$pkgs"
|
||||
then
|
||||
printf "No handler available for package '%s'\n" "$1" >&2
|
||||
exit 2
|
||||
fi
|
||||
echo "$pkgs" | while read pkg; do
|
||||
underline "$pkg"
|
||||
name="$(basename $pkg)"
|
||||
base="${name%_*}"
|
||||
test "$base" = "custom" && $pkg && exit 0
|
||||
|
||||
ext="${name##$base}"
|
||||
mgr="$home/managers/$base"
|
||||
args="$(getcontent "$pkg")"
|
||||
install="$(find "$mgr" -name "install$ext" | head -1)" && echo "Invoking '$install $args'" && $install $args
|
||||
exit 0
|
||||
done
|
||||
(-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
|
||||
|
|
19
instalee.1
19
instalee.1
|
@ -17,13 +17,13 @@ instalee - Unix-style universal package management wrapper
|
|||
|
||||
instalee provides a generic interface for installing packages. Instead of knowing it all, it relies on the user configuring it to his needs while itself being as dumb as possible.
|
||||
|
||||
Its configuration resides in a folder defaulting to XDG_CONFIG_HOME/instalee, but may be tweaked by simply editing the beginning of the script. It contains a "managers" and "packages" directory and the "sources" file.
|
||||
Its configuration resides in a folder defaulting to XDG_CONFIG_HOME/instalee, but may be tweaked by simply editing the beginning of the script. It contains a \fIhandlers\fP and \fIpackages\fP directory and the \fIhandlers.available\fP file.
|
||||
|
||||
The "managers" firectory contains a directory for each package manager, but in a very generic sense. Usually you will only need to create a directory for the package manager and then an "install" file that processes packages. The file should be executable. It will receive the "package" file result as input, or merely the package name in case that is empty.
|
||||
The \fIhandlers\fP directory contains a directory for each package handler, but in a very generic sense. Usually you will only need to create a directory for the package handler and then an \fIinstall\fP file that processes packages. The file should be executable. It will receive the \fIpackage\fP file result as input, or merely the package name in case that is empty.
|
||||
|
||||
When using multiple different system, the "sources" file unfolds its purpose. It is simply a newline-separated list of the package managers available on the system, in order of preference. When installing a package, instalee uses the first match of a "sources" entry with a file in the package directory.
|
||||
When using multiple different system, the \fIhandlers.available\fP file unfolds its purpose. It is simply a newline-separated list of the package handlers available on the system, in order of preference. When installing a package, instalee uses the first match of a \fIhandlers.available\fP entry with a file in the package directory.
|
||||
|
||||
The "packages" directory will contain the bulk of the information. It contains a directory for each package, which is then filled with files named according to the manager they represent. There are three options for this file, and the result determines the arguments to the "manager".
|
||||
The \fIpackages\fP directory will contain the bulk of the information. It contains a directory for each package, which is then filled with files named according to the handler they represent. There are three options for this file, and the result determines the arguments to the \fIhandler\fP.
|
||||
.RS
|
||||
1. The file is empty. The package name is used as argument.
|
||||
.RE
|
||||
|
@ -34,12 +34,15 @@ The "packages" directory will contain the bulk of the information. It contains a
|
|||
3. The file is executable. The file is executed and the output is used as argument.
|
||||
.RE
|
||||
|
||||
There is also a special "manager" called "custom". A package file with that name will simply be executed without invoking a manager. A custom package file that is not executable constitutes an error.
|
||||
If a \fIhandler\fP is available without entry in \fIhandlers\fP
|
||||
(commonly named after what it requires as/on the system),
|
||||
package files for that handler will be executed without invoking a handler.
|
||||
Such a package file must be executable.
|
||||
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
<packagename>
|
||||
The package to install. Corresponds to a directory in "packages".
|
||||
The package to install. Corresponds to a directory in \fIpackages\fP.
|
||||
.TP
|
||||
-a|--add
|
||||
Add a package, instead of installing it.
|
||||
|
@ -66,10 +69,10 @@ Could not install all packages
|
|||
|
||||
instalee is meant to closely follow the UNIX philosophy, by using directory structures and files as configuration. The goal is to be as generic as possible, but there are still a few exceptions. If you have an idea how to incorporate them generically, I am all ears.
|
||||
.RS
|
||||
\(bu The "custom" package file type, as explained above.
|
||||
\(bu The \fIcustom\fP package file type, as explained above.
|
||||
.RE
|
||||
.RS
|
||||
\(bu A manager must not start with a number nor contain any underscores.
|
||||
\(bu A handler must not start with a number nor contain any underscores.
|
||||
.RE
|
||||
.RS
|
||||
\(bu tbd
|
||||
|
|
1
packages/passff/arch
Normal file
1
packages/passff/arch
Normal file
|
@ -0,0 +1 @@
|
|||
passff-host
|
0
packages/xkblayout-state/custom → packages/xkblayout-state/linux
Normal file → Executable file
0
packages/xkblayout-state/custom → packages/xkblayout-state/linux
Normal file → Executable file
6
sources
6
sources
|
@ -1,6 +0,0 @@
|
|||
apt
|
||||
snap
|
||||
flatpak
|
||||
script
|
||||
make
|
||||
custom
|
Loading…
Add table
Reference in a new issue