#!/usr/bin/env bash
set -e

: "${ACEVO_APP_ID:=4564210}"

if [ -z "$STEAM_USERNAME" ] || [ -z "$STEAM_PASSWORD" ]; then
  echo "ERROR: STEAM_USERNAME and STEAM_PASSWORD must be set."
  exit 1
fi

echo "[----] Fixing permissions on /app..."
# Fix ALL permissions the manager needs
chown -R steam:steam /app 2>/dev/null || true

echo "[----] Launching SteamCMD update..."

"${STEAMCMD_DIR}/steamcmd.sh" \
  +force_install_dir "${ACEVO_INSTALL_DIR}" \
  +login "$STEAM_USERNAME" "$STEAM_PASSWORD" \
  +app_update "${ACEVO_APP_ID}" validate \
  +quit

echo "[----] AC Evo server updated."

cd /app

echo "[----] Starting AC Evo Server Manager..."
exec ./acevo-server-manager
