testsAndMisc/linux_configuration/utils/lib/steam_api.sh
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.

Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.

The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:

  - 52 relative `source` lines for lib/common.sh and lib/android.sh. The
    correct prefix differs per file: 40 were ../../ and 12 were ../../../,
    so a blanket replace would have fixed one set and broken the other.
  - REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
    each walking up four levels from a directory now two levels shallower.
    This caused a real regression -- the fixes suite went red with
    "log_warn: command not found" -- caught by running it and comparing
    against the pre-move baseline worktree.
  - conftest.py's sys.path entries, which took the pytest gate down with
    14 collection errors, and the `# shellcheck source=` directives, which
    took shellcheck down with SC1091.

16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.

Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 18:53:30 +02:00

125 lines
4.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Steam library discovery, the Steam and ProtonDB API calls, and requirement
# extraction for steam_compatibility.sh.
find_steamapps_dirs() {
local dirs=()
for base in "${STEAM_DIRS[@]}"; do
[[ -d $base ]] || continue
if [[ -f "$base/steamapps/libraryfolders.vdf" ]]; then
# Newer format includes nested objects with paths
local paths
paths=$(grep -oE '"path"\s+"[^"]+"' "$base/steamapps/libraryfolders.vdf" | sed -E 's/.*"([^"]+)"/\1/' || true)
if [[ -n $paths ]]; then
while IFS= read -r p; do
[[ -d "$p/steamapps" ]] && dirs+=("$p/steamapps")
done <<< "$paths"
fi
fi
[[ -d "$base/steamapps" ]] && dirs+=("$base/steamapps")
done
# de-dupe
printf "%s\n" "${dirs[@]}" 2> /dev/null | awk '!seen[$0]++'
}
list_installed_games() {
local d appid name
while IFS= read -r d; do
[[ -d $d ]] || continue
for mf in "$d"/appmanifest_*.acf; do
[[ -f $mf ]] || continue
appid=$(grep -oE '"appid"\s+"[0-9]+"' "$mf" | sed -E 's/.*"([0-9]+)"/\1/' | head -n1)
name=$(grep -oE '"name"\s+"[^"]+"' "$mf" | sed -E 's/.*"([^"]+)"/\1/' | head -n1)
if [[ -n $appid ]]; then
printf "%s\t%s\n" "$appid" "${name:-Unknown}"
fi
done
done < <(find_steamapps_dirs)
}
list_owned_games_via_api() {
local key="${STEAM_API_KEY:-}" sid="${STEAM_ID64:-}"
if [[ -z $key || -z $sid ]]; then
return 1
fi
local url="https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=${key}&steamid=${sid}&include_appinfo=1&include_played_free_games=1&format=json"
http_get "$url" | jq -r '.response.games[]? | "\(.appid)\t\(.name)"' || return 1
}
fetch_appdetails_json() {
local appid="$1"
# Using store API (no key)
local url="https://store.steampowered.com/api/appdetails?appids=${appid}&l=en&cc=us"
http_get "$url" || true
}
extract_requirements_and_platforms() {
# Input: JSON from appdetails; Output: TSV of fields
# Fields: success, linux, windows, mac, min_text, rec_text, type
local appid="$1" json="$2"
# Some apps return {"APPID": {"success":true, "data":{...}}}
local out
out=$(jq -r --arg APP "$appid" '
.[$APP] as $root | if ($root.success==true and ($root.data|type)=="object") then
($root.data.platforms.linux // false) as $linux |
($root.data.platforms.windows // false) as $windows |
($root.data.platforms.mac // false) as $mac |
($root.data.type // "") as $type |
# Prefer Linux reqs when present
($root.data.linux_requirements.minimum // $root.data.pc_requirements.minimum // "") as $min |
($root.data.linux_requirements.recommended // $root.data.pc_requirements.recommended // "") as $rec |
["ok", ($linux|tostring), ($windows|tostring), ($mac|tostring), ($min|tostring), ($rec|tostring), ($type|tostring)] | @tsv
else
["fail", "false", "false", "false", "", "", ""] | @tsv
end' 2> /dev/null <<< "$json") || true
if [[ -z $out ]]; then
out=$'fail false false false '
fi
printf '%s\n' "$out"
}
# Read JSON from stdin (avoids storing large/binary data in variables)
extract_requirements_and_platforms_stdin() {
local appid="$1"
local out
out=$(jq -r --arg APP "$appid" '
.[$APP] as $root | if ($root.success==true and ($root.data|type)=="object") then
($root.data.platforms.linux // false) as $linux |
($root.data.platforms.windows // false) as $windows |
($root.data.platforms.mac // false) as $mac |
($root.data.type // "") as $type |
($root.data.linux_requirements.minimum // $root.data.pc_requirements.minimum // "") as $min |
($root.data.linux_requirements.recommended // $root.data.pc_requirements.recommended // "") as $rec |
["ok", ($linux|tostring), ($windows|tostring), ($mac|tostring), ($min|tostring), ($rec|tostring), ($type|tostring)] | @tsv
else
["fail", "false", "false", "false", "", "", ""] | @tsv
end' 2> /dev/null) || true
if [[ -z $out ]]; then
out=$'fail\tfalse\tfalse\tfalse\t\t\t'
fi
printf '%s\n' "$out"
}
fetch_protondb_tier() {
local appid="$1"
local url="https://www.protondb.com/api/v1/reports/summaries/${appid}.json"
# Returns minimal JSON including .tier, .confidence; we only need .tier
local tier
tier=$(http_get "$url" | jq -r 'try .tier // "unknown"' 2> /dev/null || true)
if [[ -z $tier || $tier == "null" ]]; then
echo "unknown"
else
tr '[:upper:]' '[:lower:]' <<< "$tier" | tr -d '\r\n'
fi
}
protondb_allowed() {
local tier
tier=$(tr '[:upper:]' '[:lower:]' <<< "${1:-}")
case "$tier" in
platinum | native | gold | silver | unknown | "") return 0 ;;
bronze | pending | borked | unsupported | broken) return 1 ;;
*) return 0 ;;
esac
}