mirror of
https://github.com/kuhyx/steam-backlog-enforcer.git
synced 2026-11-10 19:07:05 +01:00
The systemd service runs as root with no User=, so _run_as_user() had no SUDO_USER/USER to drop privileges to and launched Steam as bare root with no DISPLAY/XAUTHORITY/DBUS session - its CDP port never opened. Add an explicit STEAM_ENFORCER_DESKTOP_USER env var (set in the unit, substituted by install.sh) so the enforcer always knows which desktop user owns the Steam session, regardless of how it was launched. Also fix a hardcoded _CDP_PORT=8080 colliding with an already-running local service bound to 0.0.0.0:8080: requests to 127.0.0.1:8080 always hit that service instead of steamwebhelper (which only bound [::1]:8080), so CDP detection could never succeed even with the user fix. Move to 9222, the conventional Chrome DevTools port. Verified live: journalctl shows CDP ready and games hidden within ~7s of a service restart, Steam running as the desktop user (not root).
67 lines
2.6 KiB
Bash
Executable File
67 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Install script for Steam Backlog Enforcer.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
echo "=== Steam Backlog Enforcer Installer ==="
|
|
echo
|
|
|
|
# Install Python deps.
|
|
echo "Installing Python dependencies..."
|
|
pip3 install --break-system-packages requests howlongtobeatpy 2>/dev/null \
|
|
|| pip3 install requests howlongtobeatpy
|
|
|
|
# 'block-gaming' depends on guard-lib (guardctl) for tamper-resistant
|
|
# locking. Not fatal if missing - the rest of this tool works without it.
|
|
echo
|
|
echo "Checking for guard-lib (required by 'block-gaming')..."
|
|
if command -v guardctl >/dev/null 2>&1; then
|
|
echo "guardctl found on PATH."
|
|
elif [[ -x "$HOME/utils/guard-lib/install.sh" ]]; then
|
|
echo "guardctl not found - installing guard-lib from $HOME/utils/guard-lib..."
|
|
if [[ $EUID -eq 0 ]]; then
|
|
bash "$HOME/utils/guard-lib/install.sh"
|
|
else
|
|
echo "guard-lib install needs root: sudo bash \"$HOME/utils/guard-lib/install.sh\""
|
|
echo "('block-gaming' will not work until that is done; the rest of this tool is unaffected.)"
|
|
fi
|
|
else
|
|
echo "Warning: guardctl not found and ~/utils/guard-lib is not present."
|
|
echo "'block-gaming' requires guard-lib - set up ~/utils/guard-lib and run its install.sh, then re-run this installer."
|
|
echo "(The rest of this tool is unaffected.)"
|
|
fi
|
|
|
|
# Install systemd service (system-level, runs as root).
|
|
read -rp "Install systemd enforce service? [y/N] " ans
|
|
if [[ "${ans,,}" == "y" ]]; then
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "Error: systemd service install needs root. Re-run with sudo."
|
|
exit 1
|
|
fi
|
|
|
|
SERVICE_SRC="$SCRIPT_DIR/steam-backlog-enforcer.service"
|
|
SERVICE_DST="/etc/systemd/system/steam-backlog-enforcer.service"
|
|
|
|
# Set the correct working directory, PYTHONPATH, and desktop user (the
|
|
# user whose Steam/X11 session the service should drive) in the service
|
|
# file. install.sh requires root, so it's invoked via `sudo` and
|
|
# SUDO_USER holds the real desktop user.
|
|
DESKTOP_USER="${SUDO_USER:-$USER}"
|
|
sed "s|WorkingDirectory=.*|WorkingDirectory=$SCRIPT_DIR|; \
|
|
s|PYTHONPATH=.*|PYTHONPATH=$SCRIPT_DIR|; \
|
|
s|__DESKTOP_USER__|$DESKTOP_USER|" \
|
|
"$SERVICE_SRC" > "$SERVICE_DST"
|
|
|
|
systemctl daemon-reload
|
|
systemctl enable steam-backlog-enforcer
|
|
echo "Service installed and enabled."
|
|
echo " Start now: sudo systemctl start steam-backlog-enforcer"
|
|
echo " Check: sudo systemctl status steam-backlog-enforcer"
|
|
echo " Logs: sudo journalctl -u steam-backlog-enforcer -f"
|
|
fi
|
|
|
|
echo
|
|
echo "Done! Run manually with:"
|
|
echo " python3 -m steam_backlog_enforcer.main enforce"
|