From 471c321caa885e0b85c93a0f4b994491e9675c8c Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Mon, 4 Jul 2022 19:13:34 +0200 Subject: [PATCH] feat: handle package groups --- README.md | 18 ++++++------ groups/music | 5 ++++ handlers/aur/install | 2 +- instalee | 65 ++++++++++++++++++++++++++------------------ packages/mpdris/aur | 1 + packages/vlc/arch | 2 ++ 6 files changed, 56 insertions(+), 37 deletions(-) create mode 100644 groups/music create mode 100644 packages/mpdris/aur create mode 100644 packages/vlc/arch diff --git a/README.md b/README.md index a799a6a..a64c5b7 100644 --- a/README.md +++ b/README.md @@ -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 ` -A _target_ may either be a _package_ or a _collection_. -*Instalee* first checks for a `collections/` 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/` 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//`, 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 diff --git a/groups/music b/groups/music new file mode 100644 index 0000000..1530491 --- /dev/null +++ b/groups/music @@ -0,0 +1,5 @@ +mpd +mpc +ncmpc +mpdris +vlc diff --git a/handlers/aur/install b/handlers/aur/install index e1e16bf..3cece5d 100755 --- a/handlers/aur/install +++ b/handlers/aur/install @@ -1,2 +1,2 @@ #!/bin/sh -yay -S --needed --noconfirm "$@" +yay -S --batchinstall --needed --noconfirm "$@" diff --git a/instalee b/instalee index 136754f..66bc17c 100755 --- a/instalee +++ b/instalee @@ -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 diff --git a/packages/mpdris/aur b/packages/mpdris/aur new file mode 100644 index 0000000..6aba58e --- /dev/null +++ b/packages/mpdris/aur @@ -0,0 +1 @@ +mpdris2-git diff --git a/packages/vlc/arch b/packages/vlc/arch new file mode 100644 index 0000000..9f76d7b --- /dev/null +++ b/packages/vlc/arch @@ -0,0 +1,2 @@ +vlc +phonon-qt5-vlc