-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·63 lines (50 loc) · 2.5 KB
/
install.sh
File metadata and controls
executable file
·63 lines (50 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/bash
# List of the required environment variables.
required_vars=("KC_BOOTSTRAP_ADMIN_USERNAME" "KC_BOOTSTRAP_ADMIN_PASSWORD" "DATABASE_JDBC_STRING" "DATABASE_USER" "DATABASE_PASSWORD")
missing_vars=()
# Check if an old version of Keycloak is present.
# If it is present, delete the older version.
# This is to ensure the latest updates & security patches.
if [ -f ./KEYCLOAK_VERSION ]; then
echo [LOG] Removing Previous Version Of Keycloak!
rm -rf keycloak-$(cat ./KEYCLOAK_VERSION)
fi
# Check whether the required environment variables are present.
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
missing_vars+=("$var")
fi
done
# Display a message in case there is an environment variable missing.
if [ ${#missing_vars[@]} -gt 0 ]; then
echo "Please set the following environment variables before installation: ${missing_vars[*]}"
exit 1
fi
# Set the required variables to proceed with the installation.
repo_url="https://github.com/keycloak/keycloak"
version_file="KEYCLOAK_VERSION"
# Fetch the latest version of Keycloak to include the latest updates & security patches.
latest_tag=$(curl -sSLI -o /dev/null -w '%{url_effective}' "${repo_url}/releases/latest" | awk -F/ '/tag/{print $NF}')
# Just in case the script is unable to fetch the latest version.
if [ -z "$latest_tag" ]; then
echo "Failed to retrieve the latest release tag. Exiting."
exit 1
fi
# Write the latest version to a separate file so that it can be started & updated in the future.
echo "$latest_tag" > "$version_file"
download_url="${repo_url}/releases/download/${latest_tag}/keycloak-${latest_tag}.tar.gz"
destination_file="keycloak-${latest_tag}.tar.gz"
# Download the Keycloak code.
echo "[LOG] Downloading Latest Version Of Keycloak: ${download_url}..."
curl -sSL -o "${destination_file}" "${download_url}" && echo "Download successful! File saved as ${destination_file}" || echo "Download failed. Please try again."
# Keycloak requires Java, the below script installs Java from NixPkgs for NixOS (https://search.nixos.org/packages?channel=23.11&show=zulu&from=0&size=50&sort=relevance&type=packages&query=java)
echo "[LOG] Installing Java via Zulu"
nix-env -iA nixpkgs.zulu
# Extract the compressed file.
echo "[LOG] Extracting Keycloak"
tar -xvf ./keycloak-${latest_tag}.tar.gz
# Delete the compressed file since it has already been uncompressed.
echo "[LOG] Deleting the tar file"
rm -rf ./keycloak-${latest_tag}.tar.gz
# Complete Confirmation!
echo "[LOG] Installation Completed. Execute the \"RUN\" CI command."