#!/bin/sh set -e echo "Current user is: $(whoami)" # Construct the SteamCMD login arguments. # We build a string that will be evaluated by the shell to handle credentials correctly. if [ -z "$STEAM_USER" ] || [ "$STEAM_USER" = "anonymous" ]; then echo "Using anonymous Steam login." LOGIN_ARGS="anonymous" else echo "Using Steam credentials for user '$STEAM_USER'." # Quoting the variables ensures that empty passwords or special characters are handled correctly. LOGIN_ARGS="\"$STEAM_USER\" \"$STEAM_PASSWORD\" \"$STEAM_GUARD_CODE\"" fi # The 'eval' command is used here to correctly parse the quoted LOGIN_ARGS string. # This is a safe use of eval because the variables are controlled by the user running the container. if [ -z "$MANIFEST_ID" ] || [ "$MANIFEST_ID" = "none" ]; then echo "MANIFEST_ID is not set. Downloading the latest stable version of the server..." eval steamcmd +force_install_dir "$SERVER_DIR" +login $LOGIN_ARGS +app_update 996560 validate +quit else echo "MANIFEST_ID is set to $MANIFEST_ID. Downloading specific server version..." eval steamcmd +login $LOGIN_ARGS +download_depot 996560 "$DEPOT_ID" "$MANIFEST_ID" +quit # download_depot downloads to a specific folder, not the one specified by force_install_dir DEPOT_DOWNLOAD_DIR="$INSTALL_DIR/steamapps/content/app_996560/depot_$DEPOT_ID" if [ -d "$DEPOT_DOWNLOAD_DIR" ] && [ "$(ls -A "$DEPOT_DOWNLOAD_DIR")" ]; then echo "Depot downloaded successfully. Clearing server directory..." find "$SERVER_DIR" -mindepth 1 -delete echo "Copying downloaded files from $DEPOT_DOWNLOAD_DIR to $SERVER_DIR" cp -rT "$DEPOT_DOWNLOAD_DIR" "$SERVER_DIR" echo "Successfully copied files." else echo "Error: Depot download failed or the directory is empty." >&2 echo "Please check MANIFEST_ID ($MANIFEST_ID) and DEPOT_ID ($DEPOT_ID), and ensure credentials are correct." >&2 exit 1 fi fi # Ensure config directory exists for server settings INTERNAL_CONFIG_SUBDIR="$CONFIG_DIR/SCP Secret Laboratory/config/" mkdir -p "$INTERNAL_CONFIG_SUBDIR" # Process the internal data template to accept the EULA, which is required on first run INTERNAL_DATA_TEMPLATE_FILE="$CONFIG_TEMPLATES_DIR/localadmin_internal_data.json.template" INTERNAL_DATA_FILE="$INTERNAL_CONFIG_SUBDIR/localadmin_internal_data.json" if [ ! -f "$INTERNAL_DATA_FILE" ]; then echo "Creating \`localadmin_internal_data.json\` file with EULA acceptance..." CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%S.%7NZ") sed "s/\${EulaDateAccepted}/$CURRENT_DATE/g" "$INTERNAL_DATA_TEMPLATE_FILE" > "$INTERNAL_DATA_FILE" chmod 644 "$INTERNAL_DATA_FILE" echo "Successfully created \`localadmin_internal_data.json\` file." fi echo "Starting SCP: Secret Laboratory server on port $PORT..." # Change to the server directory and execute the server binary cd "$SERVER_DIR" && HOME="$INSTALL_DIR" ./LocalAdmin "$PORT" # Fallback to keep the container alive if the server process exits sleep infinity