Files
ZomboidForge/docker/install-server.sh
T

56 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Installs the vanilla Project Zomboid dedicated server (Steam app 380870)
# with steamcmd, using an anonymous login. Runs in the steamcmd image during
# the Docker build.
#
# Usage: install-server.sh <install-dir> <branch>
# <branch> Steam branch; "public" is the default branch.
set -o errexit
set -o nounset
set -o pipefail
readonly APP_ID="380870"
readonly MAX_ATTEMPTS=3
readonly INSTALL_DIR="$1"
readonly BRANCH="$2"
log() {
echo "[install-server] $*" >&2
}
main() {
local branch_args=()
if [[ "${BRANCH}" != "public" ]]; then
branch_args=("-beta" "${BRANCH}")
fi
# app_update can fail with "Missing configuration" right after steamcmd
# updated itself; a repeated attempt succeeds.
local attempt
for (( attempt = 1; attempt <= MAX_ATTEMPTS; attempt++ )); do
log "Installing app ${APP_ID} (branch ${BRANCH}), attempt ${attempt}/${MAX_ATTEMPTS}"
if steamcmd \
+force_install_dir "${INSTALL_DIR}" \
+login anonymous \
+app_update "${APP_ID}" "${branch_args[@]}" validate \
+quit
then
break
fi
log "steamcmd failed on attempt ${attempt}"
done
if [[ ! -f "${INSTALL_DIR}/java/projectzomboid.jar" ]]; then
log "Installation failed: ${INSTALL_DIR}/java/projectzomboid.jar not found"
exit 1
fi
# Steam's install metadata; not needed at runtime.
rm --recursive --force "${INSTALL_DIR}/steamapps"
}
main