Skip to content

Instantly share code, notes, and snippets.

@vigindian
Created April 27, 2023 06:11
Show Gist options
  • Save vigindian/5d98033acfdc5c92db186aa9569f72d6 to your computer and use it in GitHub Desktop.
Save vigindian/5d98033acfdc5c92db186aa9569f72d6 to your computer and use it in GitHub Desktop.
Keycloak Upgrade script
#!/bin/bash
##################################################################
# Keycloak Upgrade Script
#
# VN
#
# Assumptions:
# - soft-link with name "current" exists to live keycloak folder
# - keycloak uses postgresql backend
# - keycloak is run as systemctl service as user 'keycloak'
##################################################################
#script needs elevated privileges
if [ ${UID} != 0 ];then
err "script should be run as root or sudo"
fi
KCHOME="/home/keycloak"
KCMODE="standalone"
KCNEWVER="12.0.4"
if [ -d ${KCHOME} ];then
systemctl stop keycloak
cd ${KCHOME}
#download package and extract
wget https://github.com/keycloak/keycloak/releases/download/${KCNEWVER}/keycloak-${KCNEWVER}.tar.gz
tar xzvf keycloak-${KCNEWVER}.tar.gz
#migrate config and customisations from current to new
cp -pr current/standalone/* keycloak-${KCNEWVER}/standalone/
#cp -pr current/themes/yourcompany/ keycloak-${KCNEWVER}/themes/ #copy your custom themes
#postgres driver
cp -pr current/modules/system/layers/keycloak/org/postgresql/ keycloak-${KCNEWVER}/modules/system/layers/keycloak/org/
#run upgrade script
keycloak-${KCNEWVER}/bin/jboss-cli.sh --file=keycloak-${KCNEWVER}/bin/migrate-${KCMODE}.cli
#ensure perm is correct
chown -R keycloak:users keycloak-${KCNEWVER}
#point to new keycloak instance
ln -sfn keycloak-${KCNEWVER} current
systemctl start keycloak
else
echo "ERR: Keycloak Home directory ${KCHOME} does not exist!"
exit 11
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment