fix: updated handlers and little fixes

This commit is contained in:
xeruf 2022-11-24 15:03:57 +01:00
parent db3c8996e0
commit 07da169c5e
9 changed files with 90 additions and 42 deletions

4
handlers.available.zorin Normal file
View File

@ -0,0 +1,4 @@
apt
snap
binary
linux

View File

@ -1,9 +1,14 @@
#!/bin/sh #!/bin/sh -e
# Install a package from a local or downloaded .deb-file and remove it # 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 case "$1" in
(http*) wget -O "$loc" "$arg";; (http*) wget --no-verbose -O "$loc" "$@";;
(*) loc="$arg";; (*.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 esac
sudo dpkg -i "$loc" sudo dpkg -i "$loc"
sudo apt -f install sudo apt -f install

View File

@ -1,10 +1,11 @@
#!/bin/sh -e #!/bin/sh -e
test "$INSTALEE_VERBOSE" -lt 10 || set -x
arg=$1 arg=$1
name=$2 name="${2:-$(basename "$arg")}"
location="/usr/local/bin/${name:-$(basename "$arg")}" location="/usr/local/bin/${name}"
case "$arg" in case "$arg" in
(*://*) curl "$arg" | sudo tee "$location" > /dev/null;; (*://*) sudo wget --no-verbose -O "$location" "$arg";;
(*) sudo cp "$arg" "$location";; (*) sudo cp -v "$arg" "$location";;
esac esac
sudo chmod +x "$location" sudo chmod +x "$location"
test "$INSTALEE_VERBOSE" -lt 3 || echo "Installed $name to $location" test "$INSTALEE_VERBOSE" -lt 3 || echo "Installed $name to $location"

View File

@ -3,8 +3,8 @@
## DEFINITIONS ## DEFINITIONS
name="$(basename "$0")" name="$(basename "$0")"
self="$(realpath "$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)" 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)"
handlers="$dir_home/handlers.available" export dir_home="$(dirname "$handlersfile")"
dir_packages="$dir_home/packages" dir_packages="$dir_home/packages"
highlight() { echo "$1" >&2; } highlight() { echo "$1" >&2; }
@ -20,7 +20,7 @@ getcontent() {
# Get available package entries for given package # Get available package entries for given package
getentries() { 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 do find "$dir_packages/$1/" -depth -type f -name "$handler*" 2>/dev/null | tac
done done
} }
@ -29,7 +29,8 @@ getentries() {
installpkg() { installpkg() {
test "$1" = "--quiet" && local quiet=true && shift test "$1" = "--quiet" && local quiet=true && shift
local dir_package="$dir_packages/$1/" 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 if test -z "$package_available_entries"; then
local pkghandlers="$(find "$dir_package" -type f -printf "%f\n" 2>/dev/null)" local pkghandlers="$(find "$dir_package" -type f -printf "%f\n" 2>/dev/null)"
for handler in $pkghandlers for handler in $pkghandlers
@ -57,6 +58,7 @@ installpkg() {
local ext="${name#$base}" local ext="${name#$base}"
local handler="$dir_home/handlers/$base" local handler="$dir_home/handlers/$base"
(cd "$(mktemp -d --tmpdir=$execdir "$name.XXXX")"
if test -d "$handler" if test -d "$handler"
then then
# This declaration needs to be ahead, otherwise it overrides failing exit codes # This declaration needs to be ahead, otherwise it overrides failing exit codes
@ -70,7 +72,8 @@ installpkg() {
else else
destress " running unhandled $pkg_entry" destress " running unhandled $pkg_entry"
fi fi
(cd "$(mktemp -d --tmpdir=$execdir "$(basename $pkg_entry).XXXX")"; $pkg_entry) $pkg_entry
)
set +e set +e
break break
done done
@ -81,7 +84,7 @@ installpkg() {
# TODO getopt # TODO getopt
case "$1" in case "$1" in
(-V|--version|"") (-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 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 # TODO license https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html#g_t_002d_002dversion
exit 0 exit 0
@ -90,7 +93,7 @@ case "$1" in
man $name 2>/dev/null || man "$dir_home/$name.1" man $name 2>/dev/null || man "$dir_home/$name.1"
exit $? exit $?
;; ;;
(-v|--verbose) set -x; shift;; (-v|--verbose) set -x; export INSTALEE_VERBOSE=10; shift;;
(-d|--default) default=true; shift;; (-d|--default) default=true; shift;;
(-x|--noexec) noexec=true; shift;; (-x|--noexec) noexec=true; shift;;
(-a|--add*) (-a|--add*)
@ -129,10 +132,9 @@ case "$1" in
fi fi
;; ;;
esac esac
noexec=true
installdefault() { installdefault() {
local defaulthandler="$(head -1 "$handlers")" local defaulthandler="$(head -1 "$handlersfile")"
highlight "Attempting install of '$1' via default handler '$defaulthandler'" highlight "Attempting install of '$1' via default handler '$defaulthandler'"
$(test "$noexec" && echo "sh") "$dir_home/handlers/$defaulthandler/install" "$1" && $(test "$noexec" && echo "sh") "$dir_home/handlers/$defaulthandler/install" "$1" &&
$(test "$noexec" && echo "sh") "$self" --add "$1" "$defaulthandler" "" && $(test "$noexec" && echo "sh") "$self" --add "$1" "$defaulthandler" "" &&
@ -150,12 +152,12 @@ runinstalee() {
} }
# TODO Manjaro # 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)" && 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" && test -n "$copy" &&
echo "Bootstrapping available handlers from $copy" && echo "Bootstrapping available handlers from $copy" &&
cp "$copy" "$handlers" || { cp "$copy" "$handlersfile" || {
echo "Missing available handlers in $handlers!" >&2 echo "Missing available handlers in $handlersfile!" >&2
exit 1 exit 1
} }
fi fi
@ -167,10 +169,12 @@ mkdir -p $execdir
cd $execdir cd $execdir
destress "Running in $execdir" destress "Running in $execdir"
export INSTALEE_VERBOSE="${INSTALEE_VERBOSE:-2}"
exitcode=0 exitcode=0
while test $# -gt 0; do while test $# -gt 0; do
runinstalee "$1" runinstalee "$1"
exitcode=$(expr $exitcode \| $?) exitcode=$(expr $exitcode \| $?)
shift shift
done done
case $- in (*x*) $(which tree && echo " -L" || echo "find -maxdepth") 3 "$execdir";; esac
exit $exitcode exit $exitcode

View File

@ -1,7 +1,7 @@
.\" Manpage for instalee - https://git.jfischer.org/xeruf/instalee .\" Manpage for instalee - https://git.jfischer.org/xeruf/instalee
.\" Contact 27jf@pm.me for improvements. .\" 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 .SH NAME
@ -17,11 +17,32 @@ instalee - Unix-style universal package management wrapper
.SH DESCRIPTION .SH DESCRIPTION
instalee provides a generic interface for installing packages. 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. 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. Use it to set up servers as well as temporary and permanent computers to your needs across operating systems.
It contains a \fIhandlers\fP and \fIpackages\fP directory and the \fIhandlers.available\fP file.
.SH OPTIONS
.TP
<packagename>
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
<identifier>
Name of the packager for which this entry is meant,
including potential pre- and suffixes.
.TP
<content>
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. 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. 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. 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 .SH CONFIGURATION DIRECTORY
.TP
<packagename> 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 package. Corresponds to a directory in \fIpackages\fP.
.TP The following locations are tried, in that order:
-a|--add - INSTALEE_HOME
Add a package entry to the repo. Will prompt for missing arguments. - XDG_CONFIG_HOME/instalee
.TP - HOME/.instalee
<identifier> - Directory of the executable (thus installation to /opt or portable locations is also easily imaginable)
Name of the packager for which this entry is meant, - Current working directory
including potential pre- and suffixes.
.TP .SH PACKAGING
<content>
Content of the file for the package to be added. - Ensure an executable entry processed by a handler does not accidentally print to stdout
If omitted, the file is opened with $EDITOR. - Link an upstream source for scripts if possible
Note that the parent directory already exists by then, but the file does not. - Try to stick to "/bin/sh -e" as shebang, requiring bash only if needed
.SH EXIT CODES .SH EXIT CODES
@ -80,7 +101,7 @@ Could not install all packages
Exhaustive testing is missing everywhere :) Exhaustive testing is missing everywhere :)
Please report issues on https://github.com/xeruf/instalee/issues 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 .SH AUTHOR

1
packages/bat/apt_deb Normal file
View File

@ -0,0 +1 @@
github.com sharkdp bat

0
packages/udefrag/aur Normal file
View File

3
packages/udefrag/binary Executable file
View File

@ -0,0 +1,3 @@
wget --no-verbose https://easy2boot.xyz/wp-content/uploads/2021/04/udefrag.zip
unzip udefrag.zip >&2
echo udefrag

9
packages/udefrag/linux Executable file
View File

@ -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