From b12000f7cd4d7e052a17789c24bdd11db655582e Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 8 Mar 2026 17:06:36 +0200 Subject: [PATCH 1/2] - Update setup/uninstall --- setup | 132 ++++++++++++++++-------------------------------------- uninstall | 104 ++++++++++++------------------------------ 2 files changed, 66 insertions(+), 170 deletions(-) diff --git a/setup b/setup index b48e9e4..c8a7f81 100755 --- a/setup +++ b/setup @@ -1,102 +1,46 @@ #!/usr/bin/env bash - -print_in_color() { - local color="$1" - shift - if [[ -z ${NO_COLOR+x} ]]; then - printf "$color%b\e[0m\n" "$*" - else - printf "%b\n" "$*" - fi -} - -red() { print_in_color "\e[31m" "$*"; } -green() { print_in_color "\e[32m" "$*"; } -green_bold() { print_in_color "\e[1;32m" "$*"; } -blue() { print_in_color "\e[34m" "$*"; } - -section() { - printf "\n=== %s\n" "$(green_bold "$@")" -} - -sudo_copy() { - printf "%s => %s\n" "$(blue "$(printf '%-25s' "$1")")" "$2" - - if [[ -n "$3" ]]; then - $sudo install -m "$3" "$1" "$2" - else - $sudo install "$1" "$2" - fi -} - -copy_executable() { - sudo_copy "$1" "/usr/local/bin/" "755" -} - -copy_man() { - for file in "$1"/*.[1-8]; do - section="${file##*.}" - target_dir="/usr/local/share/man/man$section/" - - if [[ ! -d "$target_dir" ]]; then - $sudo mkdir -p "$target_dir" +set -euo pipefail + +prepare_installer() { + echo "Initializing installer..." + SSI_VERSION="0.1.5" + + # Set up tmp dir where all work is done + tmpdir="$(mktemp -d)" + trap 'rm -rf "$tmpdir"' EXIT + cd "$tmpdir" + export PATH="$tmpdir:$PATH" + + # Download ssi if needed + if ! command -v ssi >/dev/null 2>&1 || [ "$(ssi --version 2>/dev/null)" != "$SSI_VERSION" ]; then + if command -v curl >/dev/null 2>&1; then + curl -fSsL https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi -o ssi + elif command -v wget >/dev/null 2>&1; then + wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi + else + echo "Error: please install wget or curl, then try again" >&2 + exit 1 fi - - sudo_copy "$file" "$target_dir" - done - - if command_exist makewhatis; then - $sudo makewhatis /usr/local/man + chmod +x ssi fi } -command_exist() { - [[ -x "$(command -v "$1")" ]] -} - -need() { - command_exist "$1" || fail "Cannot run $1" - printf "%s found\n" "$(blue " $1")" -} - -onerror() { - local exit_status=$? - printf "\n=== %s\n" "$(red "Aborted with exit status $exit_status")" - exit $exit_status -} - -fail() { - printf "$(red 'ERR') %s\n" "$*" - return 1 -} - -initialize() { - set -e - trap 'onerror' ERR - - # Figure out if we need sudo or not - sudo='' - if [[ $EUID -ne 0 ]]; then - sudo='sudo' - fi - - repo="$1" - repo_url="https://github.com/${repo}.git" - pushd "$(mktemp -d)" >/dev/null -} - -section "Initializing" -initialize "DannyBen/alf" - -section "Checking for pre-requisites" -need git +prepare_installer -section "Cloning $repo" -git clone --depth 1 "$repo_url" . +if ! command -v git >/dev/null 2>&1; then + echo "Error: please install git and try again" >&2 + exit 1 +fi -section "Copying files" -copy_executable 'alf' -copy_man 'doc' +ssi log info Installing alf +ssi log debug Cloning github repo +git clone -q --depth 1 https://github.com/DannyBen/alf.git alf +ssi install bin alf/alf +ssi install man alf/doc -section "Done" -alf --version +if command -v alf >/dev/null 2>&1; then + ssi log info "alf --version : $(alf --version)" +else + ssi log warn "alf not found on PATH after install" +fi +ssi log debug Installation complete \ No newline at end of file diff --git a/uninstall b/uninstall index 6ca7d9b..5ece91d 100755 --- a/uninstall +++ b/uninstall @@ -1,80 +1,32 @@ #!/usr/bin/env bash - -print_in_color() { - local color="$1" - shift - if [[ -z ${NO_COLOR+x} ]]; then - printf "$color%b\e[0m\n" "$*" - else - printf "%b\n" "$*" - fi -} - -red() { print_in_color "\e[31m" "$*"; } -green() { print_in_color "\e[32m" "$*"; } -green_bold() { print_in_color "\e[1;32m" "$*"; } -blue() { print_in_color "\e[34m" "$*"; } - -section() { - printf "\n=== %s\n" "$(green_bold "$@")" -} - -command_exist() { - [[ -x "$(command -v "$1")" ]] -} - -rm_executable() { - if [[ -z "$1" ]]; then return; fi - - printf "%s %s\n" "$(blue rm)" "$1" - $sudo rm -f "/usr/local/bin/$1" - - if command_exist "$1"; then - fail "Command $1 still exists" +set -euo pipefail + +prepare_installer() { + echo "Initializing installer..." + SSI_VERSION="0.1.5" + + # Set up tmp dir where all work is done + tmpdir="$(mktemp -d)" + trap 'rm -rf "$tmpdir"' EXIT + cd "$tmpdir" + export PATH="$tmpdir:$PATH" + + # Download ssi if needed + if ! command -v ssi >/dev/null 2>&1 || [ "$(ssi --version 2>/dev/null)" != "$SSI_VERSION" ]; then + if command -v curl >/dev/null 2>&1; then + curl -fSsL https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi -o ssi + elif command -v wget >/dev/null 2>&1; then + wget -nv -O ssi https://github.com/DannyBen/ssi/releases/download/v$SSI_VERSION/ssi + else + echo "Error: please install wget or curl, then try again" >&2 + exit 1 + fi + chmod +x ssi fi } -rm_man() { - if [[ ! -d "/usr/local/share/man/man1/" ]]; then return; fi - if [[ -z "$1" ]]; then return; fi - - printf "%s %s\n" "$(blue rm)" "/usr/local/share/man/man1/$1*.1" - $sudo rm -f /usr/local/share/man/man1/"$1"*.1 - - printf "%s %s\n" "$(blue rm)" "/usr/local/share/man/man5/$1*.5" - $sudo rm -f /usr/local/share/man/man5/"$1"*.5 - - if command_exist makewhatis; then - $sudo makewhatis /usr/local/man - fi -} - -onerror() { - local exit_status=$? - printf "\n=== %s\n" "$(red "Aborted with exit status $exit_status")" - exit $exit_status -} - -fail() { - printf "$(red 'ERR') %s\n" "$*" - return 1 -} - -initialize() { - set -e - trap 'onerror' ERR - - # Figure out if we need sudo or not - sudo='' - if [[ $EUID -ne 0 ]]; then - sudo='sudo' - fi -} - -initialize - -section "Removing files" -rm_executable 'alf' -rm_man 'alf' - -section "Done" +prepare_installer +ssi log info "Uninstalling alf" +ssi uninstall bin alf +ssi uninstall man alf --all +ssi log debug Uninstallation complete From 65d7b308b21ed4041dabd1da0234c1ece0605602 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 8 Mar 2026 17:08:46 +0200 Subject: [PATCH 2/2] fix shfmt --- setup | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup b/setup index c8a7f81..6c0080a 100755 --- a/setup +++ b/setup @@ -43,4 +43,4 @@ if command -v alf >/dev/null 2>&1; then else ssi log warn "alf not found on PATH after install" fi -ssi log debug Installation complete \ No newline at end of file +ssi log debug Installation complete