From c7080d2834700529f0a816fec1771c1e5eee5a00 Mon Sep 17 00:00:00 2001 From: Hidde Beydals Date: Mon, 11 Jan 2021 11:30:43 +0100 Subject: [PATCH] Configure `project_name` for GoReleaser This causes the format of the checksum file generated during the release to change from `flux2_*_checksums.txt` to `flux_*_checksums.txt`. The configuration change is made through `project_name` and not via the `checksum.name_template` setting, because a single checksum file is generated during the release process. The download and/or installation script in `install/flux.sh` has been adapted to assume the new filename starting with MINOR version `0.6.0`. Signed-off-by: Hidde Beydals --- .goreleaser.yml | 1 + install/flux.sh | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 8a6de6a0..dd0e4b69 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,3 +1,4 @@ +project_name: flux builds: - <<: &build_defaults binary: flux diff --git a/install/flux.sh b/install/flux.sh index 83c727cb..1394b97c 100755 --- a/install/flux.sh +++ b/install/flux.sh @@ -76,7 +76,7 @@ setup_tmp() { TMP_HASH="${TMP_DIR}/flux.hash" TMP_BIN="${TMP_DIR}/flux.tar.gz" cleanup() { - code=$? + local code=$? set +e trap - EXIT rm -rf "${TMP_DIR}" @@ -120,9 +120,51 @@ download() { [[ $? -eq 0 ]] || fatal 'Download failed' } +# Version comparison +# Returns 0 on '=', 1 on '>', and 2 on '<'. +# Ref: https://stackoverflow.com/a/4025065 +vercomp () { + if [[ $1 == $2 ]] + then + return 0 + fi + local IFS=. + local i ver1=($1) ver2=($2) + # fill empty fields in ver1 with zeros + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do + ver1[i]=0 + done + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then + # fill empty fields in ver2 with zeros + ver2[i]=0 + fi + if ((10#${ver1[i]} > 10#${ver2[i]})) + then + return 1 + fi + if ((10#${ver1[i]} < 10#${ver2[i]})) + then + return 2 + fi + done + return 0 +} + # Download hash from Github URL download_hash() { - HASH_URL="https://github.com/${GITHUB_REPO}/releases/download/v${VERSION_FLUX}/flux2_${VERSION_FLUX}_checksums.txt" + HASH_URL="https://github.com/${GITHUB_REPO}/releases/download/v${VERSION_FLUX}/flux_${VERSION_FLUX}_checksums.txt" + # NB: support the checksum filename format prior to v0.6.0 + set +e + vercomp ${VERSION_FLUX} 0.6.0 + if [[ $? -eq 2 ]]; then + HASH_URL="https://github.com/${GITHUB_REPO}/releases/download/v${VERSION_FLUX}/flux2_${VERSION_FLUX}_checksums.txt" + fi + set -e + info "Downloading hash ${HASH_URL}" download "${TMP_HASH}" "${HASH_URL}" HASH_EXPECTED=$(grep " flux_${VERSION_FLUX}_${OS}_${ARCH}.tar.gz$" "${TMP_HASH}")