Keycloak: fix update function (#6943)

* Keycloak: fix update function

* fix issue with .keycloak file

* Update keycloak-install.sh

* remove double command

---------

Co-authored-by: Tobias <96661824+CrazyWolf13@users.noreply.github.com>
This commit is contained in:
CanbiZ 2025-08-18 20:16:14 +02:00 committed by GitHub
parent 70cd362d3e
commit 23c6994835
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 42 additions and 30 deletions

View File

@ -27,38 +27,50 @@ function update_script() {
msg_error "No ${APP} Installation Found!" msg_error "No ${APP} Installation Found!"
exit exit
fi fi
if ! command -v jq &>/dev/null; then
$STD apt-get install -y jq
fi
msg_info "Stopping Keycloak" RELEASE=$(curl -fsSL https://api.github.com/repos/keycloak/keycloak/releases/latest | jq -r '.tag_name' | sed 's/^v//')
systemctl stop keycloak if [[ "${RELEASE}" != "$(cat ~/.keycloak_app 2>/dev/null)" ]] || [[ ! -f ~/.keycloak_app ]]; then
msg_ok "Stopped Keycloak" msg_info "Stopping Keycloak"
systemctl stop keycloak
msg_ok "Stopped Keycloak"
msg_info "Updating packages" msg_info "Updating packages"
$STD apt-get update $STD apt-get update
$STD apt-get -y upgrade $STD apt-get -y upgrade
msg_ok "Updated packages" msg_ok "Updated packages"
msg_info "Backup old Keycloak" msg_info "Backup old Keycloak"
cd /opt cd /opt
mv keycloak keycloak.old mv keycloak keycloak.old
tar -czf keycloak_conf_backup.tar.gz keycloak.old/conf msg_ok "Backup done"
msg_ok "Backup done"
fetch_and_deploy_gh_release "keycloak" "keycloak/keycloak" "prebuild" "latest" "/opt/keycloak" "keycloak-*.tar.gz" fetch_and_deploy_gh_release "keycloak_app" "keycloak/keycloak" "prebuild" "latest" "/opt/keycloak" "keycloak-*.tar.gz"
msg_info "Updating ${APP}" msg_info "Updating ${APP}"
cd /opt cd /opt
mv keycloak_conf_backup.tar.gz keycloak/conf cp -a keycloak.old/conf/. keycloak/conf/
cp -r keycloak.old/providers keycloak cp -a keycloak.old/providers/. keycloak/providers/ 2>/dev/null || true
cp -r keycloak.old/themes keycloak cp -a keycloak.old/themes/. keycloak/themes/ 2>/dev/null || true
rm -rf keycloak.old msg_ok "Updated ${APP} LXC"
msg_ok "Updated ${APP} LXC"
msg_info "Restarting Keycloak" msg_info "Restarting Keycloak"
systemctl restart keycloak systemctl restart keycloak
msg_ok "Restarted Keycloak" msg_ok "Restarted Keycloak"
msg_info "Cleaning up"
rm -rf keycloak.old
msg_ok "Cleanup complete"
msg_ok "Update Successful"
else
msg_ok "No update required. ${APP} is already at v${RELEASE}"
fi
exit exit
} }
start start
build_container build_container
description description

View File

@ -25,7 +25,7 @@ $STD sudo -u postgres psql -c "CREATE DATABASE $DB_NAME WITH OWNER $DB_USER ENCO
$STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;" $STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME TO $DB_USER;"
msg_ok "Configured PostgreSQL" msg_ok "Configured PostgreSQL"
fetch_and_deploy_gh_release "keycloak" "keycloak/keycloak" "prebuild" "latest" "/opt/keycloak" "keycloak-*.tar.gz" fetch_and_deploy_gh_release "keycloak_app" "keycloak/keycloak" "prebuild" "latest" "/opt/keycloak" "keycloak-*.tar.gz"
msg_info "Creating Service" msg_info "Creating Service"
cat <<EOF >/etc/systemd/system/keycloak.service cat <<EOF >/etc/systemd/system/keycloak.service