diff --git a/ansible/files/game_station/system/launch_desktop.sh b/ansible/files/game_station/system/launch_desktop.sh new file mode 100644 index 0000000..875f404 --- /dev/null +++ b/ansible/files/game_station/system/launch_desktop.sh @@ -0,0 +1,24 @@ +#!/bin/bash +set -euo pipefail +LOGFILE="$HOME/.local/logs/desktop.log" + +log() { echo "[$(date --iso-8601=seconds)] $*" | tee -a "$LOGFILE"; } + +log "Starting Desktop session..." + +DESKTOP_SESSION_BIN="$(command -v startplasma-wayland || true)" +if [ -z "$DESKTOP_SESSION_BIN" ]; then + log "ERROR: startplasma-wayland not found in PATH" + exit 127 +fi + +log "Launching Desktop: $DESKTOP_SESSION_BIN" +exec "$DESKTOP_SESSION_BIN" >>"$LOGFILE" 2>&1 & + +sleep 5 +systemd-run --user --slice=sunshine.slice --scope sunshine >>"$LOGFILE" 2>&1 || { + log "ERROR: Failed to start Sunshine" + exit 1 +} & + +tail -f /dev/null diff --git a/ansible/files/game_station/system/launch_gamescope.sh b/ansible/files/game_station/system/launch_gamescope.sh deleted file mode 100644 index 942d1d2..0000000 --- a/ansible/files/game_station/system/launch_gamescope.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/bin/bash -set -euo pipefail -LOGFILE="$HOME/.local/logs/gamescope.log" - -log() { echo "[$(date --iso-8601=seconds)] $*" | tee -a "$LOGFILE"; } - -log "Starting Gamescope session..." -CONF_FILE="$HOME/.config/gamescope/gamescope.conf" -[ -f "$CONF_FILE" ] && source "$CONF_FILE" - -OUTPUT_CONNECTOR=${OUTPUT_CONNECTOR:-HDMI-A-1} -FRAMERATE=${FRAMERATE:-60} -RESOLUTION=${RESOLUTION:-1920x1080} -WIDTH="${RESOLUTION%x*}" -HEIGHT="${RESOLUTION#*x}" - -export __GL_GSYNC_ALLOWED=1 -export __GL_VRR_ALLOWED=1 -# export __GL_THREADED_OPTIMIZATIONS=1 -export __GL_SHADER_DISK_CACHE=1 -export __GL_SYNC_TO_VBLANK=0 - -GAMESCOPE_BIN="$(command -v gamescope || true)" -if [ -z "$GAMESCOPE_BIN" ]; then - log "ERROR: gamescope not found in PATH" - exit 127 -fi - -HDR_FLAG="" -if [[ "$HDR_ENABLED" == "1" || "$HDR_ENABLED" == "true" || "$HDR_ENABLED" == "yes" ]]; then - HDR_FLAG="--hdr-enabled" - log "HDR flag added: --hdr-enabled" -else - log "HDR disabled, no HDR flag added" -fi - -GAMESCOPE_ARGS="--generate-drm-mode fixed --fade-out-duration 200 --cursor-scale-height 720 -f -w $WIDTH -h $HEIGHT --rt --mangoapp -e -O \"$OUTPUT_CONNECTOR\" -r $FRAMERATE $HDR_FLAG" -log "Launching Gamescope: $GAMESCOPE_BIN $GAMESCOPE_ARGS -- /usr/local/bin/launch_steam.sh" -exec "$GAMESCOPE_BIN" ${GAMESCOPE_ARGS} -- /usr/local/bin/launch_steam.sh >>"$LOGFILE" 2>&1 diff --git a/ansible/files/game_station/system/launch_kde.sh b/ansible/files/game_station/system/launch_kde.sh new file mode 100644 index 0000000..fb036a8 --- /dev/null +++ b/ansible/files/game_station/system/launch_kde.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail +LOGFILE="$HOME/.local/logs/desktop.log" +export PATH="$HOME/.local/bin:$PATH" + +log() { echo "[$(date --iso-8601=seconds)] $*" | tee -a "$LOGFILE"; } + +DESKTOP_BIN="$(command -v startplasma-wayland || true)" +if [ -z "$DESKTOP_BIN" ]; then + log "ERROR: startplasma-wayland not found in PATH" + exit 127 +fi + +log "Launching Plasma: $DESKTOP_BIN" +exec $DESKTOP_BIN >>"$LOGFILE" 2>&1 & + +sleep 5 +systemd-run --user --slice=sunshine.slice --scope sunshine >>"$LOGFILE" 2>&1 || { + log "ERROR: Failed to start Sunshine" + exit 1 +} & + +tail -f /dev/null \ No newline at end of file diff --git a/ansible/files/game_station/system/launch_session.sh b/ansible/files/game_station/system/launch_session.sh new file mode 100644 index 0000000..007ebb3 --- /dev/null +++ b/ansible/files/game_station/system/launch_session.sh @@ -0,0 +1,64 @@ +#!/bin/bash +set -euo pipefail +LOGFILE="$HOME/.local/logs/gamescope.log" + +log() { echo "[$(date --iso-8601=seconds)] $*" | tee -a "$LOGFILE"; } + +CONF_FILE="$HOME/.config/gamescope/gamescope.conf" +[ -f "$CONF_FILE" ] && source "$CONF_FILE" + +OUTPUT_CONNECTOR=${OUTPUT_CONNECTOR:-HDMI-A-1} +FRAMERATE=${FRAMERATE:-60} +RESOLUTION=${RESOLUTION:-1920x1080} +WIDTH="${RESOLUTION%x*}" +HEIGHT="${RESOLUTION#*x}" + +start_gamescope() { + log "Starting Gamescope session..." + + export __GL_GSYNC_ALLOWED=1 + export __GL_VRR_ALLOWED=1 + # export __GL_THREADED_OPTIMIZATIONS=1 + export __GL_SHADER_DISK_CACHE=1 + export __GL_SYNC_TO_VBLANK=0 + + GAMESCOPE_BIN="$(command -v gamescope || true)" + if [ -z "$GAMESCOPE_BIN" ]; then + log "ERROR: gamescope not found in PATH" + exit 127 + fi + + HDR_FLAG="" + if [[ "$HDR_ENABLED" == "1" || "$HDR_ENABLED" == "true" || "$HDR_ENABLED" == "yes" ]]; then + HDR_FLAG="--hdr-enabled" + log "HDR flag added: --hdr-enabled" + else + log "HDR disabled, no HDR flag added" + fi + + GAMESCOPE_ARGS="--generate-drm-mode fixed --fade-out-duration 200 --cursor-scale-height 720 -f -w $WIDTH -h $HEIGHT --rt --mangoapp -e -O \"$OUTPUT_CONNECTOR\" -r $FRAMERATE $HDR_FLAG" + log "Launching Gamescope: $GAMESCOPE_BIN $GAMESCOPE_ARGS -- $@" + exec "$GAMESCOPE_BIN" ${GAMESCOPE_ARGS} -- "$@" >>"$LOGFILE" 2>&1 +} + +start_kwin() { + log "Starting KWin session..." + KWIN_BIN="$(command -v kwin_wayland || true)" + if [ -z "$KWIN_BIN" ]; then + log "ERROR: kwin_wayland not found in PATH" + exit 127 + fi + + KWIN_ARGS="--width $WIDTH --height $HEIGHT" + log "Launching KWin: $KWIN_BIN" + exec "$KWIN_BIN" ${KWIN_ARGS} "$@" >>"$LOGFILE" 2>&1 +} + +if [[ -f "$HOME/.desktop-session-plasma" ]]; then + log "Plasma session selected." + rm "$HOME/.desktop-session-plasma" + start_kwin /usr/local/bin/launch_kde.sh +else + log "Gamescope session selected." + start_gamescope /usr/local/bin/launch_steam.sh +fi \ No newline at end of file diff --git a/ansible/files/game_station/system/launch_steam.sh b/ansible/files/game_station/system/launch_steam.sh index 8d9c1be..ea6b577 100644 --- a/ansible/files/game_station/system/launch_steam.sh +++ b/ansible/files/game_station/system/launch_steam.sh @@ -101,7 +101,7 @@ srm add >> "$LOGFILE" 2>&1 || log "ERROR: Steam ROM Manager update failed" STEAM_ARGS=("-steamdeck" "-steamos3" "-steampal" "-gamepadui" "-pipewire-dmabuf") log "Launching Steam: $STEAM_BIN ${STEAM_ARGS[*]}" -exec steam "${STEAM_ARGS[@]}" & +exec $STEAM_BIN "${STEAM_ARGS[@]}" & sleep 5 systemd-run --user --slice=sunshine.slice --scope sunshine >>"$LOGFILE" 2>&1 || { diff --git a/ansible/files/game_station/system/steamos-session-select b/ansible/files/game_station/system/steamos-session-select new file mode 100644 index 0000000..8674a47 --- /dev/null +++ b/ansible/files/game_station/system/steamos-session-select @@ -0,0 +1,27 @@ +#!/bin/bash +set -euo pipefail +LOGFILE="$HOME/.local/logs/session.log" + +log() { echo "[$(date --iso-8601=seconds)] $*" | tee -a "$LOGFILE"; } + +session="${1:-gamescope}" + +case "$session" in + plasma*) + log "Plasma session selected." + touch "$HOME/.desktop-session-plasma" + ;; + gamescope) + log "Gamescope session selected." + if [[ -f "$HOME/.desktop-session-plasma" ]]; then + rm "$HOME/.desktop-session-plasma" + fi + ;; + *) + log "!! Unrecognized session '$session'" + exit 1 + ;; +esac + +log "Restarting graphical session service..." +sudo systemctl restart gamescope-session.service \ No newline at end of file diff --git a/ansible/files/game_station/systemd/system/gamescope-session.service b/ansible/files/game_station/systemd/system/gamescope-session.service index 53bcdbe..bf91a6b 100644 --- a/ansible/files/game_station/systemd/system/gamescope-session.service +++ b/ansible/files/game_station/systemd/system/gamescope-session.service @@ -21,7 +21,7 @@ Environment=XDG_SEAT=seat0 Environment=XDG_RUNTIME_DIR=/run/user/%U Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%U/bus ExecStartPre=/usr/bin/chvt 1 -ExecStart=/usr/bin/bash /usr/local/bin/launch_gamescope.sh +ExecStart=/usr/bin/bash /usr/local/bin/launch_session.sh Restart=always KeyringMode=shared diff --git a/ansible/playbook_game_station.yml b/ansible/playbook_game_station.yml index 596d55b..2aaecc1 100644 --- a/ansible/playbook_game_station.yml +++ b/ansible/playbook_game_station.yml @@ -88,12 +88,15 @@ ansible.builtin.command: systemctl set-default graphical.target changed_when: false - - name: Disable GDM display manager + - name: Disable Unwanted services become: true ansible.builtin.systemd: - name: gdm + name: "{{ item }}" enabled: false state: stopped + loop: + - gdm + - sddm # System actions - name: Create Gamescope slice @@ -144,7 +147,7 @@ become: true ansible.builtin.file: path: /root/.local/logs/jupiter-biosupdate.log - state: touch + state: file owner: root group: root mode: "0644" @@ -166,7 +169,7 @@ - video - audio - input - shell: /bin/bash + shell: /bin/zsh create_home: true state: present