add version check to installer to avoid re-downloading the same version

This commit is contained in:
CJ van den Berg 2025-04-14 19:53:11 +02:00
parent 8ec3c54b97
commit ac54438fbe
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -8,6 +8,7 @@ nightly=${NIGHTLY:-0}
verify=${VERIFY:-0}
local=${LOCAL:-0}
use_sudo=${USE_SUDO:-0}
force_update=${FORCE_UPDATE:-0}
usage() {
echo "Options:"
@ -17,6 +18,7 @@ usage() {
echo " -d <path>, --dest <path> Set install destination (default /usr/local/bin)"
echo " -V, --verify Verify gpg signature"
echo " -l, --local Verify gpg signature with local keychain"
echo " -F, --force Force re-install even if flow is up-to-date"
exit 1
}
@ -31,7 +33,7 @@ while true; do
shift 1
;;
-d | --dest)
install_dir=/$2
install_dir=$2
shift 2
;;
-V | --verify)
@ -42,6 +44,10 @@ while true; do
local=1
shift 1
;;
-F | --force)
force_update=1
shift 1
;;
-h | --help)
usage
;;
@ -154,6 +160,18 @@ version=$(curl -s "https://api.github.com/repos/$repo/releases/latest" | grep '"
}
title="$title $version"
if [ "$force_update" -eq 0 ] && [ -e "$install_dir/flow" ]; then
current_version=$(flow --version 2>/dev/null | grep version: | cut -f2 -d ' ')
if [ "$current_version" = "$version" ]; then
echo "flow is up-to-date (version $version @ $install_dir/flow)"
exit 0
else
if [ -n "$current_version" ]; then
echo "updating flow from $current_version to $version"
fi
fi
fi
# construct download url
# note: nightly assets are named like "flow-<version>-<os>-<arch>.<ext>"
filename="flow-$version-$os-$arch"