From 9294602a528a762d643c76c62e57df17948a9358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Pereira?= Date: Mon, 5 May 2025 16:23:43 -0500 Subject: [PATCH] Allow usage of sha1sum for OS's that do not have sha256sum MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Pereira --- scripts/install_sh/install.sh.txt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/install_sh/install.sh.txt b/scripts/install_sh/install.sh.txt index f3415ad..233610f 100644 --- a/scripts/install_sh/install.sh.txt +++ b/scripts/install_sh/install.sh.txt @@ -9,6 +9,20 @@ if test -z "$BASH_VERSION"; then exit 1 fi +# Function to check for required commands +check_command() { + command -v "$1" >/dev/null 2>&1 || { echo >&2 "Error: $1 is required but not installed."; exit 1; } +} + +# Check for required commands +check_command sha256sum || check_command sha1sum + +# Set checksum command based on availability +CHECKSUM_CMD=sha256sum +if ! command -v $CHECKSUM_CMD >/dev/null 2>&1; then + CHECKSUM_CMD=sha1sum +fi + install() { set -euo pipefail @@ -17,10 +31,11 @@ install() { if [ -x "$(command -v wget)" ]; then dl_bin="wget -nv -O-" else + check_command curl dl_bin="curl -s -L" fi - shasum -v 1>/dev/null 2>&1 || (echo "Missing shasum binary" && exit 1) + $CHECKSUM_CMD -v 1>/dev/null 2>&1 || (echo "Missing shasum binary" && exit 1) if [[ `uname` == Darwin ]]; then binary_type=darwin-amd64 @@ -37,7 +52,7 @@ install() { (@ for val in data.values.products: @) echo "Installing (@= val.product @)..." $dl_bin (@= addProtocol(val.github.url) @)/releases/download/(@= val.version @)/(@= val.product @)-${binary_type} > /tmp/(@= val.product @) - echo "${(@= val.product @)_checksum} /tmp/(@= val.product @)" | shasum -c - + echo "${(@= val.product @)_checksum} /tmp/(@= val.product @)" | $CHECKSUM_CMD -c - mv /tmp/(@= val.product @) ${dst_dir}/(@= val.product @) chmod +x ${dst_dir}/(@= val.product @) echo "Installed ${dst_dir}/(@= val.product @) (@= val.version @)"