iso-profiles/oem/gaming-oem-kde6/desktop-overlay/usr/lib/os-session-select
2024-03-07 18:20:40 +07:00

85 lines
2 KiB
Bash
Executable file

#!/bin/bash
set -e
die() { echo >&2 "!! $*"; exit 1; }
# 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/manjaro.conf"
session="${1:-gamescope}"
session_launcher=""
create_sentinel=""
session_uses_x11=""
case "$session" in
plasma-wayland-persistent)
session_launcher="plasmawayland.desktop"
;;
plasma-persistent)
session_launcher="plasma.desktop"
session_uses_x11=1
;;
plasma)
session_launcher="plasma-steamos-oneshot.desktop"
create_sentinel=1
session_uses_x11=1
;;
gamescope)
# session_launcher="gamescope-session.desktop"
session_launcher="gamepadui-with-qam-session.desktop"
;;
*)
echo >&2 "!! Unrecognized session '$session'"
exit 1
;;
esac
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
{
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"