use new bootstrap + webinstall approach
[webi-installers/.git] / rg / rg.bash
index 7c2a825b34aa887ef14b723b791970b3bc5beb2f..afc1c1906c35f309c6e02c920df1b3540aac6858 100644 (file)
 set -e
 set -u
 
-# Use the script's first argument or the supplied WEBI_VERSION or ''
-WEBI_VERSION=${1:-${WEBI_VERSION:-}}
-
-# Set a temporary directory, if not already set
-WEBI_TMP=${WEBI_TMP:-"$(mktemp -d -t webinstall-ripgrep.XXXXXXXX)"}
-
-###################
-#  Get WEBI vars  #
-###################
-
-# The WEBI bootstrap will define these
-# but each script should be testable in its own right
-
-if [ -z "${WEBI_PKG_URL:-}" ]; then
-  release_tab="${WEBI_HOST}/api/releases/ripgrep@${WEBI_VERSION:-}.csv?os=$(uname -s)&arch=$(uname -m)&ext=tar&limit=1"
-  WEBI_CSV=$(curl -fsSL "$release_tab" -H "User-Agent: $(uname -a)")
-  WEBI_CHANNEL=$(echo $WEBI_CSV | cut -d ',' -f 3)
-  if [ "error" == "$WEBI_CHANNEL" ]; then
-     echo "could not find release for ripgrep v${WEBI_VERSION}"
-     exit 1
-  fi
-  WEBI_VERSION=$(echo $WEBI_CSV | cut -d ',' -f 1)
-  WEBI_PKG_URL=$(echo $WEBI_CSV | cut -d ',' -f 9)
-  WEBI_PKG_FILE="$WEBI_TMP/$(echo $WEBI_PKG_URL | sed s:.*/::)"
-fi
-
 ###################
 # Install ripgrep #
 ###################
 
 new_rg="${HOME}/.local/bin/rg"
 
-# Test for existing version 
+# Test for existing version
 set +e
 cur_rg="$(command -v rg)"
 set -e
@@ -67,14 +41,19 @@ if [ -n "$cur_rg" ]; then
   fi
 fi
 
-# TODO move download to the webi bootstrap
-echo Downloading ripgrep v"${WEBI_VERSION}" from "${WEBI_PKG_URL}"
-curl -fsSL "${WEBI_PKG_URL}" -o "${WEBI_PKG_FILE}"
-pushd "${WEBI_TMP}" 2>&1 >/dev/null
-        echo Installing ripgrep v${WEBI_VERSION} as "$new_rg" 
-       tar xf "${WEBI_PKG_FILE}"
-        rm "${WEBI_PKG_FILE}"
-        mv ./ripgrep-*/rg "${HOME}/.local/bin/"
+# Note: this file is `source`d by the true installer and hence will have the webi functions
+
+# because we created releases.js we can use webi_download()
+# downloads ripgrep to ~/Downloads
+webi_download
+
+# because this is tar or zip, we can webi_extract()
+# extracts to the WEBI_TMP directory, raw (no --strip-prefix)
+webi_extract
+
+pushd "$WEBI_TMP" 2>&1 >/dev/null
+        echo Installing ripgrep v${WEBI_VERSION} as "$new_rg"
+        mv ./ripgrep-*/rg "$HOME/.local/bin/"
 popd 2>&1 >/dev/null
 
 ###################
@@ -82,7 +61,7 @@ popd 2>&1 >/dev/null
 ###################
 
 # TODO get better output from pathman / output the path to add as return to webi bootstrap
-pathman add "$HOME/.local/bin/"
+webi_path_add "$HOME/.local/bin"
 
 echo "Installed 'rg'"
 echo ""