fix: Ensure Steam credentials are used for downloads

This commit is contained in:
Mikolaj Wojciech Gorski 2025-07-24 23:58:34 +02:00
parent 0b76ab9022
commit f00af75333
2 changed files with 32 additions and 26 deletions

View file

@ -5,18 +5,13 @@ services:
dockerfile: Dockerfile
container_name: scp-sl-server
ports:
- "7777:7777/udp"
- 7777:7777/udp
volumes:
- ./config:/home/steam/.config
- /home/oliwier/dockerData/scpsl/config:/home/steam/.config
environment:
- UID=1000
- GID=1000
# To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this [list](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List).
# - TZ=Etc/UTC
# To download a specific version of the server, uncomment the next line and set the value to a valid manifest ID.
# - MANIFEST_ID=none
# If you need to use your own Steam credentials, uncomment and set the following variables.
# - STEAM_USER=your_steam_username
# - STEAM_PASSWORD=your_steam_password
# - STEAM_GUARD_CODE=your_2fa_code
- STEAM_USER=thestopa
- STEAM_PASSWORD=${ST_PASSWORD}
restart: unless-stopped
networks: {}

View file

@ -3,16 +3,27 @@ set -e
echo "Current user is: $(whoami)"
# Install/update SCP:SL server
if [ "$MANIFEST_ID" = "none" ]; then
echo "MANIFEST_ID not set, downloading latest server version..."
steamcmd +force_install_dir $SERVER_DIR +login "$STEAM_USER" "$STEAM_PASSWORD" "$STEAM_GUARD_CODE" +app_update 996560 validate +quit
# 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 "MANIFEST_ID set to $MANIFEST_ID, downloading specific server version..."
# download_depot downloads to a specific folder, not the one specified by force_install_dir
# It will be downloaded to <install_dir>/steamapps/content/app_<id>/depot_<id>
steamcmd +login "$STEAM_USER" "$STEAM_PASSWORD" "$STEAM_GUARD_CODE" +download_depot 996560 $DEPOT_ID $MANIFEST_ID +quit
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
@ -23,29 +34,29 @@ else
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)" >&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
# 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 EULA
# 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..."
# Get current date in the correct format
CURRENT_DATE=$(date -u +"%Y-%m-%dT%H:%M:%S.%7NZ")
# Replace placeholder in template
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 with EULA acceptance."
echo "Successfully created \`localadmin_internal_data.json\` file."
fi
# Run server
cd $SERVER_DIR && HOME=$INSTALL_DIR ./LocalAdmin $PORT
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