From 2f67e128007163f8b9e098f42fd06bfdfaeccd4f Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 15 Nov 2021 08:43:05 +0000 Subject: [PATCH] refactor: scope downloads to thing/version/thing-version.tar.gz --- _webi/template.sh | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/_webi/template.sh b/_webi/template.sh index 4a15ec5..07f4761 100644 --- a/_webi/template.sh +++ b/_webi/template.sh @@ -36,6 +36,7 @@ function __bootstrap_webi() { #PKG_FORMATS= WEBI_UA="$(uname -a)" WEBI_PKG_DOWNLOAD="" + WEBI_PKG_PATH="${HOME}/Downloads/webi/${PKG_NAME:-error}/${WEBI_VERSION:-latest}" export WEBI_HOST ## @@ -45,7 +46,7 @@ function __bootstrap_webi() { WEBI_TMP=${WEBI_TMP:-"$(mktemp -d -t webinstall-"${WEBI_PKG:-}".XXXXXXXX)"} export _webi_tmp="${_webi_tmp:-"$HOME/.local/opt/webi-tmp.d"}" - mkdir -p "$HOME/Downloads/webi" + mkdir -p "${WEBI_PKG_PATH}" mkdir -p "$HOME/.local/bin" mkdir -p "$HOME/.local/opt" @@ -106,7 +107,14 @@ function __bootstrap_webi() { my_current_cmd="$(command -v "$pkg_cmd_name")" set -e if [ -n "$my_current_cmd" ]; then - pkg_current_version="$(pkg_get_current_version 2> /dev/null | head -n 1)" + # TODO get version from symlink? + pkg_current_version="" + if [ -n "$(command -v pkg_get_current_version)" ]; then + pkg_current_version="$( + pkg_get_current_version 2> /dev/null | + head -n 1 + )" + fi # remove trailing '.0's for golang's sake my_current_version="$(echo "$pkg_current_version" | sed 's:\.0::g')" my_src_version="$(echo "$WEBI_VERSION" | sed 's:\.0::g')" @@ -150,7 +158,7 @@ function __bootstrap_webi() { if [ -n "${2:-}" ]; then my_dl="$2" else - my_dl="$HOME/Downloads/webi/$WEBI_PKG_FILE" + my_dl="${WEBI_PKG_PATH}/$WEBI_PKG_FILE" fi WEBI_PKG_DOWNLOAD="${my_dl}" @@ -200,20 +208,20 @@ function __bootstrap_webi() { webi_extract() { pushd "$WEBI_TMP" > /dev/null 2>&1 if [ "tar" == "$WEBI_EXT" ]; then - echo "Extracting $HOME/Downloads/webi/$WEBI_PKG_FILE" - tar xf "$HOME/Downloads/webi/$WEBI_PKG_FILE" + echo "Extracting ${WEBI_PKG_PATH}/$WEBI_PKG_FILE" + tar xf "${WEBI_PKG_PATH}/$WEBI_PKG_FILE" elif [ "zip" == "$WEBI_EXT" ]; then - echo "Extracting $HOME/Downloads/webi/$WEBI_PKG_FILE" - unzip "$HOME/Downloads/webi/$WEBI_PKG_FILE" > __unzip__.log + echo "Extracting ${WEBI_PKG_PATH}/$WEBI_PKG_FILE" + unzip "${WEBI_PKG_PATH}/$WEBI_PKG_FILE" > __unzip__.log elif [ "exe" == "$WEBI_EXT" ]; then - echo "Moving $HOME/Downloads/webi/$WEBI_PKG_FILE" - mv "$HOME/Downloads/webi/$WEBI_PKG_FILE" . + echo "Moving ${WEBI_PKG_PATH}/$WEBI_PKG_FILE" + mv "${WEBI_PKG_PATH}/$WEBI_PKG_FILE" . elif [ "xz" == "$WEBI_EXT" ]; then - echo "Inflating $HOME/Downloads/webi/$WEBI_PKG_FILE" - unxz -c "$HOME/Downloads/webi/$WEBI_PKG_FILE" > "$(basename "$WEBI_PKG_FILE")" + echo "Inflating ${WEBI_PKG_PATH}/$WEBI_PKG_FILE" + unxz -c "${WEBI_PKG_PATH}/$WEBI_PKG_FILE" > "$(basename "$WEBI_PKG_FILE")" else # do nothing - echo "Failed to extract $HOME/Downloads/webi/$WEBI_PKG_FILE" + echo "Failed to extract ${WEBI_PKG_PATH}/$WEBI_PKG_FILE" exit 1 fi popd > /dev/null 2>&1 -- 2.25.1