Add container test harness and Portal 2 sound theme builder
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013UzjWUxheYfqqjWGH7Ktmc
This commit is contained in:
1 parent
3d08572911
commit
c76e87e0c7
4 files changed
+170
-1
No files matched your search
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"_comment": "freedesktop event -> VPK glob patterns, first match wins. Explore with: build-sound-theme --list 'sound/*turret*'",
|
||||
"events": {
|
||||
"desktop-login": ["sound/weapons/portalgun/portal_open*1.wav", "sound/*portal_open*"],
|
||||
"desktop-logout": ["sound/weapons/portalgun/portal_close*1.wav", "sound/*portal_close*", "sound/*fizzle*"],
|
||||
"device-added": ["sound/weapons/portalgun/*shoot*blue*1.wav", "sound/*portalgun*shoot*blue*"],
|
||||
"device-removed": ["sound/weapons/portalgun/*shoot*red*1.wav", "sound/*portalgun*shoot*orange*", "sound/*portalgun*shoot*red*"],
|
||||
"dialog-error": ["sound/*button*deny*", "sound/*denied*", "sound/*buzz*"],
|
||||
"outcome-failure": ["sound/*button*deny*", "sound/*denied*", "sound/*buzz*"],
|
||||
"dialog-warning": ["sound/*turret*active*", "sound/*turret*alert*", "sound/*turret*deploy*"],
|
||||
"dialog-information": ["sound/*elevator*ding*", "sound/*ding*", "sound/*bell*"],
|
||||
"message-new-instant": ["sound/*elevator*ding*", "sound/*ding*", "sound/*chime*"],
|
||||
"message-new-email": ["sound/*chime*", "sound/*ding*"],
|
||||
"complete": ["sound/*button*positive*", "sound/*button*press*", "sound/*success*"],
|
||||
"outcome-success": ["sound/*button*positive*", "sound/*success*"],
|
||||
"bell": ["sound/ui/*click*", "sound/*buttonclick*"],
|
||||
"audio-volume-change": ["sound/ui/*rollover*", "sound/ui/*click*"],
|
||||
"trash-empty": ["sound/*incinerat*", "sound/*disintegrat*"],
|
||||
"power-plug": ["sound/*power*up*", "sound/*powerup*"],
|
||||
"power-unplug": ["sound/*power*down*", "sound/*powerdown*"],
|
||||
"battery-low": ["sound/*alarm*", "sound/*klaxon*"]
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,10 @@ let
|
||||
exec ${py}/bin/python ${../../scripts/wallpaper-sort.py} "$@"
|
||||
'';
|
||||
|
||||
build-sound-theme = pkgs.writeShellScriptBin "build-sound-theme" ''
|
||||
exec ${pkgs.python3.withPackages (ps: [ ps.vpk ])}/bin/python ${../../scripts/build-sound-theme.py} "$@"
|
||||
'';
|
||||
|
||||
wallpapers = "${config.home.homeDirectory}/Pictures/Wallpapers";
|
||||
|
||||
userService = description: exec: {
|
||||
@@ -39,7 +43,7 @@ let
|
||||
};
|
||||
in
|
||||
lib.mkIf config.dotfiles.gui {
|
||||
home.packages = [ konsole-daynight daynight-hooks wallpaper-sort ];
|
||||
home.packages = [ konsole-daynight daynight-hooks wallpaper-sort build-sound-theme ];
|
||||
|
||||
xdg.configFile."dotfiles/activities.json".text = builtins.toJSON {
|
||||
# First entry takes over the stock "Default" activity.
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
"""Build a freedesktop sound theme from Portal 2's own sound files.
|
||||
|
||||
build-sound-theme # build + activate ~/.local/share/sounds/portal2
|
||||
build-sound-theme --list PATTERN # explore the VPK, e.g. --list '*turret*'
|
||||
|
||||
Game assets can't live in git, so this extracts them from your local Steam
|
||||
install. Each freedesktop event takes the first VPK path matching one of its
|
||||
glob patterns; edit config/sounds/portal2.json to retune.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import fnmatch
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
import vpk
|
||||
|
||||
HOME = Path.home()
|
||||
MAPPING = Path(__file__).resolve().parent.parent / "config/sounds/portal2.json"
|
||||
THEME = "portal2"
|
||||
|
||||
|
||||
def steam_libraries() -> list[Path]:
|
||||
roots = [HOME / ".local/share/Steam", HOME / ".steam/steam", HOME / ".var/app/com.valvesoftware.Steam/.local/share/Steam"]
|
||||
libs = []
|
||||
for root in roots:
|
||||
vdf = root / "steamapps/libraryfolders.vdf"
|
||||
if vdf.is_file():
|
||||
libs += [Path(p) for p in re.findall(r'"path"\s+"([^"]+)"', vdf.read_text())]
|
||||
libs.append(root)
|
||||
return list(dict.fromkeys(libs))
|
||||
|
||||
|
||||
def find_vpks() -> list[Path]:
|
||||
found = []
|
||||
for lib in steam_libraries():
|
||||
game = lib / "steamapps/common/Portal 2"
|
||||
for sub in ("portal2", "portal2_dlc1", "portal2_dlc2"):
|
||||
p = game / sub / "pak01_dir.vpk"
|
||||
if p.is_file():
|
||||
found.append(p)
|
||||
return found
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--list", metavar="PATTERN")
|
||||
ap.add_argument("--no-activate", action="store_true")
|
||||
args = ap.parse_args()
|
||||
|
||||
paks = [vpk.open(str(p)) for p in find_vpks()]
|
||||
if not paks:
|
||||
raise SystemExit("Portal 2 not found in any Steam library; install it and re-run")
|
||||
index = {}
|
||||
for pak in paks:
|
||||
for path in pak:
|
||||
if path.startswith("sound/") and path.endswith((".wav", ".mp3")):
|
||||
index.setdefault(path, pak)
|
||||
|
||||
if args.list:
|
||||
for path in sorted(index):
|
||||
if fnmatch.fnmatch(path, args.list):
|
||||
print(path)
|
||||
return
|
||||
|
||||
mapping = json.loads(MAPPING.read_text())
|
||||
out = HOME / ".local/share/sounds" / THEME / "stereo"
|
||||
out.mkdir(parents=True, exist_ok=True)
|
||||
for event, patterns in mapping["events"].items():
|
||||
match = next((p for pat in patterns for p in sorted(index) if fnmatch.fnmatch(p, pat)), None)
|
||||
if not match:
|
||||
print(f"-- {event}: no match for {patterns}")
|
||||
continue
|
||||
ext = Path(match).suffix
|
||||
for old in out.glob(f"{event}.*"):
|
||||
old.unlink()
|
||||
(out / f"{event}{ext}").write_bytes(index[match].get_file(match).read())
|
||||
print(f"ok {event:24} <- {match}")
|
||||
|
||||
(out.parent / "index.theme").write_text(
|
||||
f"[Sound Theme]\nName=Portal 2\nComment=Aperture Science approved notifications\nInherits=ocean,freedesktop\nDirectories=stereo\n\n[stereo]\nOutputProfile=stereo\n"
|
||||
)
|
||||
if not args.no_activate:
|
||||
subprocess.run(["kwriteconfig6", "--file", "kdeglobals", "--group", "Sounds", "--key", "Theme", THEME], check=False)
|
||||
print(f"activated sound theme '{THEME}'")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
# From-scratch install test in a throwaway container (run on any Podman host).
|
||||
#
|
||||
# tests/container-test.sh IMAGE PROFILE [name]
|
||||
# tests/container-test.sh docker.io/archlinux:latest headless
|
||||
# tests/container-test.sh docker.io/cachyos/cachyos:latest headless
|
||||
# tests/container-test.sh lscr.io/linuxserver/webtop:fedora-kde full webtop # see README
|
||||
#
|
||||
# The repo is copied in from the current checkout (no Gitea access needed), a
|
||||
# sudo-capable user is created if the image has none, and bootstrap.sh runs as
|
||||
# that user. The container is left running for inspection; `podman rm -f NAME`.
|
||||
set -euo pipefail
|
||||
|
||||
IMAGE="$1"; PROFILE="$2"; NAME="${3:-dotfiles-test-$(basename "${IMAGE%%:*}")}"
|
||||
HERE="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
TEST_USER="${TEST_USER:-tester}"
|
||||
|
||||
podman rm -f "$NAME" >/dev/null 2>&1 || true
|
||||
if [ "${WEBTOP:-0}" = 1 ]; then
|
||||
# Selkies webtop: s6 init, user abc (uid 1000) with passwordless sudo.
|
||||
podman run -d --name "$NAME" --shm-size=1g -e PUID=1000 -e PGID=1000 -e TZ=America/Denver \
|
||||
-p "${WEBTOP_PORT:-3901}:3001" "$IMAGE" >/dev/null
|
||||
TEST_USER=abc
|
||||
for _ in $(seq 60); do podman exec "$NAME" id abc >/dev/null 2>&1 && break; sleep 2; done
|
||||
else
|
||||
podman run -d --name "$NAME" "$IMAGE" sleep infinity >/dev/null
|
||||
podman exec "$NAME" sh -c '
|
||||
set -e
|
||||
. /etc/os-release
|
||||
case "$ID" in
|
||||
arch|cachyos) pacman -Sy --noconfirm --needed sudo >/dev/null ;;
|
||||
fedora|almalinux) dnf install -y sudo shadow-utils >/dev/null ;;
|
||||
debian|ubuntu) apt-get update >/dev/null && apt-get install -y sudo >/dev/null ;;
|
||||
esac
|
||||
id '"$TEST_USER"' >/dev/null 2>&1 || useradd -m -s /bin/bash '"$TEST_USER"'
|
||||
echo "'"$TEST_USER"' ALL=(ALL) NOPASSWD: ALL" >/etc/sudoers.d/'"$TEST_USER"'
|
||||
'
|
||||
fi
|
||||
|
||||
HOME_DIR="$(podman exec "$NAME" sh -c "getent passwd $TEST_USER | cut -d: -f6")"
|
||||
tar -C "$HERE" -cf - . | podman exec -i "$NAME" sh -c "mkdir -p $HOME_DIR/.dotfiles && tar -C $HOME_DIR/.dotfiles -xf - && chown -R $TEST_USER: $HOME_DIR/.dotfiles"
|
||||
|
||||
echo "==> bootstrap in $NAME ($IMAGE, $PROFILE)"
|
||||
start=$(date +%s)
|
||||
podman exec -u "$TEST_USER" -e HOME="$HOME_DIR" -e USER="$TEST_USER" -e DOTFILES_PROFILE="$PROFILE" \
|
||||
-w "$HOME_DIR" "$NAME" bash "$HOME_DIR/.dotfiles/bootstrap.sh"
|
||||
echo "==> bootstrap took $(( $(date +%s) - start ))s"
|
||||
|
||||
echo "==> doctor"
|
||||
podman exec -u "$TEST_USER" -e HOME="$HOME_DIR" -e USER="$TEST_USER" -w "$HOME_DIR" "$NAME" \
|
||||
zsh -lic 'dot doctor; echo; pokefetch | tail -5' || true
|
||||
Reference in new issue
Block a user