Keycloak insatll script
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.3 KiB

  1. #! /bin/bash
  2. RAND_PASS=`pwgen -s1 16`
  3. read -p "Keycloak version: " -ei '24.0.4' KEYCLOAK_VERSION
  4. read -p "Server hostname: " -ei 'keycloak.exmample.com' KEYCLOAK_HOST
  5. read -p "Postgres hostname: " -ei 'localhost' POSTGRES_HOST
  6. read -p "Postgres username: " -ei 'keycloak' POSTGRES_USER
  7. read -p "Postgres password: " -ei "$RAND_PASS" POSTGRES_PASS
  8. read -p "Postgres database: " -ei 'keycloak' POSTGRES_DB
  9. echo $PASSWORD_PASS > /usr/local/src/keycloak_db_pass
  10. if [ ! -f "keycloak-$KEYCLOAK_VERSION.tar.gz" ]; then
  11. wget https://github.com/keycloak/keycloak/releases/download/$KEYCLOAK_VERSION/keycloak-$KEYCLOAK_VERSION.tar.gz
  12. wget https://github.com/keycloak/keycloak/releases/download/$KEYCLOAK_VERSION/keycloak-$KEYCLOAK_VERSION.tar.gz.sha1
  13. fi
  14. SHA_HASH=`sha1sum keycloak-$KEYCLOAK_VERSION.tar.gz | cut -d" " -f1`
  15. KEYCLOAK_HASH=`cat keycloak-$KEYCLOAK_VERSION.tar.gz.sha1`
  16. if [ "$SHA_HASH" != "$KEYCLOAK_HASH" ]; then
  17. echo "Exit. Hash doesnt match."
  18. else
  19. sudo -u postgres psql -h $POSTGRES_HOST -c "CREATE DATABASE $POSTGRES_DB"
  20. sudo -u postgres psql -h $POSTGRES_HOST -c "CREATE USER $POSTGRES_USER WITH PASSWORD $POSTGRES_PASS"
  21. sudo -u postgres psql -h $POSTGRES_HOST -c "GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO $POSTGRES_USER"
  22. tar xpf keycloak-$KEYCLOAK_VERSION.tar.gz
  23. mv keycloak-$KEYCLOAK_VERSION /opt/keycloak
  24. echo "
  25. # Basic settings for running in production. Change accordingly before deploying the server.
  26. # Database
  27. # The database vendor.
  28. db=postgres
  29. # The username of the database user.
  30. db-username=$POSTGRES_USER
  31. # The password of the database user.
  32. db-password=$POSTGRES_PASS
  33. # The full database JDBC URL. If not provided, a default URL is set based on the selected database vendor.
  34. db-url=jdbc:postgresql://$POSTGRES_HOST/$POSTGRES_DB
  35. # Observability
  36. # If the server should expose healthcheck endpoints.
  37. health-enabled=true
  38. # If the server should expose metrics endpoints.
  39. metrics-enabled=true
  40. # HTTP
  41. # The proxy address forwarding mode if the server is behind a reverse proxy.
  42. proxy=edge
  43. proxy-headers=xforwarded
  44. # Do not attach route to cookies and rely on the session affinity capabilities from reverse proxy
  45. #spi-sticky-session-encoder-infinispan-should-attach-route=false
  46. # Hostname for the Keycloak server.
  47. hostname=$KEYCLOAK_HOST
  48. hostname-strict=false" > /opt/keycloak/conf/keyclaok.conf
  49. fi