From d00b178f1c3b24d64a6086f3aacdb3d4c5509c41 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Tue, 8 Feb 2022 15:57:42 +0100 Subject: [PATCH] feat: rename managers to handlers and respect environment --- handlers.available | 7 +++++++ handlers/apt/install | 2 ++ {managers => handlers}/apt/ppa | 0 handlers/arch/install | 2 ++ handlers/aur/install | 2 ++ handlers/deb/install | 11 ++++++++++ {managers => handlers}/make/install | 3 ++- handlers/script/install | 7 +++++++ {managers => handlers}/snap/install | 0 instalee | 31 +++++++++++++++-------------- managers/apt/install | 2 -- managers/apt/install_deb | 9 --------- managers/pac/install | 2 -- managers/script/install | 5 ----- 14 files changed, 49 insertions(+), 34 deletions(-) create mode 100644 handlers.available create mode 100644 handlers/apt/install rename {managers => handlers}/apt/ppa (100%) create mode 100644 handlers/arch/install create mode 100644 handlers/aur/install create mode 100644 handlers/deb/install rename {managers => handlers}/make/install (60%) mode change 100755 => 100644 create mode 100644 handlers/script/install rename {managers => handlers}/snap/install (100%) mode change 100755 => 100644 instalee delete mode 100755 managers/apt/install delete mode 100644 managers/apt/install_deb delete mode 100755 managers/pac/install delete mode 100755 managers/script/install diff --git a/handlers.available b/handlers.available new file mode 100644 index 0000000..afc66f5 --- /dev/null +++ b/handlers.available @@ -0,0 +1,7 @@ +apt +deb +snap +flatpak +script +make +custom diff --git a/handlers/apt/install b/handlers/apt/install new file mode 100644 index 0000000..d725705 --- /dev/null +++ b/handlers/apt/install @@ -0,0 +1,2 @@ +#!/bin/sh +xargs sudo apt install diff --git a/managers/apt/ppa b/handlers/apt/ppa similarity index 100% rename from managers/apt/ppa rename to handlers/apt/ppa diff --git a/handlers/arch/install b/handlers/arch/install new file mode 100644 index 0000000..7ef36e1 --- /dev/null +++ b/handlers/arch/install @@ -0,0 +1,2 @@ +#!/bin/sh +xargs sudo pacman -S diff --git a/handlers/aur/install b/handlers/aur/install new file mode 100644 index 0000000..bd7c27d --- /dev/null +++ b/handlers/aur/install @@ -0,0 +1,2 @@ +#!/bin/sh +xargs sudo yay -S diff --git a/handlers/deb/install b/handlers/deb/install new file mode 100644 index 0000000..c0732dd --- /dev/null +++ b/handlers/deb/install @@ -0,0 +1,11 @@ +#!/bin/sh +# Install a package from a local or downloaded .deb-file and remove it +loc="/tmp/install.deb" +arg="$(read)" +case "$arg" in + (http*) sudo wget -O "$loc" "$arg";; + (*) loc="$arg";; +esac +sudo dpkg -i "$loc" +sudo apt -f install +sudo rm -f "$loc" diff --git a/managers/make/install b/handlers/make/install old mode 100755 new mode 100644 similarity index 60% rename from managers/make/install rename to handlers/make/install index d74f5f3..1cfaac6 --- a/managers/make/install +++ b/handlers/make/install @@ -1,3 +1,4 @@ #!/usr/bin/env sh -cd $1 +arg="$(read)" +cd "$arg" sudo checkinstall diff --git a/handlers/script/install b/handlers/script/install new file mode 100644 index 0000000..30ba62b --- /dev/null +++ b/handlers/script/install @@ -0,0 +1,7 @@ +#!/bin/sh +read arg +read name +location="/usr/local/bin/${name:-$(basename "$arg")}" +curl "$arg" | sudo tee "$location" > /dev/null +sudo chmod +x "$location" +test "$INSTALEE_VERBOSE" -lt 3 || echo "Installed $name to $location" diff --git a/managers/snap/install b/handlers/snap/install similarity index 100% rename from managers/snap/install rename to handlers/snap/install diff --git a/instalee b/instalee old mode 100755 new mode 100644 index 044f80e..1020902 --- a/instalee +++ b/instalee @@ -1,31 +1,33 @@ #!/bin/sh -home="${XDG_CONFIG_HOME:-$HOME/.config}/instalee" +home="${INSTALEE_HOME:-${XDG_CONFIG_HOME:-$HOME/.config}/instalee}" underline() { 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() { - result=$(cat "$home/sources" | while read source - do find "$home/packages/$1" -name "$source*" 2>/dev/null - done) - test ! "$result" && echo "No source for package '$1'" >>/dev/stderr && exit 1 + result="$(cat "$home/handlers.available" | while read handler + do find "$home/packages/$1" -name "$handler*" 2>/dev/null + done)" + test ! "$result" && echo "No handler for package '$1'" >>/dev/stderr && exit 1 echo "$result" } -getcontent() { - case "$(file "$1")" in - *executable*) $1;; - *) cat "$1";; - esac -} -case $1 in - -a) +case "$1" in + (--version) + printf "instalee r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" + # TODO license https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion + ;; + (-a|--add) dir="$home/packages/$2" mkdir -p "$dir" test $# -gt 3 && echo "$4">"$dir/$3" || $EDITOR "$dir/$3" ;; - *) + (*) set -e pkgs=$(get "$1") echo "$pkgs" | while read pkg; do @@ -42,4 +44,3 @@ case $1 in done ;; esac - diff --git a/managers/apt/install b/managers/apt/install deleted file mode 100755 index 33ff3b7..0000000 --- a/managers/apt/install +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -sudo apt install "$@" diff --git a/managers/apt/install_deb b/managers/apt/install_deb deleted file mode 100644 index 6884372..0000000 --- a/managers/apt/install_deb +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -loc="/tmp/install.deb" -case $1 in - (http*) sudo wget -O "$loc" $1 ;; - (*) loc="$1" ;; -esac -sudo dpkg -i "$loc" -sudo apt -f install -sudo rm -f "$loc" diff --git a/managers/pac/install b/managers/pac/install deleted file mode 100755 index 9e384d8..0000000 --- a/managers/pac/install +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -pac -S "$@" diff --git a/managers/script/install b/managers/script/install deleted file mode 100755 index 7e3d196..0000000 --- a/managers/script/install +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -location="/usr/local/bin/$(basename $1)" -curl "$1" | sudo tee "$location" > /dev/null -sudo chmod +x "$location" -echo "Installed to $location"