#!/bin/sh
if [ -n "$APP_UID" ] && [ -n "$APP_GID" ]; then
  echo "Changing reitti user/group to UID:$APP_UID / GID:$APP_GID"
  # Add shadow package for usermod and groupmod commands
  apk add --no-cache shadow
  # Change GID first
  groupmod -g $APP_GID reitti
  # Then change UID
  usermod -u $APP_UID reitti
  # Fix ownership of all files
  chown -R reitti:reitti $APP_HOME
fi
# Ensure data directory exists and has correct ownership
mkdir -p $DATA_DIR
chown -R reitti:reitti $DATA_DIR
exec su-exec reitti java $JAVA_OPTS -jar $APP_HOME/app.jar -Dspring.profiles.active=docker "$@"
