Add kcw script to Keycloak repository

Signed-off-by: stianst <stianst@gmail.com>
This commit is contained in:
stianst 2025-06-04 08:56:43 +02:00 committed by Stian Thorgersen
parent 6f4af1f390
commit f7a948fbe7
2 changed files with 180 additions and 0 deletions

37
misc/scripts/README.md Normal file
View File

@ -0,0 +1,37 @@
## dependency-report.sh
Search for a dependency in the Keycloak project to identify where it is used, and if there are multiple versions in use.
For example:
```
misc/scripts/dependency-report.sh org.twitter4j:twitter4j-core
```
Will output a report like:
```
===================================================================================================
Dependency tree for org.twitter4j:twitter4j-core
---------------------------------------------------------------------------------------------------
org.keycloak:keycloak-services:jar:999.0.0-SNAPSHOT
\- org.twitter4j:twitter4j-core:jar:4.1.2:compile
org.keycloak:keycloak-crypto-fips1402:jar:999.0.0-SNAPSHOT
\- org.keycloak:keycloak-services:jar:999.0.0-SNAPSHOT:compile
\- org.twitter4j:twitter4j-core:jar:4.1.2:compile
...
```
# kcw
Provides a quick and convenient way of starting a Keycloak server, supporting a specific version, a locally built version,
or the nightly release.
Examples:
```
kcw dev start-dev
kcw nightly start --hostname=mykeycloak
```
For more details run `kcw help`.

143
misc/scripts/kcw Executable file
View File

@ -0,0 +1,143 @@
#!/bin/bash -e
KC_DIR=~/kc
if [ "$KC_SRC_HOME" != "" ]; then
SRC_DIR="$KC_SRC_HOME"
else
SRC_DIR=$(readlink -f "$0" | sed 's|/misc/scripts/kcw||')
fi
DL_DIR=~/Downloads
ARGS=""
while [ "$1" != "" ]; do
if [ "$1" == "dev" ]; then
INSTALL="dev"
elif [ "$1" == "dev-build" ]; then
INSTALL="dev"
BUILD=1
elif [ "$1" == "rel" ]; then
INSTALL=$(curl --silent https://api.github.com/repos/keycloak/keycloak/releases/latest | jq -r .tag_name)
elif [[ "$1" =~ "rel=" ]]; then
INSTALL=`echo $1 | cut -d '=' -f 2`
elif [ "$1" == "nightly" ]; then
INSTALL="nightly"
elif [ "$1" = "help" ]; then
echo "Usage: kcw [command] [kc commands]"
echo " dev install from local fork"
echo " dev-build build and install from local fork"
echo " nightly install nightly release"
echo " rel install latest release"
echo " rel[=version] install specific version"
echo ""
echo "Examples:"
echo " Start existing install: kcw start-dev"
echo " Install nightly and start: kcw nightly start-dev --cluster=none"
exit
else
ARGS="$ARGS $1"
fi
shift
done
echo "###########################################################################################"
echo "Installing: $INSTALL"
echo "Executing: bin/kc.sh$ARGS"
echo "###########################################################################################"
if [ "$INSTALL" != "" ]; then
# Clean current install
PID=$(ps -e -wwf | grep java | grep "$KC_DIR" | awk '{ print $2 }')
if [ "$PID" != "" ]; then
echo ""
echo "-------------------------------------------------------------------------------------------"
echo "Killing existing install"
echo "-------------------------------------------------------------------------------------------"
kill -9 $PID
echo "Killed: $PID"
fi
if [ -d $KC_DIR ]; then
echo ""
echo "-------------------------------------------------------------------------------------------"
echo "Deleting existing install"
echo "-------------------------------------------------------------------------------------------"
rm -rf $KC_DIR
echo "Deleted $KC_DIR"
fi
if [ "$INSTALL" == "dev" ]; then
VERSION=$(cat $SRC_DIR/pom.xml | grep '<version>' | head -n 2 | tail -n 1 | cut -d '>' -f 2 | cut -d '<' -f 1)
if [ "$BUILD" ]; then
echo ""
echo "-------------------------------------------------------------------------------------------"
echo "Building"
echo "-------------------------------------------------------------------------------------------"
#mvn -pl quarkus/dist -am -DskipTests -f $SRC_DIR/pom.xml -T 1C --offline clean install
cd $SRC_DIR
./mvnw -T 1C -Dmaven.build.cache.enabled=true -DskipTests -DskipTestsuite -DskipExamples -DskipAdapters -DskipDocs install
fi
echo ""
echo "-------------------------------------------------------------------------------------------"
echo "Installing"
echo "-------------------------------------------------------------------------------------------"
cd /tmp/
unzip -q $SRC_DIR/quarkus/dist/target/keycloak-$VERSION.zip
mv keycloak-$VERSION $KC_DIR
echo "Built and installed $VERSION from $SRC_DIR"
else
VERSION=$INSTALL
if [ "$INSTALL" == "nightly" ]; then
VERSION=999.0.0-SNAPSHOT
fi
echo ""
echo "-------------------------------------------------------------------------------------------"
echo "Installing"
echo "-------------------------------------------------------------------------------------------"
cd $DL_DIR
if [ -f keycloak-$VERSION.zip ]; then
if ( ! md5sum keycloak-$VERSION.zip | grep $(wget -q -O - https://github.com/keycloak/keycloak/releases/download/$INSTALL/keycloak-$VERSION.zip.md5) &>/dev/null ); then
echo "Checksum doesn't match deleting keycloak-$VERSION.zip"
rm keycloak-$VERSION.zip
fi
fi
if [ ! -f keycloak-$VERSION.zip ]; then
cd $DL_DIR
echo "Downloading keycloak-$VERSION.zip"
wget -q https://github.com/keycloak/keycloak/releases/download/$INSTALL/keycloak-$VERSION.zip
fi
cd /tmp/
unzip -q $DL_DIR/keycloak-$VERSION.zip
mv keycloak-$VERSION $KC_DIR
echo "Installed $VERSION"
fi
fi
if [ "$ARGS" != "" ]; then
echo ""
echo "-------------------------------------------------------------------------------------------"
echo "Running: bin/kc.sh$ARGS"
echo "-------------------------------------------------------------------------------------------"
export KC_BOOTSTRAP_ADMIN_USERNAME=admin
export KC_BOOTSTRAP_ADMIN_PASSWORD=admin
export KC_BOOTSTRAP_ADMIN_CLIENT_ID=admin
export KC_BOOTSTRAP_ADMIN_CLIENT_SECRET=admin
cd $KC_DIR/bin
./kc.sh $ARGS
fi