From c14626b10494b03176f2df4ceb1f796754857d3d Mon Sep 17 00:00:00 2001 From: Kristian Ollikainen <14197772+DatCaptainHorse@users.noreply.github.com> Date: Fri, 31 Jan 2025 02:49:59 +0200 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=20feat(scripts):=20Auto-launch=20Stea?= =?UTF-8?q?m=20(#173)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Woop Co-authored-by: DatCaptainHorse --- packages/scripts/entrypoint.sh | 2 - packages/scripts/entrypoint_nestri.sh | 58 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/packages/scripts/entrypoint.sh b/packages/scripts/entrypoint.sh index 2d58a49f..8c4f6ecc 100644 --- a/packages/scripts/entrypoint.sh +++ b/packages/scripts/entrypoint.sh @@ -55,6 +55,4 @@ echo "Cleaning up old package cache..." paccache -rk1 echo "Switching to nestri user for application startup..." -# Make sure user home dir is owned properly -chown ${USER}:${USER} /home/${USER} exec sudo -E -u nestri /etc/nestri/entrypoint_nestri.sh diff --git a/packages/scripts/entrypoint_nestri.sh b/packages/scripts/entrypoint_nestri.sh index 2d895e0b..f8559afb 100644 --- a/packages/scripts/entrypoint_nestri.sh +++ b/packages/scripts/entrypoint_nestri.sh @@ -1,6 +1,13 @@ #!/bin/bash set -euo pipefail +# Make user directory owned by the default user +chown -f "$(id -nu):$(id -ng)" ~ || \ + sudo-root chown -f "$(id -nu):$(id -ng)" ~ || \ + chown -R -f -h --no-preserve-root "$(id -nu):$(id -ng)" ~ || \ + sudo-root chown -R -f -h --no-preserve-root "$(id -nu):$(id -ng)" ~ || \ + echo 'Failed to change user directory permissions, there may be permission issues' + # Source environment variables from envs.sh if [ -f /etc/nestri/envs.sh ]; then echo "Sourcing environment variables from envs.sh..." @@ -112,6 +119,27 @@ start_wlr_randr() { echo "wlr-randr configuration successful." } +# Function to start Steam +start_steam() { + if [[ -n "${STEAM_PID:-}" ]] && kill -0 "${STEAM_PID}" 2 >/dev/null; then + echo "Killing existing Steam process..." + kill "${STEAM_PID}" + fi + + echo "Starting Steam with -tenfoot..." + WAYLAND_DISPLAY=wayland-0 steam -tenfoot & + STEAM_PID=$! + + # Verify Steam started successfully + sleep 2 + if ! kill -0 "$STEAM_PID" 2>/dev/null; then + echo "Error: Steam failed to start." + return 1 + fi + echo "Steam started successfully." + return 0 +} + # Main loop to monitor processes main_loop() { trap 'echo "Terminating..."; @@ -120,6 +148,9 @@ kill "${NESTRI_PID}" fi if [[ -n "${COMPOSITOR_PID:-}" ]] && kill -0 "${COMPOSITOR_PID}" 2>/dev/null; then kill "${COMPOSITOR_PID}" +fi +if [[ -n "${STEAM_PID:-}" ]] && kill -0 "${STEAM_PID}" 2>/dev/null; then +kill "${STEAM_PID}" fi exit 0' SIGINT SIGTERM @@ -136,6 +167,14 @@ fi exit 1 fi restart_chain + start_steam || { + echo "Failed to restart Steam after chain restart." + ((RETRY_COUNT++)) + if [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]; then + echo "Max retries reached. Exiting." + exit 1 + fi + } elif ! kill -0 ${COMPOSITOR_PID:-} 2 >/dev/null; then echo "compositor crashed. Restarting compositor..." ((RETRY_COUNT++)) @@ -144,6 +183,22 @@ fi exit 1 fi start_compositor + start_steam || { + echo "Failed to restart Steam after compositor restart." + ((RETRY_COUNT++)) + if [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]; then + echo "Max retries reached. Exiting." + exit 1 + fi + } + elif ! kill -0 ${STEAM_PID:-} 2 >/dev/null; then + echo "Steam crashed. Restarting Steam..." + ((RETRY_COUNT++)) + if [ "$RETRY_COUNT" -ge "$MAX_RETRIES" ]; then + echo "Max retries reached for Steam. Exiting." + exit 1 + fi + start_steam fi done } @@ -154,5 +209,8 @@ RETRY_COUNT=0 # Start the initial chain restart_chain +# Start Steam after initial setup +start_steam + # Enter monitoring loop main_loop