refactor: scope downloads to thing/version/thing-version.tar.gz
authorAJ ONeal <aj@therootcompany.com>
Mon, 15 Nov 2021 08:43:05 +0000 (08:43 +0000)
committerAJ ONeal <aj@therootcompany.com>
Mon, 15 Nov 2021 11:28:53 +0000 (11:28 +0000)
_webi/template.sh

index 4a15ec5057df76a5362c721d5ff2072911d35dec..07f4761d01a05b7c0d6949e1f4b4d1de25f43c9d 100644 (file)
@@ -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