From 78eb8854bf2beefc540f4d15d7aa53cae4335afa Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Mon, 19 Jul 2021 00:57:14 -0700 Subject: [PATCH] DRY up some install scripts --- install-scripts/.local/bin/install-dust | 6 +--- install-scripts/.local/bin/install-hugo-home | 36 +++++++------------ install-scripts/.local/bin/install-procs | 6 +--- .../.local/bin/install-shellcheck-home | 28 ++------------- 4 files changed, 18 insertions(+), 58 deletions(-) diff --git a/install-scripts/.local/bin/install-dust b/install-scripts/.local/bin/install-dust index 6eaabc2..3d66518 100755 --- a/install-scripts/.local/bin/install-dust +++ b/install-scripts/.local/bin/install-dust @@ -17,8 +17,4 @@ URL="https://github.com/bootandy/dust/releases/download/v${VERSION}/dust-v${VERS extract_tarball "${URL}" "${DEST}/${VERSION}" "--strip-component 1" set_current_link "${DEST}" "${VERSION}" - -cd "$XDG_BIN_HOME" || exit 1 -unlink_if_set "$XDG_BIN_HOME/${APP}" -ln -s "$(relative_path "${XDG_BIN_HOME}" "${DEST}/current/${APP}")" ${APP} -cd - >/dev/null || exit 1 +set_link "${XDG_BIN_HOME}/${APP}" "${DEST}" "${APP}" diff --git a/install-scripts/.local/bin/install-hugo-home b/install-scripts/.local/bin/install-hugo-home index 4792683..eb93bec 100755 --- a/install-scripts/.local/bin/install-hugo-home +++ b/install-scripts/.local/bin/install-hugo-home @@ -1,30 +1,20 @@ #!/usr/bin/env bash -set -e -set -x - # shellcheck disable=SC1090 source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh" -APP=hugo -VERSION=${VERSION:-0.81.0} -APPS_DIR=${XDG_DATA_HOME}/buddy-up/apps/${APP} - -ARCH= -case $(get_arch) in - amd64) ARCH=64bit -esac -URL=https://github.com/gohugoio/hugo/releases/download/v${VERSION}/hugo_${VERSION}_$(uname)-${ARCH}.tar.gz +get_arch () { + case $(uname -m) in + x86_64*) echo 64bit;; + *) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;; + esac +} -extract_tarball "${URL}" "${APPS_DIR}/${VERSION}" -set_current_link "${APPS_DIR}" "${VERSION}" +APP=hugo +VERSION=${VERSION:-0.85.0} +DEST="${XDG_DATA_HOME}/apps/releases/${APP}" +URL=https://github.com/gohugoio/hugo/releases/download/v${VERSION}/hugo_extended_${VERSION}_$(uname)-$(get_arch).tar.gz -apps=$(find "${APPS_DIR}/current/" -maxdepth 1 -executable -type f -exec basename {} \;) -cd "${XDG_BIN_HOME}" -for bin in $apps; do - if [[ ! -s $bin ]]; then - ln --symbolic \ - "$(relative_path "${XDG_BIN_HOME}" "${APPS_DIR}/current/${bin}")" \ - "${bin}" - fi -done +extract_tarball "${URL}" "${DEST}/${VERSION}" +set_current_link "${DEST}" "${VERSION}" +set_link "${XDG_BIN_HOME}/${APP}" "${DEST}" "${APP}" diff --git a/install-scripts/.local/bin/install-procs b/install-scripts/.local/bin/install-procs index d3c3547..7733f92 100755 --- a/install-scripts/.local/bin/install-procs +++ b/install-scripts/.local/bin/install-procs @@ -17,8 +17,4 @@ URL="https://github.com/dalance/procs/releases/download/v${VERSION}/procs-v${VER extract_zip "${URL}" "${DEST}/${VERSION}" set_current_link "${DEST}" "${VERSION}" - -cd "$XDG_BIN_HOME" || exit 1 -unlink_if_set "$XDG_BIN_HOME/${APP}" -ln -s "$(relative_path "${XDG_BIN_HOME}" "${DEST}/current/${APP}")" ${APP} -cd - >/dev/null || exit 1 +set_link "${XDG_BIN_HOME}/${APP}" "${DEST}" "${APP}" diff --git a/install-scripts/.local/bin/install-shellcheck-home b/install-scripts/.local/bin/install-shellcheck-home index 46e5688..1b4aeed 100755 --- a/install-scripts/.local/bin/install-shellcheck-home +++ b/install-scripts/.local/bin/install-shellcheck-home @@ -3,33 +3,11 @@ # shellcheck disable=SC1090 source "${XDG_DATA_HOME}/buddy-up/includes/utils.sh" -function get_os () { - case $(uname -s) in - Linux*) echo linux;; - Darwin*) echo darwin;; - *) >&2 echo "unsupported os: $(uname -s)"; exit 1;; - esac -} - -function get_arch () { - case $(uname -m) in - amd64*|x86_64*) echo x86_64;; - arm|armv7*|armv6*) echo armv6hf;; - aarch64*|armv8*) echo aarch64;; - *) >&2 echo "unsupported architecture: $(uname -m)"; exit 1;; - esac -} - APP=shellcheck -DEST="${XDG_DATA_HOME}/apps/releases/${APP}" -CURRENT="${DEST}/current" VERSION=${VERSION:-0.7.2} -URL=https://github.com/koalaman/shellcheck/releases/download/v${VERSION}/shellcheck-v${VERSION}.$(get_os).$(get_arch).tar.xz +DEST="${XDG_DATA_HOME}/apps/releases/${APP}" +URL=https://github.com/koalaman/shellcheck/releases/download/v${VERSION}/shellcheck-v${VERSION}.$(get_os).$(uname -m).tar.xz extract_tarball "${URL}" "${DEST}/${VERSION}" "--strip-components 1" set_current_link "${DEST}" "${VERSION}" - -unlink_if_set "${XDG_BIN_HOME}/${APP}" -cd "${XDG_BIN_HOME}" || exit 1 -ln -s "$(relative_path "${XDG_BIN_HOME}" "${CURRENT}/${APP}")" "${APP}" -cd - &> /dev/null || exit 1 +set_link "${XDG_BIN_HOME}/${APP}" "${DEST}" "${APP}"