From 58176fd84cd41458ba6b8933a5146a3fc151634d Mon Sep 17 00:00:00 2001 From: Milan Date: Wed, 23 Oct 2024 15:20:21 +0200 Subject: [PATCH] smarter keycloak update script --- updates/keycloak.sh | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/updates/keycloak.sh b/updates/keycloak.sh index d25c985..e334bc8 100644 --- a/updates/keycloak.sh +++ b/updates/keycloak.sh @@ -1,14 +1,14 @@ #!/bin/bash set -e -if [ -z "$1" ] -then - echo "ERROR: Can't continue. Version querying not implemented, because we might not use the latest major release." - echo "Usage: bash ./update.sh 9.9.9" - exit 1 -fi -export XDG_RUNTIME_DIR=/run/user/$UID +# +# Use ./update.sh 1.2.3 to OVERRIDE the release check. +# +# Without an argument, THIS SCRIPT WILL AUTODETECT the release +# that was tagged as "latest" by the project. +# +export XDG_RUNTIME_DIR=/run/user/$UID location=$HOME olddir=`readlink $location/latest` @@ -16,14 +16,37 @@ olddir=`readlink $location/latest` # script does not require this to function #themename=mytheme +if [ -z "$1" ] + then + release=`curl -L https://api.github.com/repos/keycloak/keycloak/releases/latest -s | jq -r '.tag_name'` + echo ">>> Detected v$release being tagged as the latest release." + else + release=$1 +fi + +current_release=$(cat latest/version.txt) +current_release=${current_release#'Keycloak - Version '} + +if [[ $current_release == "$release" ]] + then + echo ">>> It appears, are on v$current_release. Nothing to do." + exit + else + read -p "Proceed? With Keycloak ${release}?" -n 1 -r + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 + fi +fi + systemctl stop --user keycloak cd $location # FIXME: move to rsync or use git tags directly -wget "https://github.com/keycloak/keycloak/releases/download/$1/keycloak-$1.zip" -unzip keycloak-$1.zip -rm keycloak-$1.zip +wget "https://github.com/keycloak/keycloak/releases/download/$release/keycloak-$release.zip" +unzip keycloak-$release.zip +rm keycloak-$release.zip [ -L $location/latest ] && rm -v $location/latest ln -sv $location/keycloak-$1 $location/latest