fix: initial
This commit is contained in:
commit
fff6f91b06
5 files changed
+640
No files matched your search
Executable
+595
@@ -0,0 +1,595 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# setup-gamescope-boot-gnome.sh
|
||||
#
|
||||
# GNOME/GDM equivalent of theupriser/cachyos-gamescope-boot, scoped to boot
|
||||
# mechanics only (no Vapor theme / wallpaper / icon work).
|
||||
#
|
||||
# CONFIRMED (by reading CachyOS/gamescope-session source directly) that
|
||||
# gamescope-session-cachyos's own session-switching tooling is KDE-only:
|
||||
#
|
||||
# 1. /usr/lib/steamos/steam-set-session hardcodes a case statement over
|
||||
# plasmalogin/sddm and silently `exit 0`s (no error!) for any other
|
||||
# display manager, including GDM. This is called both by
|
||||
# steamos-session-select AND by the packaged system service
|
||||
# cachyos-gamescope-autologin.service - so under GDM, both are
|
||||
# currently silent no-ops.
|
||||
# 2. /usr/bin/steamos-session-select additionally shells out to
|
||||
# `qdbus6 org.kde.Shutdown /Shutdown org.kde.Shutdown.logout`, a
|
||||
# KDE-Plasma-specific D-Bus call with no GNOME/Mutter equivalent.
|
||||
#
|
||||
# FIX APPROACH: this script replaces those two files directly at their real
|
||||
# paths (/usr/lib/steamos/steam-set-session, /usr/bin/steamos-session-select)
|
||||
# with GDM-aware versions, so Steam's own "Switch to Desktop" button (which
|
||||
# calls these by path) works unmodified - no separate parallel tool needed.
|
||||
# No upstream PR is filed and nothing is submitted to any other repo; this is
|
||||
# a purely local override.
|
||||
#
|
||||
# SURVIVING PACKAGE UPDATES: a `pacman -Syu` of gamescope-session-cachyos
|
||||
# would normally overwrite these back to the broken originals. To make the
|
||||
# fix self-healing at the system level without manual reapplication, a
|
||||
# persistent source-of-truth copy is kept under /usr/local/share/gamescope-gdm-fix
|
||||
# (a path pacman never touches), and a pacman hook
|
||||
# (/etc/pacman.d/hooks/95-gamescope-gdm-fix.hook) automatically re-applies it
|
||||
# via PostTransaction every time that package is installed or upgraded.
|
||||
#
|
||||
# Also configures:
|
||||
# - GDM autologin as the target user (AutomaticLoginEnable/AutomaticLogin)
|
||||
# for the initial boot.
|
||||
# - Deck-style "reset to gamescope after any desktop logout", i.e. the
|
||||
# actual GDM analog of plasmalogin's Relogin=true. VERIFIED (via GDM bug
|
||||
# reports, not guessed) that GDM's own AutomaticLoginEnable/TimedLogin
|
||||
# ONLY apply once at daemon startup and do NOT reliably re-arm after a
|
||||
# logout - see e.g. https://bugs.launchpad.net/ubuntu/+source/gdm/+bug/499337
|
||||
# and https://discussion.fedoraproject.org/t/gnome-wayland-automatic-login-for-single-application-mode-kiosk-mode-is-not-working-after-log-out/109453 .
|
||||
# The workaround that's actually used is restarting gdm.service itself,
|
||||
# which forces it to re-evaluate AutomaticLoginEnable from scratch - the
|
||||
# same trick the KDE original performs explicitly via
|
||||
# `systemctl restart plasmalogin` in its own desktop shortcut. Here it's
|
||||
# wired to fire automatically on every logout via a user-level systemd
|
||||
# unit bound to that user's own shutdown.target.
|
||||
# - The user's default session via AccountsService
|
||||
# (/var/lib/AccountsService/users/<user>), which is what GDM actually
|
||||
# reads - written by the fixed steam-set-session.
|
||||
# - Steam's background-autostart systemd user unit (DE-agnostic fix,
|
||||
# ported unchanged from the KDE original's step 8b, minus the KWin-only
|
||||
# env var) so the Steam Controller virtual keyboard (Steam+X) keeps
|
||||
# working in desktop mode.
|
||||
# - A plain "Return to Gaming Mode" desktop launcher (no custom icon/theme)
|
||||
# that calls the now-working `steamos-session-select gamescope`.
|
||||
#
|
||||
# Explicitly NOT done here: Vapor theme, wallpaper, icon cache, launcher
|
||||
# icon theming - out of scope per request.
|
||||
#
|
||||
# Safe to re-run: idempotent, backs up files before editing.
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
# ---------- helpers ----------
|
||||
|
||||
c_reset="\033[0m"; c_bold="\033[1m"; c_green="\033[32m"; c_yellow="\033[33m"; c_red="\033[31m"; c_cyan="\033[36m"
|
||||
|
||||
info() { echo -e "${c_cyan}[INFO]${c_reset} $*"; }
|
||||
ok() { echo -e "${c_green}[OK]${c_reset} $*"; }
|
||||
warn() { echo -e "${c_yellow}[WARN]${c_reset} $*"; }
|
||||
err() { echo -e "${c_red}[ERROR] $*${c_reset}" >&2; }
|
||||
ask_yn() {
|
||||
local prompt="$1" default="${2:-y}" reply
|
||||
local hint="[Y/n]"; [[ "$default" == "n" ]] && hint="[y/N]"
|
||||
read -rp "$(echo -e "${c_bold}${prompt}${c_reset} ${hint} ")" reply
|
||||
reply="${reply:-$default}"
|
||||
[[ "$reply" =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
require_root_helper() {
|
||||
if [[ $EUID -eq 0 && -z "${SUDO_USER:-}" ]]; then
|
||||
err "Please run this script as your normal user (it will call sudo itself), not directly as root."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
backup_file() {
|
||||
local f="$1"
|
||||
if [[ -f "$f" && ! -f "${f}.bak-gamescope-wizard-gnome" ]]; then
|
||||
sudo cp -a "$f" "${f}.bak-gamescope-wizard-gnome"
|
||||
info "Backed up $f -> ${f}.bak-gamescope-wizard-gnome"
|
||||
fi
|
||||
}
|
||||
|
||||
# Find the wayland-sessions/xsessions desktop entry gamescope-session-cachyos
|
||||
# ships, and print its session ID (filename minus .desktop) via stdout.
|
||||
find_gamescope_session_id() {
|
||||
local f
|
||||
for f in /usr/share/wayland-sessions/*gamescope*.desktop /usr/share/xsessions/*gamescope*.desktop; do
|
||||
[[ -f "$f" ]] || continue
|
||||
basename "$f" .desktop
|
||||
return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Find the GNOME desktop-mode session entry (name varies: gnome.desktop,
|
||||
# gnome-xorg.desktop, etc). Falls back to "gnome" if nothing is found.
|
||||
find_gnome_session_id() {
|
||||
local f
|
||||
for f in /usr/share/wayland-sessions/gnome*.desktop /usr/share/xsessions/gnome*.desktop; do
|
||||
[[ -f "$f" ]] || continue
|
||||
basename "$f" .desktop
|
||||
return 0
|
||||
done
|
||||
echo "gnome"
|
||||
}
|
||||
|
||||
# ---------- start ----------
|
||||
|
||||
require_root_helper
|
||||
|
||||
echo -e "${c_bold}CachyOS Steam Deck-style Gamescope Boot Wizard (GNOME/GDM)${c_reset}"
|
||||
echo "Boot mechanics only, self-healing via a pacman hook. No theming, no upstream PR."
|
||||
echo
|
||||
|
||||
if ! command -v pacman >/dev/null 2>&1; then
|
||||
err "This doesn't look like an Arch/CachyOS system (no pacman found). Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
TARGET_USER="${SUDO_USER:-$USER}"
|
||||
read -rp "$(echo -e "${c_bold}Which user should autologin into gamescope?${c_reset} [${TARGET_USER}] ")" input_user
|
||||
TARGET_USER="${input_user:-$TARGET_USER}"
|
||||
|
||||
if ! id "$TARGET_USER" >/dev/null 2>&1; then
|
||||
err "User '$TARGET_USER' does not exist on this system."
|
||||
exit 1
|
||||
fi
|
||||
user_home="$(eval echo "~$TARGET_USER")"
|
||||
ok "Using user: $TARGET_USER"
|
||||
echo
|
||||
|
||||
# ---------- 1. Login manager check ----------
|
||||
|
||||
DM="$(systemctl show -p Id --value display-manager 2>/dev/null | sed 's/\.service$//')"
|
||||
info "Detected display manager: ${DM:-none}"
|
||||
|
||||
if [[ "$DM" != "gdm" ]]; then
|
||||
warn "This wizard targets GDM. Detected display manager is '${DM:-unknown}'."
|
||||
warn "If you're on plasma-login-manager/SDDM + KDE, use the original KDE wizard instead."
|
||||
ask_yn "Continue anyway?" n || exit 0
|
||||
fi
|
||||
echo
|
||||
|
||||
# ---------- 2. Install packages ----------
|
||||
|
||||
info "Checking required packages: gamescope-session-cachyos, steam, mangohud, accountsservice"
|
||||
MISSING=()
|
||||
for pkg in gamescope-session-cachyos steam mangohud accountsservice; do
|
||||
pacman -Qi "$pkg" >/dev/null 2>&1 || MISSING+=("$pkg")
|
||||
done
|
||||
|
||||
if [[ ${#MISSING[@]} -gt 0 ]]; then
|
||||
info "Missing packages: ${MISSING[*]}"
|
||||
if ask_yn "Install them now?"; then
|
||||
sudo pacman -S --needed "${MISSING[@]}"
|
||||
else
|
||||
err "Cannot continue without these packages."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
ok "All required packages already installed."
|
||||
fi
|
||||
echo
|
||||
|
||||
# ---------- 3. Verify gamescope has a GDM-visible session entry ----------
|
||||
|
||||
info "Looking for a gamescope session entry under /usr/share/wayland-sessions or /usr/share/xsessions"
|
||||
GAMESCOPE_SESSION_ID=""
|
||||
if GAMESCOPE_SESSION_ID="$(find_gamescope_session_id)"; then
|
||||
ok "Found session: $GAMESCOPE_SESSION_ID"
|
||||
else
|
||||
err "No gamescope *.desktop entry found under /usr/share/wayland-sessions or /usr/share/xsessions."
|
||||
err "gamescope-session-cachyos isn't exposing a session for GDM to list. Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GNOME_SESSION_ID="$(find_gnome_session_id)"
|
||||
info "Desktop-mode session detected as: $GNOME_SESSION_ID"
|
||||
echo
|
||||
|
||||
# ---------- 4. Configure GDM autologin ----------
|
||||
|
||||
CUSTOM_CONF="/etc/gdm/custom.conf"
|
||||
info "Configuring $CUSTOM_CONF for autologin as $TARGET_USER"
|
||||
backup_file "$CUSTOM_CONF"
|
||||
sudo touch "$CUSTOM_CONF"
|
||||
|
||||
if ! grep -q '^\[daemon\]' "$CUSTOM_CONF"; then
|
||||
sudo tee -a "$CUSTOM_CONF" > /dev/null <<< "[daemon]"
|
||||
fi
|
||||
|
||||
set_daemon_key() {
|
||||
local key="$1" value="$2"
|
||||
if sudo grep -q "^${key}=" "$CUSTOM_CONF"; then
|
||||
sudo sed -i "s|^${key}=.*|${key}=${value}|" "$CUSTOM_CONF"
|
||||
else
|
||||
sudo awk -v k="$key" -v v="$value" '
|
||||
/^\[daemon\]/ && !done { print; print k"="v; done=1; next }
|
||||
{ print }
|
||||
' "$CUSTOM_CONF" | sudo tee "${CUSTOM_CONF}.tmp" > /dev/null
|
||||
sudo mv "${CUSTOM_CONF}.tmp" "$CUSTOM_CONF"
|
||||
fi
|
||||
}
|
||||
|
||||
set_daemon_key "AutomaticLoginEnable" "True"
|
||||
set_daemon_key "AutomaticLogin" "$TARGET_USER"
|
||||
# NOT using TimedLoginEnable as a Relogin=true stand-in: confirmed via GDM
|
||||
# bug reports (see header) that it does not reliably re-arm after a logout.
|
||||
# The actual re-login-after-logout mechanism is step 5 below.
|
||||
|
||||
ok "GDM autologin config written:"
|
||||
sudo sed -n '/\[daemon\]/,/^\[/p' "$CUSTOM_CONF" | head -n -1 2>/dev/null || sudo cat "$CUSTOM_CONF"
|
||||
echo
|
||||
|
||||
# ---------- 5. Re-login after logout (real Relogin=true equivalent) ----------
|
||||
#
|
||||
# GDM only evaluates AutomaticLoginEnable when gdm.service itself starts, not
|
||||
# on every logout (confirmed - see header links). Restarting gdm.service
|
||||
# forces that re-evaluation, so it will log the autologin user straight back
|
||||
# in. Fires automatically on every logout via a user-level systemd unit bound
|
||||
# to that user's own shutdown.target, so it covers both this script's own
|
||||
# toggle tool and an ordinary desktop logout uniformly.
|
||||
|
||||
SUDOERS_FILE="/etc/sudoers.d/99-gamescope-gdm-relogin"
|
||||
info "Installing a narrow sudoers rule so $TARGET_USER can restart gdm.service without a password"
|
||||
sudo tee "$SUDOERS_FILE" > /dev/null << EOF
|
||||
$TARGET_USER ALL=(root) NOPASSWD: /usr/bin/systemctl restart gdm.service
|
||||
EOF
|
||||
sudo chmod 440 "$SUDOERS_FILE"
|
||||
if ! sudo visudo -c -f "$SUDOERS_FILE" >/dev/null 2>&1; then
|
||||
err "Generated sudoers file failed validation - removing it."
|
||||
sudo rm -f "$SUDOERS_FILE"
|
||||
exit 1
|
||||
fi
|
||||
ok "Sudoers rule installed and validated."
|
||||
|
||||
RELOGIN_UNIT_DIR="$user_home/.config/systemd/user"
|
||||
sudo -u "$TARGET_USER" mkdir -p "$RELOGIN_UNIT_DIR"
|
||||
sudo -u "$TARGET_USER" tee "$RELOGIN_UNIT_DIR/gamescope-gdm-relogin.service" > /dev/null << 'EOF'
|
||||
[Unit]
|
||||
Description=Restart GDM on logout so it re-triggers autologin (Deck-style relogin)
|
||||
DefaultDependencies=no
|
||||
Before=shutdown.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/sudo /usr/bin/systemctl restart gdm.service
|
||||
|
||||
[Install]
|
||||
WantedBy=shutdown.target
|
||||
EOF
|
||||
sudo -u "$TARGET_USER" XDG_RUNTIME_DIR="/run/user/$(id -u "$TARGET_USER")" systemctl --user daemon-reload
|
||||
sudo -u "$TARGET_USER" XDG_RUNTIME_DIR="/run/user/$(id -u "$TARGET_USER")" systemctl --user enable gamescope-gdm-relogin.service
|
||||
ok "Relogin-on-logout unit installed and enabled."
|
||||
echo
|
||||
|
||||
# ---------- 6. GDM-aware steam-set-session / steamos-session-select, self-healing ----------
|
||||
#
|
||||
# Rather than filing anything upstream, this replaces the two KDE-only files
|
||||
# with our own GDM-aware versions directly at their real paths, so Steam's
|
||||
# own "Switch to Desktop" button (which calls these by path) works
|
||||
# unmodified. To survive a `pacman -Syu` of gamescope-session-cachyos
|
||||
# overwriting them back to the broken originals, a persistent source-of-truth
|
||||
# copy is kept under /usr/local/share (never touched by pacman) and a pacman
|
||||
# hook re-applies it automatically after every install/upgrade of that
|
||||
# package - fully self-healing, no manual reapplication, no upstream PR.
|
||||
|
||||
FIX_SHARE_DIR="/usr/local/share/gamescope-gdm-fix"
|
||||
STEAM_SET_SESSION="/usr/lib/steamos/steam-set-session"
|
||||
SESSION_SELECT="/usr/bin/steamos-session-select"
|
||||
|
||||
info "Installing GDM-aware steam-set-session / steamos-session-select as persistent source of truth"
|
||||
sudo mkdir -p "$FIX_SHARE_DIR"
|
||||
|
||||
sudo tee "$FIX_SHARE_DIR/steam-set-session" > /dev/null << 'STEAM_SET_SESSION_EOF'
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DISPLAY_MANAGER="$(systemctl show -p Id --value display-manager)"
|
||||
DM_ID="${DISPLAY_MANAGER%.service}"
|
||||
|
||||
# Session, gamescope or plasma
|
||||
SESSION="${1:-gamescope-session.desktop}"
|
||||
|
||||
case "$DM_ID" in
|
||||
plasmalogin) CONF_FILE="/etc/plasmalogin.conf.d/zz-steamos-autologin.conf";;
|
||||
sddm) CONF_FILE="/etc/sddm.conf.d/zz-steamos-autologin.conf";;
|
||||
gdm)
|
||||
# GDM has no conf.d-style autologin fragment to write - it reads a
|
||||
# per-user default session straight out of AccountsService. Write it
|
||||
# there instead, stripping the .desktop suffix that plasmalogin/sddm
|
||||
# keep (AccountsService's Session= key is the session ID, not a
|
||||
# filename).
|
||||
if [[ -n "${PKEXEC_UID:-}" ]]; then
|
||||
TARGET_USER="$(id -un "$PKEXEC_UID")"
|
||||
else
|
||||
TARGET_USER="$(logname 2>/dev/null || echo "${SUDO_USER:-}")"
|
||||
fi
|
||||
[[ -z "$TARGET_USER" ]] && exit 0
|
||||
|
||||
ACCOUNTS_FILE="/var/lib/AccountsService/users/$TARGET_USER"
|
||||
SESSION_ID="${SESSION%.desktop}"
|
||||
|
||||
mkdir -p /var/lib/AccountsService/users
|
||||
touch "$ACCOUNTS_FILE"
|
||||
grep -q '^\[User\]' "$ACCOUNTS_FILE" || echo "[User]" >> "$ACCOUNTS_FILE"
|
||||
|
||||
if grep -q '^Session=' "$ACCOUNTS_FILE"; then
|
||||
sed -i "s|^Session=.*|Session=$SESSION_ID|" "$ACCOUNTS_FILE"
|
||||
else
|
||||
sed -i "/^\[User\]/a Session=$SESSION_ID" "$ACCOUNTS_FILE"
|
||||
fi
|
||||
systemctl restart accounts-daemon 2>/dev/null || true
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
|
||||
# Don't do anything if system is using unsupported display manager
|
||||
[[ -z "$CONF_FILE" ]] && exit 0
|
||||
|
||||
if [[ ! -d "$(dirname "$CONF_FILE")" ]]; then
|
||||
mkdir -p "$(dirname "$CONF_FILE")"
|
||||
fi
|
||||
|
||||
cat <<INNEREOF > "$CONF_FILE"
|
||||
[Autologin]
|
||||
Session=$SESSION
|
||||
INNEREOF
|
||||
STEAM_SET_SESSION_EOF
|
||||
|
||||
sudo tee "$FIX_SHARE_DIR/steamos-session-select" > /dev/null << 'SESSION_SELECT_EOF'
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
DISPLAY_MANAGER="$(systemctl show -p Id --value display-manager)"
|
||||
DM_ID="${DISPLAY_MANAGER%.service}"
|
||||
|
||||
# Desktop-mode session filename varies by DM: plasmalogin/sddm boot KDE
|
||||
# Plasma (plasma.desktop, a fixed name). GDM boots whatever GNOME session
|
||||
# happens to be installed, which may be named gnome.desktop or
|
||||
# gnome-xorg.desktop depending on the system - detect it instead of
|
||||
# hardcoding, falling back to "gnome.desktop" if detection fails.
|
||||
find_desktop_session_file() {
|
||||
local f
|
||||
for f in /usr/share/wayland-sessions/gnome*.desktop /usr/share/xsessions/gnome*.desktop; do
|
||||
[[ -f "$f" ]] || continue
|
||||
basename "$f"
|
||||
return 0
|
||||
done
|
||||
echo "gnome.desktop"
|
||||
}
|
||||
|
||||
case "$DM_ID" in
|
||||
gdm) DESKTOP_SESSION="$(find_desktop_session_file)";;
|
||||
*) DESKTOP_SESSION="plasma.desktop";;
|
||||
esac
|
||||
|
||||
logout_current_session() {
|
||||
# Under GDM, ending the session is all this needs to do - re-arming
|
||||
# autologin back into whatever session was just set (gamescope or
|
||||
# desktop) is handled separately by a per-user systemd unit bound to
|
||||
# shutdown.target (installed by setup-gamescope-boot-gnome.sh), which
|
||||
# restarts gdm.service so it re-evaluates AutomaticLoginEnable. Plain
|
||||
# AutomaticLoginEnable/TimedLogin do not reliably re-arm after a logout
|
||||
# on their own.
|
||||
case "$DM_ID" in
|
||||
gdm)
|
||||
gnome-session-quit --no-prompt --logout 2>/dev/null \
|
||||
|| loginctl terminate-user "$(id -un)";;
|
||||
*)
|
||||
qdbus6 org.kde.Shutdown /Shutdown org.kde.Shutdown.logout;;
|
||||
esac
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
'persistent')
|
||||
systemctl --user mask cachyos-gamescope-autologin.service
|
||||
pkexec /usr/lib/steamos/steam-set-session "$DESKTOP_SESSION";;
|
||||
'oneshot')
|
||||
systemctl --user unmask cachyos-gamescope-autologin.service
|
||||
pkexec /usr/lib/steamos/steam-set-session gamescope-session.desktop;;
|
||||
'gamescope')
|
||||
pkexec /usr/lib/steamos/steam-set-session gamescope-session.desktop
|
||||
logout_current_session;;
|
||||
'desktop'|'plasma'|'gnome')
|
||||
pkexec /usr/lib/steamos/steam-set-session "$DESKTOP_SESSION"
|
||||
steam -shutdown
|
||||
systemctl --user stop gamescope-session.target;;
|
||||
*)
|
||||
[[ -n "$1" ]] && echo -e "Unknown session '$1'\n"
|
||||
cat <<INNEREOF
|
||||
Usage: $(basename "$0") <mode>
|
||||
|
||||
Modes:
|
||||
persistent
|
||||
Enable persistent session mode.
|
||||
The system will remember the last session you used and boot into it
|
||||
next time. If you last used Gamescope, it will boot into Gamescope.
|
||||
If you last used the desktop, it will boot into the desktop.
|
||||
|
||||
oneshot
|
||||
Restore default oneshot behaviour.
|
||||
Every fresh boot will start in Gamescope first, regardless of the
|
||||
previously used session.
|
||||
|
||||
gamescope
|
||||
Immediately switch to the Gamescope session.
|
||||
|
||||
desktop
|
||||
Immediately switch to the desktop session - whichever one is actually
|
||||
installed (Plasma under plasma-login-manager/SDDM, or the detected
|
||||
GNOME session under GDM). 'plasma' and 'gnome' are accepted as aliases
|
||||
for this same mode, kept for compatibility with old habits/scripts,
|
||||
but 'desktop' is the name to use since it doesn't assume either DE.
|
||||
This is the same action triggered by Steam's "Switch to Desktop".
|
||||
|
||||
Example:
|
||||
$(basename "$0") persistent
|
||||
INNEREOF
|
||||
|
||||
exit 1;;
|
||||
esac
|
||||
|
||||
if [[ -e /dev/input/.hidden ]]; then
|
||||
echo "Unhide hidden controller devices as needed"
|
||||
pkexec mv /dev/input/.hidden/* /dev/input
|
||||
pkexec rm -r /dev/input/.hidden
|
||||
fi
|
||||
SESSION_SELECT_EOF
|
||||
|
||||
sudo chmod 755 "$FIX_SHARE_DIR/steam-set-session" "$FIX_SHARE_DIR/steamos-session-select"
|
||||
sudo chown root:root "$FIX_SHARE_DIR/steam-set-session" "$FIX_SHARE_DIR/steamos-session-select"
|
||||
ok "Persistent copies installed under $FIX_SHARE_DIR."
|
||||
|
||||
REAPPLY_SCRIPT="/usr/local/bin/reapply-gamescope-gdm-fix"
|
||||
info "Installing $REAPPLY_SCRIPT (copies the fix over the real package paths)"
|
||||
sudo tee "$REAPPLY_SCRIPT" > /dev/null << EOF
|
||||
#!/bin/bash
|
||||
# Re-applies the GNOME/GDM support fix for gamescope-session-cachyos.
|
||||
# Safe to run any time; called automatically by a pacman hook after every
|
||||
# install/upgrade of that package, and once now by the setup script.
|
||||
set -euo pipefail
|
||||
install -m 755 -o root -g root "$FIX_SHARE_DIR/steam-set-session" "$STEAM_SET_SESSION"
|
||||
install -m 755 -o root -g root "$FIX_SHARE_DIR/steamos-session-select" "$SESSION_SELECT"
|
||||
EOF
|
||||
sudo chmod +x "$REAPPLY_SCRIPT"
|
||||
ok "Reapply script installed."
|
||||
|
||||
HOOK_FILE="/etc/pacman.d/hooks/95-gamescope-gdm-fix.hook"
|
||||
info "Installing pacman hook at $HOOK_FILE (auto-reapplies the fix after every package update)"
|
||||
sudo mkdir -p /etc/pacman.d/hooks
|
||||
sudo tee "$HOOK_FILE" > /dev/null << 'EOF'
|
||||
[Trigger]
|
||||
Operation = Install
|
||||
Operation = Upgrade
|
||||
Type = Package
|
||||
Target = gamescope-session-cachyos
|
||||
|
||||
[Action]
|
||||
Description = Reapplying GNOME/GDM support fix to gamescope-session-cachyos...
|
||||
When = PostTransaction
|
||||
Exec = /usr/local/bin/reapply-gamescope-gdm-fix
|
||||
EOF
|
||||
ok "Pacman hook installed - future updates to gamescope-session-cachyos will self-heal."
|
||||
|
||||
info "Applying the fix now"
|
||||
backup_file "$STEAM_SET_SESSION"
|
||||
backup_file "$SESSION_SELECT"
|
||||
sudo "$REAPPLY_SCRIPT"
|
||||
ok "steam-set-session and steamos-session-select now support GDM directly."
|
||||
echo
|
||||
|
||||
# ---------- 7. Set the user's initial default session ----------
|
||||
|
||||
info "Setting initial default session for $TARGET_USER to '$GAMESCOPE_SESSION_ID' via the now-fixed steam-set-session"
|
||||
sudo "$STEAM_SET_SESSION" "${GAMESCOPE_SESSION_ID}.desktop"
|
||||
ok "Default session set."
|
||||
echo
|
||||
|
||||
# ---------- 8. Steam background autostart (Steam+X virtual keyboard) ----------
|
||||
#
|
||||
# DE-agnostic - ported unchanged from the KDE original's step 8b, minus the
|
||||
# KWIN_IM_SHOW_ALWAYS env var (KWin-specific, meaningless under Mutter).
|
||||
|
||||
info "Configuring Steam background autostart for desktop-mode virtual keyboard support"
|
||||
steam_env_dir="$user_home/.config/environment.d"
|
||||
sudo -u "$TARGET_USER" mkdir -p "$steam_env_dir"
|
||||
sudo -u "$TARGET_USER" tee "$steam_env_dir/99-gamescope-steam-glyphs.conf" > /dev/null <<< 'STEAM_GAMEPADUI_ARGS="-gamepadui -steamos3"'
|
||||
|
||||
systemd_user_dir="$user_home/.config/systemd/user"
|
||||
sudo -u "$TARGET_USER" mkdir -p "$systemd_user_dir"
|
||||
|
||||
sudo -u "$TARGET_USER" tee "$systemd_user_dir/steam-desktop-autostart.service" > /dev/null << 'EOF'
|
||||
[Unit]
|
||||
Description=Steam Background Autostart for Virtual Keyboard
|
||||
After=graphical-session.target
|
||||
PartOf=graphical-session.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/steam -silent
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=graphical-session.target
|
||||
EOF
|
||||
|
||||
sudo -u "$TARGET_USER" rm -f "$user_home/.config/autostart/steam.desktop"
|
||||
sudo -u "$TARGET_USER" XDG_RUNTIME_DIR="/run/user/$(id -u "$TARGET_USER")" systemctl --user daemon-reload
|
||||
sudo -u "$TARGET_USER" XDG_RUNTIME_DIR="/run/user/$(id -u "$TARGET_USER")" systemctl --user enable steam-desktop-autostart.service
|
||||
ok "Steam background autostart unit installed (will start on next graphical login)."
|
||||
echo
|
||||
|
||||
# ---------- 9. "Return to Gaming Mode" desktop shortcut (no theming) ----------
|
||||
|
||||
info "Creating a plain 'Return to Gaming Mode' desktop shortcut"
|
||||
desktop_dir="$user_home/Desktop"
|
||||
if [[ -f "$user_home/.config/user-dirs.dirs" ]]; then
|
||||
xdg_desktop=$(grep '^XDG_DESKTOP_DIR=' "$user_home/.config/user-dirs.dirs" | cut -d '"' -f 2)
|
||||
[[ -n "$xdg_desktop" ]] && desktop_dir="${xdg_desktop/\$HOME/$user_home}"
|
||||
fi
|
||||
sudo -u "$TARGET_USER" mkdir -p "$desktop_dir"
|
||||
|
||||
shortcut_path="$desktop_dir/Return to Gaming Mode.desktop"
|
||||
sudo -u "$TARGET_USER" tee "$shortcut_path" > /dev/null << 'EOF'
|
||||
[Desktop Entry]
|
||||
Name=Return to Gaming Mode
|
||||
Comment=Switch session back to Gamescope
|
||||
Exec=steamos-session-select gamescope
|
||||
Icon=applications-games
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Categories=System;
|
||||
EOF
|
||||
sudo -u "$TARGET_USER" chmod +x "$shortcut_path"
|
||||
ok "Shortcut created at: $shortcut_path (using the stock icon theme - no custom icon)."
|
||||
echo
|
||||
|
||||
# ---------- 10. Summary ----------
|
||||
|
||||
echo -e "${c_bold}Setup complete.${c_reset}"
|
||||
echo "What this did:"
|
||||
echo " - Installed gamescope-session-cachyos, steam, mangohud, accountsservice (if missing)"
|
||||
echo " - Set $CUSTOM_CONF to autologin '$TARGET_USER' at boot"
|
||||
echo " - Installed $SUDOERS_FILE + gamescope-gdm-relogin.service (user unit) so gdm"
|
||||
echo " restarts on every logout, forcing real Relogin=true-equivalent behavior"
|
||||
echo " (confirmed AutomaticLoginEnable/TimedLogin alone do NOT reliably re-arm"
|
||||
echo " after logout on GDM - see the script header for the bug reports)"
|
||||
echo " - Replaced $STEAM_SET_SESSION and $SESSION_SELECT with GDM-aware versions,"
|
||||
echo " with a persistent copy under $FIX_SHARE_DIR and a pacman hook"
|
||||
echo " ($HOOK_FILE) that automatically reapplies them after every"
|
||||
echo " gamescope-session-cachyos update - self-healing, no manual steps, no PR needed"
|
||||
echo " - Set '$TARGET_USER's initial default session to gamescope"
|
||||
echo " - Configured Steam background autostart (steam-desktop-autostart.service,"
|
||||
echo " user unit) so Steam+X virtual keyboard works in desktop mode"
|
||||
echo " - Created a plain 'Return to Gaming Mode' desktop shortcut (stock icon)"
|
||||
echo
|
||||
echo "Steam's own in-Big-Picture 'Switch to Desktop' button now works too, since it"
|
||||
echo "calls steamos-session-select by path and that's exactly what was replaced."
|
||||
echo
|
||||
echo "To manually flip sessions any time:"
|
||||
echo " steamos-session-select gamescope # switch to gamescope right now"
|
||||
echo " steamos-session-select desktop # switch to desktop right now (also: plasma, gnome)"
|
||||
echo " steamos-session-select persistent # remember last-used session across reboots"
|
||||
echo " steamos-session-select oneshot # always start in gamescope (default Deck behavior)"
|
||||
echo
|
||||
echo "Deliberately NOT done here: Vapor theme, wallpaper, icon cache, launcher icon"
|
||||
echo "theming - out of scope."
|
||||
echo
|
||||
echo "Backups of any files this script modified were saved with a"
|
||||
echo ".bak-gamescope-wizard-gnome suffix next to the original."
|
||||
echo
|
||||
|
||||
if ask_yn "Reboot now to test it?" n; then
|
||||
sudo reboot
|
||||
else
|
||||
info "Skipping reboot. Run 'sudo reboot' whenever you're ready to test."
|
||||
fi
|
||||
Reference in new issue
Block a user