From 07da169c5e36d823967f645f71da670588d1d8e7 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Thu, 24 Nov 2022 15:03:57 +0100 Subject: [PATCH] fix: updated handlers and little fixes --- handlers.available.zorin | 4 +++ handlers/apt/install_deb | 13 +++++--- handlers/binary/install | 9 +++--- instalee | 28 +++++++++-------- instalee.1 | 65 ++++++++++++++++++++++++++-------------- packages/bat/apt_deb | 1 + packages/udefrag/aur | 0 packages/udefrag/binary | 3 ++ packages/udefrag/linux | 9 ++++++ 9 files changed, 90 insertions(+), 42 deletions(-) create mode 100644 handlers.available.zorin create mode 100644 packages/bat/apt_deb create mode 100644 packages/udefrag/aur create mode 100755 packages/udefrag/binary create mode 100755 packages/udefrag/linux diff --git a/handlers.available.zorin b/handlers.available.zorin new file mode 100644 index 0000000..f5b063b --- /dev/null +++ b/handlers.available.zorin @@ -0,0 +1,4 @@ +apt +snap +binary +linux diff --git a/handlers/apt/install_deb b/handlers/apt/install_deb index 910a0b8..066aaeb 100755 --- a/handlers/apt/install_deb +++ b/handlers/apt/install_deb @@ -1,9 +1,14 @@ -#!/bin/sh +#!/bin/sh -e # Install a package from a local or downloaded .deb-file and remove it -loc="$(basename "$arg")" +# Can also infer a latest github release +loc="$(basename "$1")" case "$1" in - (http*) wget -O "$loc" "$arg";; - (*) loc="$arg";; + (http*) wget --no-verbose -O "$loc" "$@";; + (*.deb) loc="$1";; + (git*) domain="$1"; shift + result=$(curl -s "https://api.$domain/repos/$1/$2/releases/latest" | grep -o "http.*${3:-deb}" | awk '{ print length(), $0}' | sort -n | cut -d' ' -f2-) + "$0" $(echo "$result" | command grep amd64 | head -1 || echo "$result") + exit $?;; esac sudo dpkg -i "$loc" sudo apt -f install diff --git a/handlers/binary/install b/handlers/binary/install index b3916c4..f9feabf 100755 --- a/handlers/binary/install +++ b/handlers/binary/install @@ -1,10 +1,11 @@ #!/bin/sh -e +test "$INSTALEE_VERBOSE" -lt 10 || set -x arg=$1 -name=$2 -location="/usr/local/bin/${name:-$(basename "$arg")}" +name="${2:-$(basename "$arg")}" +location="/usr/local/bin/${name}" case "$arg" in - (*://*) curl "$arg" | sudo tee "$location" > /dev/null;; - (*) sudo cp "$arg" "$location";; + (*://*) sudo wget --no-verbose -O "$location" "$arg";; + (*) sudo cp -v "$arg" "$location";; esac sudo chmod +x "$location" test "$INSTALEE_VERBOSE" -lt 3 || echo "Installed $name to $location" diff --git a/instalee b/instalee index 4a99eb5..7968b0a 100755 --- a/instalee +++ b/instalee @@ -3,8 +3,8 @@ ## DEFINITIONS name="$(basename "$0")" self="$(realpath "$0")" -export dir_home="$(find "$INSTALEE_HOME" "${XDG_CONFIG_HOME:-$HOME/.config}/$name" "$HOME/.$name" "$(realpath "$(dirname "$0")")" "$PWD" -maxdepth 0 2>/dev/null | head -1)" -handlers="$dir_home/handlers.available" +handlersfile="$(find "$INSTALEE_HOME" "${XDG_CONFIG_HOME:-$HOME/.config}/$name" "$HOME/.$name" "$(realpath "$(dirname "$0")")" "$PWD" -maxdepth 1 -name "handlers.available*" 2>/dev/null | head -1)" +export dir_home="$(dirname "$handlersfile")" dir_packages="$dir_home/packages" highlight() { echo "$1" >&2; } @@ -20,7 +20,7 @@ getcontent() { # Get available package entries for given package getentries() { - cat "$handlers" | while read handler + cat "$handlersfile" | while read handler do find "$dir_packages/$1/" -depth -type f -name "$handler*" 2>/dev/null | tac done } @@ -29,7 +29,8 @@ getentries() { installpkg() { test "$1" = "--quiet" && local quiet=true && shift local dir_package="$dir_packages/$1/" - test -d "$dir_package" && local package_available_entries=$(getentries "$1") + # prefer unsuffixed entries, i.e. sort by length + test -d "$dir_package" && local package_available_entries="$(getentries "$1")" if test -z "$package_available_entries"; then local pkghandlers="$(find "$dir_package" -type f -printf "%f\n" 2>/dev/null)" for handler in $pkghandlers @@ -57,6 +58,7 @@ installpkg() { local ext="${name#$base}" local handler="$dir_home/handlers/$base" + (cd "$(mktemp -d --tmpdir=$execdir "$name.XXXX")" if test -d "$handler" then # This declaration needs to be ahead, otherwise it overrides failing exit codes @@ -70,7 +72,8 @@ installpkg() { else destress " running unhandled $pkg_entry" fi - (cd "$(mktemp -d --tmpdir=$execdir "$(basename $pkg_entry).XXXX")"; $pkg_entry) + $pkg_entry + ) set +e break done @@ -81,7 +84,7 @@ installpkg() { # TODO getopt case "$1" in (-V|--version|"") - printf "$name r%s.%s\n" "$(git rev-list --count HEAD 2>/dev/null)" "$(git rev-parse --short HEAD 2>/dev/null)" + printf "$name r%s.%s%s\n" "$(git rev-list --count HEAD 2>/dev/null)" "$(git rev-parse --short HEAD 2>/dev/null)" "$(git diff-index HEAD | wc -l | sed 's|^[1-9]|-mod\0|')" echo "Try '$0 --help' or 'man $name' for usage info" >&2 # TODO license https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion exit 0 @@ -90,7 +93,7 @@ case "$1" in man $name 2>/dev/null || man "$dir_home/$name.1" exit $? ;; - (-v|--verbose) set -x; shift;; + (-v|--verbose) set -x; export INSTALEE_VERBOSE=10; shift;; (-d|--default) default=true; shift;; (-x|--noexec) noexec=true; shift;; (-a|--add*) @@ -129,10 +132,9 @@ case "$1" in fi ;; esac -noexec=true installdefault() { - local defaulthandler="$(head -1 "$handlers")" + local defaulthandler="$(head -1 "$handlersfile")" highlight "Attempting install of '$1' via default handler '$defaulthandler'" $(test "$noexec" && echo "sh") "$dir_home/handlers/$defaulthandler/install" "$1" && $(test "$noexec" && echo "sh") "$self" --add "$1" "$defaulthandler" "" && @@ -150,12 +152,12 @@ runinstalee() { } # TODO Manjaro -if ! test -f "$handlers" +if ! test -f "$handlersfile" then copy="$(find "$dir_home" -name "handlers.available.*" -exec sh -c "echo {} | rev | cut -d'.' -f1 | rev | xargs -i% expr $(lsb_release -s -i | tr 'A-Z' 'a-z' || cat /etc/os-release | grep '^ID=' | cut -d= -f2) : % >/dev/null" \; -a -print)" && test -n "$copy" && echo "Bootstrapping available handlers from $copy" && - cp "$copy" "$handlers" || { - echo "Missing available handlers in $handlers!" >&2 + cp "$copy" "$handlersfile" || { + echo "Missing available handlers in $handlersfile!" >&2 exit 1 } fi @@ -167,10 +169,12 @@ mkdir -p $execdir cd $execdir destress "Running in $execdir" +export INSTALEE_VERBOSE="${INSTALEE_VERBOSE:-2}" exitcode=0 while test $# -gt 0; do runinstalee "$1" exitcode=$(expr $exitcode \| $?) shift done +case $- in (*x*) $(which tree && echo " -L" || echo "find -maxdepth") 3 "$execdir";; esac exit $exitcode diff --git a/instalee.1 b/instalee.1 index 1202c2d..036422b 100644 --- a/instalee.1 +++ b/instalee.1 @@ -1,7 +1,7 @@ .\" Manpage for instalee - https://git.jfischer.org/xeruf/instalee .\" Contact 27jf@pm.me for improvements. -.TH man 1 "06 May 2020" "0.1" "instalee man page" +.TH man 1 "22 Nov 2022" "0.1" "instalee man page" .SH NAME @@ -17,11 +17,32 @@ instalee - Unix-style universal package management wrapper .SH DESCRIPTION -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. +Instalee provides a generic interface for installing packages. +It relies on the user configuring it to pers needs, keeping the core logic as simple as possible. -Its configuration resides in a folder defaulting to XDG_CONFIG_HOME/instalee. -It contains a \fIhandlers\fP and \fIpackages\fP directory and the \fIhandlers.available\fP file. +Use it to set up servers as well as temporary and permanent computers to your needs across operating systems. + +.SH OPTIONS + +.TP + +The package. Corresponds to a directory in \fIpackages\fP. +.TP +-a|--add +Add a package entry to the repo. Will prompt for missing arguments. +.TP + +Name of the packager for which this entry is meant, +including potential pre- and suffixes. +.TP + +Content of the file for the package to be added. +If omitted, the file is opened with $EDITOR. +Note that the parent directory already exists by then, but the file does not. + +.SH SETUP + +Instalee requires a CONFIGURATION DIRECTORY containing a \fIhandlers\fP and \fIpackages\fP directory and the \fIhandlers.available\fP file. The \fIhandlers\fP directory contains a directory for each package manager. Usually you will only need to create a directory for the package manager and then an \fIinstall\fP file that processes packages. @@ -47,22 +68,22 @@ There are three options for this file, and the result determines the arguments t 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 - -The package. Corresponds to a directory in \fIpackages\fP. -.TP --a|--add -Add a package entry to the repo. Will prompt for missing arguments. -.TP - -Name of the packager for which this entry is meant, -including potential pre- and suffixes. -.TP - -Content of the file for the package to be added. -If omitted, the file is opened with $EDITOR. -Note that the parent directory already exists by then, but the file does not. +.SH CONFIGURATION DIRECTORY + +Instalee is configured through a folder defaulting to XDG_CONFIG_HOME/instalee, if that does not exist it will try to use the current working directory or the directory of the executable. + +The following locations are tried, in that order: +- INSTALEE_HOME +- XDG_CONFIG_HOME/instalee +- HOME/.instalee +- Directory of the executable (thus installation to /opt or portable locations is also easily imaginable) +- Current working directory + +.SH PACKAGING + +- Ensure an executable entry processed by a handler does not accidentally print to stdout +- Link an upstream source for scripts if possible +- Try to stick to "/bin/sh -e" as shebang, requiring bash only if needed .SH EXIT CODES @@ -80,7 +101,7 @@ Could not install all packages Exhaustive testing is missing everywhere :) Please report issues on https://github.com/xeruf/instalee/issues -(note: hosting service is subject to change soon) +(note: forge is subject to change) .SH AUTHOR diff --git a/packages/bat/apt_deb b/packages/bat/apt_deb new file mode 100644 index 0000000..0f15c2d --- /dev/null +++ b/packages/bat/apt_deb @@ -0,0 +1 @@ +github.com sharkdp bat diff --git a/packages/udefrag/aur b/packages/udefrag/aur new file mode 100644 index 0000000..e69de29 diff --git a/packages/udefrag/binary b/packages/udefrag/binary new file mode 100755 index 0000000..248da28 --- /dev/null +++ b/packages/udefrag/binary @@ -0,0 +1,3 @@ +wget --no-verbose https://easy2boot.xyz/wp-content/uploads/2021/04/udefrag.zip +unzip udefrag.zip >&2 +echo udefrag diff --git a/packages/udefrag/linux b/packages/udefrag/linux new file mode 100755 index 0000000..9288e6c --- /dev/null +++ b/packages/udefrag/linux @@ -0,0 +1,9 @@ +#!/bin/sh -e +# Inspired by https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=udefrag +name="ultradefrag-5.0.0AB.8" +zip="$name.zip" +wget --no-verbose "http://jp-andre.pagesperso-orange.fr/$zip" +unzip "$zip" +cd "$name/src" +make +cp udefrag /usr/local/bin