Files
gamescope-session-portprotonqt/usr/bin/portproton-session-select
2025-06-09 21:25:57 +05:00

150 lines
4.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
die() { echo >&2 "!! $*"; exit 1; }
SENTINEL_FILE="gamescope-session-type"
# Determine the configuration directory
if [[ "$USER" == "root" ]] ; then
config_dir="${XDG_CONF_DIR:-"/home/$4/.config"}"
else
config_dir="${XDG_CONF_DIR:-"$HOME/.config"}"
fi
[[ -f "$config_dir/$SENTINEL_FILE" ]] && source "$config_dir/$SENTINEL_FILE"
session="${1:-gamescope}"
session_launcher=""
create_sentinel=""
if [[ "$2" == "--sentinel-created" ]]; then
SENTINEL_CREATED=1
fi
# Ensure necessary environment variables are set
if [[ -z "$HOME" ]]; then
die "No \$HOME variable"
fi
update_config_sentinel() {
[[ $EUID == 0 ]] && die "Running $0 as root is not allowed"
mkdir -p "$config_dir"
if [[ ! -f "$config_dir/$SENTINEL_FILE" ]]; then
if [[ "$XDG_SESSION_TYPE" == "wayland" ]]; then
echo "SESSION_TYPE=wayland" > "$config_dir/$SENTINEL_FILE"
else
echo "SESSION_TYPE=x11" > "$config_dir/$SENTINEL_FILE"
fi
echo "DE=$XDG_CURRENT_DESKTOP" >> "$config_dir/$SENTINEL_FILE"
fi
}
configure_lightdm() {
sed -i "s/^.*autologin-user=.*/autologin-user=${USER}/" /etc/lightdm/lightdm.conf.d/10-gamescope-session.conf
sed -i "s/^.*autologin-user-timeout=.*/autologin-user-timeout=0/" /etc/lightdm/lightdm.conf.d/10-gamescope-session.conf
sed -i "s/^.*autologin-session=.*/autologin-session=$session_launcher/" /etc/lightdm/lightdm.conf.d/10-gamescope-session.conf
systemctl restart lightdm
}
configure_sddm() {
sed -i "s/^.*Relogin=.*/Relogin=true/" /etc/sddm.conf.d/10-gamescope-session.conf
sed -i "s/^.*Session=.*/Session=$session_launcher/" /etc/sddm.conf.d/10-gamescope-session.conf
sed -i "s/^.*User=.*/User=${USER}/" /etc/sddm.conf.d/10-gamescope-session.conf
systemctl restart sddm
}
yad_question() {
env GDK_BACKEND="x11" yad --window-icon="/usr/share/icons/hicolor/scalable/actions/steamdeck-gaming-return.svg" --image="/usr/share/icons/hicolor/scalable/actions/steamdeck-gaming-return.svg" --question --title="$1" --text="$2" --width=300 --text-align=center
[[ "$?" != 0 ]] && return 1 || return 0
}
if [[ -z $SENTINEL_CREATED ]]; then
update_config_sentinel
export SENTINEL_CREATED=1
fi
if [[ $(grep -E '^X-KDE-PluginInfo-Version=' /usr/share/xsessions/plasmax11.desktop | cut -d'=' -f2) =~ 6.* ]] ; then
KDE6="true"
fi
case "$session" in
desktop)
if [[ "$SESSION_TYPE" == "wayland" ]]; then
if [[ "$DE" == "GNOME" ]]; then
session_launcher="gnome-wayland"
elif [[ "$DE" == "KDE" ]]; then
session_launcher="plasma"
[[ "$KDE6" != "true" ]] && session_launcher="plasmawayland"
fi
else
if [[ "$DE" == "GNOME" ]]; then
session_launcher="gnome-xorg"
elif [[ "$DE" == "KDE" ]]; then
session_launcher="plasmax11"
[[ "$KDE6" != "true" ]] && session_launcher="plasma"
elif [[ "$DE" == "MATE" ]]; then
session_launcher="mate"
fi
fi
create_sentinel=1
;;
gamescope)
session_launcher="gamescope-session-steam"
create_sentinel=1
;;
*)
die "Unrecognized session '$session'"
;;
esac
echo "Updated user selected session to $session_launcher"
if [[ ! -z $4 ]]; then
USER="$4"
fi
if systemctl is-active --quiet gdm; then
env GDK_BACKEND="x11" yad --window-icon="/usr/share/icons/hicolor/scalable/actions/steamdeck-gaming-return.svg" --image="/usr/share/icons/hicolor/scalable/actions/steamdeck-gaming-return.svg" --title="Требуется подтверждение" --text="Для работы данной функии требуется LIGHTDM или SDDM, GDM не поддерживается" --width=290 --text-align=center --button="OK"
echo "autologin=false" >> "$config_dir/$SENTINEL_FILE"
die "Autologin configuration aborted due to GDM."
fi
if ! grep -iq "autologin" "$config_dir/$SENTINEL_FILE" || [[ "$2" == "plasma" ]] || [[ "$2" == "desktop" ]] ; then
if yad_question "Требуется подтверждение" "Для работы данной функции требуется настроить автологин. Хотите ли вы, чтобы это было настроено автоматически?" ; then
echo "autologin=true" >> "$config_dir/$SENTINEL_FILE"
echo "autologin enabled"
else
echo "autologin=false" >> "$config_dir/$SENTINEL_FILE"
echo "autologin disabled"
fi
fi
[[ -f "$config_dir/$SENTINEL_FILE" ]] && source "$config_dir/$SENTINEL_FILE"
if [[ "$autologin" == "true" ]] ; then
# Re-execute as root
if [[ $EUID != 0 ]]; then
exec pkexec "$(realpath $0)" "$session" --sentinel-created "$session_type" "$USER"
exit 1
fi
if ! grep -q "nopasswdlogin" "/etc/group" ; then
groupadd -r nopasswdlogin
fi
if ! id -nG "$USER" | grep -qw "nopasswdlogin"; then
gpasswd -a "$USER" nopasswdlogin
fi
if systemctl is-active --quiet lightdm; then
configure_lightdm
fi
if systemctl is-active --quiet sddm; then
configure_sddm
fi
fi