From 2927408ddd4c5e1240afc23980edb428ca678175 Mon Sep 17 00:00:00 2001 From: Javier Matias-Cabrera Date: Mon, 19 Sep 2022 20:59:54 -0400 Subject: [PATCH] Use Github API to download binaries. --- global_install_scripts/install.bash | 11 +++-------- global_install_scripts/update_talisman.bash | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/global_install_scripts/install.bash b/global_install_scripts/install.bash index 79c1b62e..a52f5fd4 100755 --- a/global_install_scripts/install.bash +++ b/global_install_scripts/install.bash @@ -72,12 +72,6 @@ function run() { } export -f echo_success - function collect_version_artifact_download_urls() { - curl -Ls -w %{url_effective} "https://github.com/${INSTALL_ORG_REPO}/releases/latest" | grep -Eo '/'${INSTALL_ORG_REPO}'/releases/download/.+/[^/"]+' | sed 's/^/https:\/\/github.com/' >${TEMP_DIR}/download_urls - echo_debug "All release artifact download urls can be found at ${TEMP_DIR}/download_urls:" - [[ -z "${DEBUG}" ]] && return - cat ${TEMP_DIR}/download_urls - } function operating_system() { OS=$(uname -s) @@ -135,7 +129,9 @@ function run() { function download() { OBJECT=$1 - DOWNLOAD_URL=$(grep 'http.*'${OBJECT}'$' ${TEMP_DIR}/download_urls) + DOWNLOAD_URL=$(curl -Ls https://api.github.com/repos/"$INSTALL_ORG_REPO"/releases/latest | + grep download_url | awk '{print $2}' | tr -d '"' | grep "$OBJECT") + echo_debug "Downloading ${OBJECT} from ${DOWNLOAD_URL}" curl --location --silent ${DOWNLOAD_URL} >${TEMP_DIR}/${OBJECT} } @@ -399,7 +395,6 @@ END_OF_SCRIPT # would be good to create a separate script which does the upgrade and the initial install if [[ ! -x ${TALISMAN_SETUP_DIR}/${TALISMAN_BINARY_NAME} || ! -x ${TALISMAN_HOOK_SCRIPT_PATH} || -n ${FORCE_DOWNLOAD} ]]; then echo "Downloading talisman binary" - collect_version_artifact_download_urls download_talisman_binary echo echo "Setting up talisman binary and helper script in $HOME/.talisman" diff --git a/global_install_scripts/update_talisman.bash b/global_install_scripts/update_talisman.bash index 294092cc..f3dea825 100755 --- a/global_install_scripts/update_talisman.bash +++ b/global_install_scripts/update_talisman.bash @@ -48,12 +48,6 @@ function run() { } export -f echo_success - function collect_version_artifact_download_urls() { - curl -Ls -w %{url_effective} "https://github.com/${INSTALL_ORG_REPO}/releases/latest" | grep -Eo '/'${INSTALL_ORG_REPO}'/releases/download/.+/[^/"]+' | sed 's/^/https:\/\/github.com/' >${TEMP_DIR}/download_urls - echo_debug "All release artifact download urls can be found at ${TEMP_DIR}/download_urls:" - [[ -z "${DEBUG}" ]] && return - cat ${TEMP_DIR}/download_urls - } function operating_system() { OS=$(uname -s) @@ -113,7 +107,9 @@ function run() { function download() { echo_debug "Running download()" OBJECT=$1 - DOWNLOAD_URL=$(grep 'http.*'${OBJECT}'$' ${TEMP_DIR}/download_urls) + DOWNLOAD_URL=$(curl -Ls https://api.github.com/repos/"$INSTALL_ORG_REPO"/releases/latest | + grep download_url | awk '{print $2}' | tr -d '"' | grep "$OBJECT") + echo_debug "Downloading ${OBJECT} from ${DOWNLOAD_URL}" curl --location --silent ${DOWNLOAD_URL} >${TEMP_DIR}/${OBJECT} } @@ -177,7 +173,6 @@ function run() { set_talisman_binary_name echo "Downloading latest talisman binary..." - collect_version_artifact_download_urls download_talisman_binary setup_talisman if [ -z "$UPDATE_TYPE" ]; then