mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-23 11:06:18 +01:00
`./run.sh <anything>` is now the entry point. It installs its own dependencies (steamcmd via yay, DepotDownloader from the SteamRE release, a local .venv) and works out what the argument is: an appid, a Steam URL, an exact title, or part of a title. Every route is confirmed through steamcmd's own app_info before anything acts on it. Name search moves to steamcommunity.com/actions/SearchApps, which works, with the storefront API kept as a fallback -- it TLS-rejects scripted clients here, so search had been effectively dead. DNS on this box fails transiently about one lookup in three, so each backend is retried before giving up. An exact title now wins over Steam's own ranking, which puts "Portal 2" above "Portal"; an ambiguous name shows a picker, or exits 2 rather than guessing. Two problems found while building this, both now handled: Anonymous steamcmd has no licence for a paid app and does not say so. It transfers nothing, prints "Success! App '284160' fully installed.", exits 0, and writes StateFlags=4 with SizeOnDisk=0 and no depots. A running Steam client then reads that, decides the app is installed but stale, and downloads the whole game by itself. `ghost.py` detects that state -- validated read-only against all ten manifests in a real library, where the nine genuine installs are untouched and only the fabricated one matches -- and `--repair-ghosts` clears it away. Repair uses rmdir, never rmtree, so a non-empty directory survives a wrong diagnosis. And Steam's own in-progress downloads are no longer wasted. `takeover.py` hardlinks `steamapps/downloading/<appid>/` into the install directory before depotdownloader runs; depotdownloader hash-checks what is already on disk (ContentDownloader.cs skips a file when neededChunks is empty) and fetches only the remainder. Nothing is deleted up front -- the staging tree is cleared only after the install is verified -- so a failed run still leaves Steam able to resume. The trees share inodes, so an in-place chunk patch corrects both. cli.py drops from 311 to 244 lines, back under the repo's 250-line cap, by moving the install flow to flow.py and the manifest finish to finalize.py. install.sh had a latent bug: `pip install -e .[dev]` only warns about a missing extra and exits 0, so the `|| fallback` that installed pytest and coverage never ran. A fresh venv had no test tools at all; the existing one only worked because they had been installed by hand earlier. Now named outright and asserted. 246 tests, 100% statement and branch coverage. Verified live: all four input forms resolve to 284160, an exact "Portal" resolves to 400 and not 620, an ambiguous name exits 2, ghost detection flags nothing on nine real installs, and a from-scratch venv bootstraps and runs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Sgkb3wH6MU9fYquX328ovT
103 lines
2.5 KiB
Bash
Executable File
103 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# ============================================================================
|
|
# Install a Steam game from whatever you happen to have: an AppID, a Steam URL,
|
|
# or the game's name.
|
|
#
|
|
# ./run.sh 284160
|
|
# ./run.sh https://steamcommunity.com/app/284160/guides/
|
|
# ./run.sh BeamNG.drive
|
|
# ./run.sh BeamNG
|
|
#
|
|
# Dependencies install themselves on first run. Every other argument is passed
|
|
# straight through to the CLI, so `./run.sh --help` lists the full set.
|
|
# ============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
readonly SCRIPT_DIR
|
|
readonly VENV_PY="${SCRIPT_DIR}/.venv/bin/python"
|
|
readonly STAMP="${SCRIPT_DIR}/.venv/.deps-ok"
|
|
readonly INSTALLER="${SCRIPT_DIR}/install.sh"
|
|
|
|
SKIP_DEPS="${SGI_SKIP_DEPS:-0}"
|
|
DEPS_ONLY=0
|
|
ARGS=()
|
|
|
|
usage() {
|
|
echo "Usage: run.sh [TARGET] [OPTIONS]"
|
|
echo
|
|
echo "TARGET is any of:"
|
|
echo " 284160 an AppID"
|
|
echo " https://steamcommunity.com/app/284160/... a Steam URL"
|
|
echo " BeamNG.drive the exact name"
|
|
echo " BeamNG part of the name"
|
|
echo
|
|
echo "run.sh options:"
|
|
echo " --no-deps Skip the dependency check (also: SGI_SKIP_DEPS=1)"
|
|
echo " --deps-only Install dependencies and exit"
|
|
echo " -h, --help Show this help, then the installer's own options"
|
|
echo
|
|
if [[ -x "$VENV_PY" ]]; then
|
|
"$VENV_PY" -m steam_installer.cli --help
|
|
fi
|
|
exit 0
|
|
}
|
|
|
|
# Dependencies are only re-checked when the stamp is missing or older than the
|
|
# files that decide what gets installed, so a normal run adds no startup cost.
|
|
deps_are_current() {
|
|
[[ -x "$VENV_PY" ]] || return 1
|
|
[[ -f "$STAMP" ]] || return 1
|
|
[[ "$STAMP" -nt "$INSTALLER" ]] || return 1
|
|
[[ "$STAMP" -nt "${SCRIPT_DIR}/pyproject.toml" ]] || return 1
|
|
"$VENV_PY" -c 'import steam_installer' >/dev/null 2>&1
|
|
}
|
|
|
|
main() {
|
|
if [[ "$SKIP_DEPS" != "1" ]] && ! deps_are_current; then
|
|
"$INSTALLER"
|
|
fi
|
|
|
|
if [[ "$DEPS_ONLY" -eq 1 ]]; then
|
|
exit 0
|
|
fi
|
|
|
|
[[ -x "$VENV_PY" ]] || {
|
|
echo "error: no virtualenv at ${VENV_PY}. Run ./install.sh" >&2
|
|
exit 1
|
|
}
|
|
|
|
# `-m` rather than the console script, so a stale .venv shim can never
|
|
# shadow the working tree.
|
|
exec "$VENV_PY" -m steam_installer.cli "${ARGS[@]}"
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
--no-deps)
|
|
SKIP_DEPS=1
|
|
shift
|
|
;;
|
|
--deps-only)
|
|
DEPS_ONLY=1
|
|
shift
|
|
;;
|
|
-h | --help)
|
|
usage
|
|
;;
|
|
--)
|
|
shift
|
|
ARGS+=("$@")
|
|
break
|
|
;;
|
|
*)
|
|
ARGS+=("$1")
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
main
|