#!/bin/bash # Get the directory where this script is located SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # Get username from ego-mgr username=$(ego-mgr get default-username) # Check if username is provided if [[ -z "$username" ]]; then echo "Error: default-username not set in ego-mgr, please contact ard" exit 1 fi realm="Hangman-Lab" # Check if user exists result=$("$SCRIPT_DIR/kcadm" get users -r "$realm" -q "username=$username") user_count=$(echo "$result" | jq 'length') if [[ "$user_count" -eq 0 ]]; then echo "Error: User $username not found in Keycloak" exit 1 fi # Get user ID userid=$(echo "$result" | jq -r '.[0].id') # Set firstName and lastName "$SCRIPT_DIR/kcadm" update users/"$userid" -r "$realm" \ --set "firstName=$username" \ --set "lastName=$username" echo "Name set for user: $username (firstName=$username, lastName=$username)"