#! /bin/sh

STATUS_CODE="$(curl -s -o /dev/null -w '%{http_code}' http://imxc-keycloak-http/auth/realms/exem)"

if [ $STATUS_CODE -eq 200 ]; then
  JWT_KEY="$(curl -s -XGET http://imxc-keycloak-http/auth/realms/exem | jq -r '.public_key')"
  export JWT_KEY

  chmod -R 777 /home/cloudmoa/notification/cloudmoa_alert.log

  /sbin/tini -- java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
  #java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
elif [ $STATUS_CODE -eq 404 ]; then
  echo "not found exem relam. check realm in imxc-keycloak"
else
  echo "not found keycloak. check to install keycloak"
fi
