[presets] update steam

This commit is contained in:
Philip Mueller
2023-07-03 15:56:02 +02:00
parent e4c9ded69f
commit b3d6b09f61
6 changed files with 128 additions and 71 deletions

View File

@@ -1,67 +1,40 @@
#! /usr/bin/bash
#!/bin/bash
set -e
die() { echo >&2 "!! $*"; exit 1; }
CONF_FILE="/etc/sddm.conf.d/99-autologin.conf"
# FIXME Purge old files and use this one
# File this script will modify, in addition to (potentially) the per-user sentinel file
CONF_FILE="/etc/sddm.conf.d/zz-steamos-autologin.conf"
SENTINEL_FILE="steamos-session-select"
# For sanity this shipped file must be present, to ensure we're still on a normal-looking setup.
CHECK_FILE="/etc/sddm.conf.d/99-autologin.conf"
CHECK_FILE="/etc/sddm.conf.d/manjaro.conf"
session="${1:-gamescope}"
session_type="wayland"
session_launcher="gamescope-session"
session_launcher=""
create_sentinel=""
session_uses_x11=""
if [[ "$2" == "--sentinel-created" ]]; then
SENTINEL_CREATED=1
session_type="wayland"
fi
# Update config sentinel
if [[ -z $SENTINEL_CREATED ]]; then
[[ $EUID == 0 ]] && die "Running $0 as root is not allowed"
[[ -n ${HOME+x} ]] || die "No \$HOME variable"
config_dir="${XDG_CONF_DIR:-"$HOME/.config"}"
session_type=$(
cd "$HOME"
mkdir -p "$config_dir"
cd "$config_dir"
if [[ -f "steamos-session-type" ]]; then
cp steamos-session-type "$SENTINEL_FILE"
else
echo "wayland" > "$SENTINEL_FILE"
fi
cat "$SENTINEL_FILE"
)
# clear steam game desktop shortcut clutter
DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
grep --files-with-matches "Exec=steam steam://rungameid/" ${DATA_HOME}/applications/* | tr '\n' '\0' | xargs -0 -I {} rm {} || true
# If we were executed as a session user and then re-execute as root below, we don't want to set root's sentinel too
export SENTINEL_CREATED=1
fi
# We use "plasma" as "desktop" to hook up to SteamOS's scripts
case "$session" in
plasma-wayland-persistent)
session_launcher="plasma"
session_launcher="plasmawayland.desktop"
;;
plasma-x11-persistent)
session_launcher="plasma"
plasma-persistent)
session_launcher="plasma.desktop"
session_uses_x11=1
;;
desktop|plasma)
session_launcher="plasma"
plasma)
session_launcher="plasma-steamos-oneshot.desktop"
create_sentinel=1
session_uses_x11=1
;;
gamescope)
session_launcher="gamescope-session"
create_sentinel=1
session_launcher="gamescope-session.desktop"
;;
*)
echo >&2 "!! Unrecognized session '$session'"
@@ -69,21 +42,43 @@ case "$session" in
;;
esac
echo "Updated user selected session to $session_launcher"
if [[ "$2" == "--sentinel-created" ]]; then
SENTINEL_CREATED=1
fi
# Update config sentinel
if [[ -z $SENTINEL_CREATED ]]; then
[[ -n ${HOME+x} ]] || die "No \$HOME variable"
config_dir="${XDG_CONF_DIR:-"$HOME/.config"}"
(
cd "$HOME"
mkdir -p "$config_dir"
cd "$config_dir"
echo "$session_launcher" > "$SENTINEL_FILE"
)
# If we were executed as a session user and then re-execute as root below, we don't want to set root's sentinel too
export SENTINEL_CREATED=1
echo "Updated user selected session to $session_launcher"
fi
# Become root
if [[ $EUID != 0 ]]; then
exec pkexec "$(realpath $0)" "$session" --sentinel-created
exit 1
fi
sed -i "s/.*Session=.*/Session=$session_launcher/g" $CONF_FILE
{
if [[ -n $session_uses_x11 ]]; then
# Default is Wayland
echo "[General]"
echo "DisplayServer=X11"
fi
echo "[Autologin]"
echo "Session=$session_launcher"
} > "$CONF_FILE"
echo "Updated system autologin session to $session_launcher"
systemctl reset-failed sddm
systemctl restart sddm
echo "Restarted SDDM"
if [[ $session == plasma ]] || [[ $session == desktop ]]; then
echo "Ending gamescope session"
pkill -f gamescope
fi