feat: handle package groups

This commit is contained in:
xeruf 2022-07-04 19:13:34 +02:00
parent 14c9d58ebd
commit 471c321caa
6 changed files with 56 additions and 37 deletions

View File

@ -30,7 +30,7 @@ Keep the following in mind when configuring instalee:
for sensible syncing across many different machines
a mechanism such as [yasm alternate files](https://yadm.io/docs/alternates)
can prove useful.
- `collections` are usually personal, but system-agnostic
- `groups` are usually personal, but system-agnostic
- `handlers` and `packages` need to be attuned,
as the package entry format needs to fit the handler definitions.
These may be obtained from a trusted source
@ -44,12 +44,14 @@ See the [man page](instalee.1) for more details.
`instalee <target>`
A _target_ may either be a _package_ or a _collection_.
*Instalee* first checks for a `collections/<target>` file.
A _collection_ is a newline-separated list of packages to install,
A _target_ may either be a _package_ or a _group_.
*Instalee* first checks for a `groups/<target>` file.
A _group_ is a newline-separated list of packages to install,
which *instalee* then resolves individually.
One difference here is that it will try the first handler for the package
if it has no associated definition.
When there is no corresponding _collection_,
When there is no corresponding _group_,
*instalee* searches for the first available _handler_
with a corresponding entry at `packages/<target>/<handler>`,
piping it into the _handler_ to install the package.
@ -57,14 +59,12 @@ The package definition may be an empty file
(thus simply indicating the availability of a package for a _handler_),
in which case the name of the package is passed to the _handler_.
Note that both _collections_ and package entries can be executable files,
Note that both _groups_ and package entries can be executable files,
in which case *instalee* will execute them and use their output instead,
so watch the file permissions!
If an available _handler_ has no definition in `handlers`,
the package file _has to be_ executable,
as *instalee* will then simply execute it.
This _handler_ is usually named `custom`,
though that is no requirement.
### Handlers
@ -80,7 +80,7 @@ enabling batching and the consolidation of interdependent packages into one unit
## Planned
- detection mechanism for handlers and features
(e.g. whether they support batching)
- helper/hook for adding packages to collections upon install
- helper/hook for adding packages to groups upon install
(at least for `pacman`)
## TODOs

5
groups/music Normal file
View File

@ -0,0 +1,5 @@
mpd
mpc
ncmpc
mpdris
vlc

View File

@ -1,2 +1,2 @@
#!/bin/sh
yay -S --needed --noconfirm "$@"
yay -S --batchinstall --needed --noconfirm "$@"

View File

@ -17,17 +17,46 @@ get() {
done
}
# Install a package by name
installpkg() {
pkgs=$(get "$1")
if test -z "$pkgs"
then
printf "No handler available for package '%s'\n" "$1" >&2
return 2
fi
for pkg in $pkgs; do
highlight "$pkg"
name="$(basename $pkg)"
base="${name%_*}"
ext="${name#$base}"
handler="$home/handlers/$base"
if test -d "$handler"
then
args="$(getcontent "$pkg")"
install="$(find "$handler" -name "install$ext" | head -1)" &&
destress " $install $args" &&
$install $args
else
destress " running unhandled $pkg"
$pkg
fi
break
done
}
## EXECUTION
chmod +rx "$home/handlers" -R
case "$1" in
(-v|--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)
(-h|--help)
man $name 2>/dev/null || man "$home/$name.1"
exit $?
;;
@ -44,31 +73,13 @@ case "$1" in
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
groupfile="$home/groups/$1"
if test -f "$groupfile"
then for pkg in $(getcontent "$groupfile")
do installpkg "$pkg" ||
"$home/handlers/$(head -1 handlers.available)/install" "$pkg"
done
else installpkg "$1"
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

1
packages/mpdris/aur Normal file
View File

@ -0,0 +1 @@
mpdris2-git

2
packages/vlc/arch Normal file
View File

@ -0,0 +1,2 @@
vlc
phonon-qt5-vlc