#!/usr/bin/env bash # # Prints the current Steam build ID of a branch of the Project Zomboid # dedicated server (app 380870), using steamcmd in a container. # # Usage: steam-buildid.sh # Steam branch: public, unstable, or a version branch such as 42.19 # # Environment: # CONTAINER_ENGINE docker or podman. Default: docker if installed, else podman set -o errexit set -o nounset set -o pipefail readonly APP_ID="380870" readonly STEAMCMD_IMAGE="docker.io/steamcmd/steamcmd:debian-13" readonly BRANCH="$1" log() { echo "[steam-buildid] $*" >&2 } container_engine() { if [[ -n "${CONTAINER_ENGINE:-}" ]]; then echo "${CONTAINER_ENGINE}" elif command -v docker > /dev/null; then echo "docker" else echo "podman" fi } # Prints app_info for the app. The output is Valve KeyValues text; the # "branches" section contains one block per branch with its "buildid". print_app_info() { "$(container_engine)" run --rm "${STEAMCMD_IMAGE}" \ +login anonymous \ +app_info_update 1 \ +app_info_print "${APP_ID}" \ +quit } # Reads the buildid of the branch block inside the "branches" section. extract_build_id() { awk -v branch="\"${BRANCH}\"" ' $1 == "\"branches\"" { in_branches = 1; next } in_branches && $1 == branch { in_branch = 1; next } in_branch && $1 == "\"buildid\"" { gsub(/"/, "", $2); print $2; exit } in_branch && $1 == "}" { exit } ' } main() { local app_info local build_id # Captured first: extract_build_id stops reading early, which would end # print_app_info with SIGPIPE inside a pipeline. app_info="$(print_app_info)" build_id="$(extract_build_id <<< "${app_info}")" if [[ -z "${build_id}" ]]; then log "No build ID found for branch '${BRANCH}' of app ${APP_ID}" exit 1 fi echo "${build_id}" } main