#!/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 # Steam branch: "public" (default branch), "unstable", or a # version branch such as "42.19". # "bundled" keeps the steamclient.so files shipped with the # server; "steamcmd" replaces them with steamcmd's own, newer # copies (a known workaround for failing Workshop downloads). # # Writes the installed Steam build ID to /steam-buildid. set -o errexit set -o nounset set -o pipefail readonly APP_ID="380870" readonly MAX_ATTEMPTS=3 readonly STEAMCMD_DIR="${HOME}/.local/share/Steam/steamcmd" readonly INSTALL_DIR="$1" readonly BRANCH="$2" readonly STEAMCLIENT="$3" log() { echo "[install-server] $*" >&2 } install_app() { 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 } # Copies the build ID from Steam's app manifest, which is removed afterwards. record_build_id() { local manifest="${INSTALL_DIR}/steamapps/appmanifest_${APP_ID}.acf" local build_id build_id="$(grep --max-count=1 '"buildid"' "${manifest}" | tr --delete --complement '0-9')" if [[ -z "${build_id}" ]]; then log "No buildid found in ${manifest}" exit 1 fi echo "${build_id}" > "${INSTALL_DIR}/steam-buildid" log "Installed Steam build ${build_id}" } # The install root holds the 32-bit steamclient.so, linux64/ the 64-bit one. replace_steamclient() { case "${STEAMCLIENT}" in bundled) ;; steamcmd) log "Replacing the bundled steamclient.so files with steamcmd's" cp "${STEAMCMD_DIR}/linux32/steamclient.so" "${INSTALL_DIR}/steamclient.so" cp "${STEAMCMD_DIR}/linux64/steamclient.so" "${INSTALL_DIR}/linux64/steamclient.so" ;; *) log "Unknown steamclient option '${STEAMCLIENT}' (expected: bundled, steamcmd)" exit 1 ;; esac } main() { install_app record_build_id replace_steamclient # Steam's install metadata; not needed at runtime. rm --recursive --force "${INSTALL_DIR}/steamapps" } main