-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentrypoint.sh
More file actions
172 lines (137 loc) · 5.97 KB
/
Copy pathentrypoint.sh
File metadata and controls
172 lines (137 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
set -e
# Disable core dumps to prevent core.xxx files on forced restarts
ulimit -c 0
# --- 0. BOOT CLEANUP ---
echo "--- [Boot] Cleaning up ---"
# Polite ask:
killall -q sunshine gamescope steam steamwebhelper seatd pipewire wireplumber rtkit-daemon hyprland || true
sleep 2
# Force kill only the stubborn remnants:
killall -s 9 -q sunshine gamescope steam steamwebhelper seatd pipewire wireplumber rtkit-daemon hyprland || true
rm -rf /tmp/.X* /run/user/1000/* /run/seatd.sock /tmp/pulse-* /run/dbus/pid /tmp/trigger_restart 2>/dev/null
# --- 1. RUNTIME ENV ---
export SEATD_VTBOUND=0
export LIBSEAT_BACKEND=seatd
export XDG_RUNTIME_DIR=/run/user/1000
mkdir -p "$XDG_RUNTIME_DIR"
chmod 0700 "$XDG_RUNTIME_DIR"
chown steam:steam "$XDG_RUNTIME_DIR"
# Fix Steam directories for volume mounts
mkdir -p /home/steam/.config /home/steam/.steam /home/steam/.local/share/Steam
chown -R steam:steam /home/steam/.config /home/steam/.steam /home/steam/.local
# Global Permissions
chmod 666 /dev/uinput /dev/dri/card* /dev/dri/renderD* /dev/input/event* /dev/nvidia* 2>/dev/null || true
chown root:video /dev/input/event* 2>/dev/null || true
# --- 2. INIT MODULES ---
# CRITICAL FIX: Removed 'watchdog' from this synchronous loop
for script in init_system init_audio init_proton init_sunshine init_filebrowser; do
if [ -x "/usr/local/bin/scripts/${script}.sh" ]; then
/usr/local/bin/scripts/${script}.sh
fi
done
# Start Watchdog in the BACKGROUND so it doesn't block the boot process
if [ -x "/usr/local/bin/scripts/watchdog.sh" ]; then
/usr/local/bin/scripts/watchdog.sh &
fi
# --- 3. SUPERVISOR LOOP ---
while true; do
echo "--- [Supervisor] Starting Session ---"
# ----------------------------------------
# PHASE A: TEARDOWN
# ----------------------------------------
rm -f /tmp/trigger_restart
killall -q sunshine gamescope steam steamwebhelper seatd hyprland || true
sleep 2
killall -s 9 -q sunshine gamescope steam steamwebhelper seatd hyprland || true
# Socket Cleanup
rm -rf /tmp/.X11-unix /tmp/.X0-lock /run/seatd.sock "$XDG_RUNTIME_DIR/gamescope-0" "$XDG_RUNTIME_DIR"/wayland-*
mkdir -p /tmp/.X11-unix
chmod 1777 /tmp/.X11-unix
# ----------------------------------------
# PHASE B: HARDWARE PREP
# ----------------------------------------
udevadm trigger --action=change --subsystem-match=input
udevadm trigger --action=change --subsystem-match=drm
sleep 0.5
# Refresh the library cache so Vulkan and EGL can finally "see" the drivers
ldconfig 2>/dev/null || true
# Re-apply NVIDIA permissions after udevadm trigger wipes them!
chmod 666 /dev/uinput /dev/dri/card* /dev/dri/renderD* /dev/input/event* /dev/nvidia* 2>/dev/null || true
# Start Seatd
echo " [Supervisor] Starting seatd..."
seatd -g video &
SEATD_PID=$!
TIMEOUT=10
while [ ! -S "/run/seatd.sock" ]; do
sleep 0.1
((TIMEOUT--))
if [ $TIMEOUT -le 0 ]; then echo "Seatd failed to start"; break; fi
done
chmod 777 /run/seatd.sock
# ----------------------------------------
# PHASE C: LAUNCH USER SESSION
# ----------------------------------------
echo " [Supervisor] Launching Steam Session (Hyprland)..."
runuser -u steam -g steam -G video -G input -G audio -G render -- \
/usr/local/bin/scripts/steam-session.sh &
SESSION_PID=$!
# ----------------------------------------
# PHASE D: SUNSHINE & WATCHDOG
# ----------------------------------------
TIMEOUT=30
echo " [Supervisor] Waiting for Wayland socket..."
# Check for any valid wayland socket created by Hyprland
while [ -z "$(ls -A $XDG_RUNTIME_DIR/wayland-* 2>/dev/null)" ] && [ $TIMEOUT -gt 0 ]; do
sleep 0.5
((TIMEOUT--))
done
WAYLAND_SOCKET=$(ls -1 $XDG_RUNTIME_DIR/wayland-* 2>/dev/null | head -n 1 | awk -F/ '{print $NF}')
if [ -n "$WAYLAND_SOCKET" ]; then
export WAYLAND_DISPLAY=$WAYLAND_SOCKET
export PULSE_SERVER="unix:${XDG_RUNTIME_DIR}/pulse/native"
export EGL_PLATFORM=wayland
chmod 777 "$XDG_RUNTIME_DIR/$WAYLAND_SOCKET"
echo " [Supervisor] Found $WAYLAND_SOCKET. Waiting for GPU stability..."
sleep 2
LOCAL_IP=$(ip -4 route get 1.1.1.1 2>/dev/null | awk '{print $7}' || hostname -I | awk '{print $1}')
SUNSHINE_CONF="/home/steam/.config/sunshine/sunshine.conf"
# 2. Ensure the config file exists
mkdir -p /home/steam/.config/sunshine
touch "$SUNSHINE_CONF"
# 3. Strip out any old CSRF rules to prevent duplication on reboot
sed -i '/^csrf_allowed_origins/d' "$SUNSHINE_CONF"
# 4. Inject the current IP address
if [ -n "$LOCAL_IP" ]; then
echo " [Supervisor] Whitelisting Sunshine Web UI for IP: $LOCAL_IP"
echo "csrf_allowed_origins = https://${LOCAL_IP}:47990" >> "$SUNSHINE_CONF"
fi
chown steam:steam "$SUNSHINE_CONF"
echo " [Supervisor] Starting Sunshine..."
sunshine &
SUNSHINE_PID=$!
else
echo " [Supervisor] ERROR: Wayland socket failed to appear!"
fi
echo " [Supervisor] Starting File Browser..."
runuser -u steam -g steam -- filebrowser -a 0.0.0.0 -p 8080 -d /home/steam/.config/filebrowser.db &
FILEBROWSER_PID=$!
# WATCHDOG
while kill -0 "$SESSION_PID" 2>/dev/null; do
if [ -f "/tmp/trigger_restart" ]; then
echo " >>> RESTART TRIGGER DETECTED <<<"
break
fi
sleep 0.5
done
echo "--- [Supervisor] Session Ending... ---"
[ -n "$SUNSHINE_PID" ] && kill "$SUNSHINE_PID" 2>/dev/null || true
killall -9 -q steam || true
if kill -0 "$SESSION_PID" 2>/dev/null; then
kill "$SESSION_PID"
TIMEOUT=5
while kill -0 "$SESSION_PID" 2>/dev/null && [ $TIMEOUT -gt 0 ]; do sleep 0.5; ((TIMEOUT--)); done
kill -9 "$SESSION_PID" 2>/dev/null || true
fi
sleep 1
done