Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions bin/omarchy-install-service-sunshine
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SUNSHINE_ADMIN_APP="Sunshine Admin"
SUNSHINE_ADMIN_URL="https://localhost:47990"
SUNSHINE_ADMIN_EXEC="omarchy-launch-webapp $SUNSHINE_ADMIN_URL --ignore-certificate-errors"
SUNSHINE_ICON_SOURCE="/usr/share/sunshine/web/images/logo-sunshine-45.png"
SUNSHINE_UNIT="app-dev.lizardbyte.app.Sunshine.service"
HYPR_AUTOSTART_FILE="$HOME/.config/hypr/autostart.lua"
HYPR_AUTOSTART_ENTRY='o.launch_on_start("sunshine")'

Expand Down Expand Up @@ -60,18 +61,13 @@ install_admin_webapp() {
omarchy-webapp-install "$SUNSHINE_ADMIN_APP" "$SUNSHINE_ADMIN_URL" "$SUNSHINE_ICON_SOURCE" "$SUNSHINE_ADMIN_EXEC"
}

enable_hyprland_autostart() {
mkdir -p "$(dirname "$HYPR_AUTOSTART_FILE")"
touch "$HYPR_AUTOSTART_FILE"

if ! grep -Fxq "$HYPR_AUTOSTART_ENTRY" "$HYPR_AUTOSTART_FILE"; then
printf '\n%s\n' "$HYPR_AUTOSTART_ENTRY" >>"$HYPR_AUTOSTART_FILE"
fi
}

echo "Installing Sunshine..."
omarchy-pkg-add sunshine
systemctl --user enable --now sunshine
systemctl --user enable --now "$SUNSHINE_UNIT"

if [[ -f $HYPR_AUTOSTART_FILE ]]; then
sed -i "\|^$HYPR_AUTOSTART_ENTRY$|d" "$HYPR_AUTOSTART_FILE"
fi

echo "Opening Sunshine firewall ports..."
open_ufw_ports
Expand All @@ -80,8 +76,5 @@ echo "Installing Sunshine admin web app..."
install_admin_webapp
$SUNSHINE_ADMIN_EXEC >/dev/null 2>&1 &

echo "Enabling Sunshine autostart..."
enable_hyprland_autostart

echo ""
echo "Sunshine has been installed and its Moonlight streaming ports are open for private LANs and Tailscale."
3 changes: 2 additions & 1 deletion bin/omarchy-remove-service-sunshine
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TCP_PORTS=(47984 47989 48010)
UDP_PORTS=(5353 47998 47999 48000 48002 48010)
PRIVATE_CIDRS=(10.0.0.0/8 172.16.0.0/12 192.168.0.0/16)
SUNSHINE_ADMIN_APP="Sunshine Admin"
SUNSHINE_UNIT="app-dev.lizardbyte.app.Sunshine.service"
HYPR_AUTOSTART_FILE="$HOME/.config/hypr/autostart.lua"
HYPR_AUTOSTART_ENTRY='o.launch_on_start("sunshine")'

Expand Down Expand Up @@ -59,7 +60,7 @@ disable_hyprland_autostart() {
fi
}

systemctl --user disable --now sunshine 2>/dev/null || true
systemctl --user disable --now "$SUNSHINE_UNIT" 2>/dev/null || true
omarchy-pkg-drop sunshine
omarchy-webapp-remove "$SUNSHINE_ADMIN_APP" 2>/dev/null || true
disable_hyprland_autostart
Expand Down
10 changes: 10 additions & 0 deletions migrations/1789703649.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
echo "Stop starting Sunshine twice at login"

# Keep a user's sole launcher when they disabled the unit to avoid the double start.
# An explicit reinstall enables the unit and removes the legacy launcher instead.
file="$HOME/.config/hypr/autostart.lua"
entry='o.launch_on_start("sunshine")'

if [[ -f $file ]] && grep -Fxq "$entry" "$file" && systemctl --user is-enabled --quiet app-dev.lizardbyte.app.Sunshine.service; then
sed -i "\|^$entry$|d" "$file"
fi
134 changes: 134 additions & 0 deletions test/shell.d/sunshine-autostart-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

unit="app-dev.lizardbyte.app.Sunshine.service"
entry='o.launch_on_start("sunshine")'

test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT
mock_bin="$test_tmp/bin"
mkdir -p "$mock_bin"

cat >"$mock_bin/systemctl" <<'MOCK'
#!/bin/bash
printf 'systemctl %s\n' "$*" >>"$OMARCHY_TEST_LOG"
case $2 in
enable) exit "$OMARCHY_TEST_ENABLE_STATUS" ;;
disable) exit "$OMARCHY_TEST_DISABLE_STATUS" ;;
esac
MOCK

cat >"$mock_bin/external" <<'MOCK'
#!/bin/bash
printf '%s %s\n' "${0##*/}" "$*" >>"$OMARCHY_TEST_LOG"
case ${0##*/} in
omarchy-cmd-missing|ip) exit 1 ;;
esac
MOCK
chmod +x "$mock_bin/systemctl" "$mock_bin/external"
for command in omarchy-pkg-add omarchy-pkg-drop omarchy-webapp-install omarchy-webapp-remove omarchy-launch-webapp omarchy-cmd-missing sudo ip; do
ln -s external "$mock_bin/$command"
done

export PATH="$mock_bin:$PATH" OMARCHY_PATH="$ROOT"
export OMARCHY_TEST_ENABLE_STATUS=0 OMARCHY_TEST_DISABLE_STATUS=0

home="$test_tmp/home"
autostart="$home/.config/hypr/autostart.lua"

reset_home() {
rm -rf "$home"
mkdir -p "$home/.config/hypr"
cat >"$autostart" <<'LUA'
-- Extra autostart processes.
o.launch_on_start("my-service")
LUA
export OMARCHY_TEST_LOG=$(mktemp -p "$test_tmp" commands.XXXXXX)
}

uses_alias() {
grep -Eq '^systemctl --user (enable|disable) --now sunshine(\.service)?$' "$OMARCHY_TEST_LOG"
}

reset_home
printf '%s\n' "$entry" >>"$autostart"
HOME="$home" bash "$ROOT/bin/omarchy-install-service-sunshine" >/dev/null

# The installer backgrounds the web app launch; wait for the mock to run, or cleanup could let it find the real one.
for _ in {1..50}; do
grep -q '^omarchy-launch-webapp ' "$OMARCHY_TEST_LOG" && break
sleep 0.1
done
grep -q '^omarchy-launch-webapp ' "$OMARCHY_TEST_LOG" || fail "Sunshine installer opens the admin web app"

grep -Fxq "systemctl --user enable --now $unit" "$OMARCHY_TEST_LOG" || fail "Sunshine installer enables the canonical user unit"
if uses_alias; then
fail "Sunshine installer does not enable the sunshine alias"
fi
pass "Sunshine installer enables the canonical user unit"
grep -Fq 'o.launch_on_start("my-service")' "$autostart" || fail "Sunshine installer leaves other autostart entries"
if grep -Fq "$entry" "$autostart"; then
fail "Sunshine installer removes the legacy Hyprland autostart copy"
fi
pass "Sunshine installer removes the legacy Hyprland autostart copy"

reset_home
printf '%s\n' "$entry" >>"$autostart"
OMARCHY_TEST_ENABLE_STATUS=1
if HOME="$home" bash "$ROOT/bin/omarchy-install-service-sunshine" >"$test_tmp/output" 2>&1; then
fail "Sunshine installer fails when the unit cannot be enabled"
fi
grep -Fxq "systemctl --user enable --now $unit" "$OMARCHY_TEST_LOG" || fail "Sunshine installer tries to enable the canonical user unit"
grep -Fxq "$entry" "$autostart" || fail "Sunshine installer keeps the legacy launcher when enable fails"
if grep -Eq '^(sudo|omarchy-cmd-missing|omarchy-webapp-install|omarchy-launch-webapp) ' "$OMARCHY_TEST_LOG"; then
fail "Sunshine installer skips firewall and web-app setup when enable fails"
fi
if grep -Fq 'Sunshine has been installed' "$test_tmp/output"; then
fail "Sunshine installer does not report success when enable fails"
fi
pass "Sunshine installer stops before firewall and web-app setup when enable fails"
OMARCHY_TEST_ENABLE_STATUS=0

reset_home
printf '%s\n' "$entry" >>"$autostart"
HOME="$home" bash "$ROOT/bin/omarchy-remove-service-sunshine" >/dev/null
awk -v expected="systemctl --user disable --now $unit" '
$0 == expected { disabled = 1 }
$0 == "omarchy-pkg-drop sunshine" { removed = disabled }
END { exit !removed }
' "$OMARCHY_TEST_LOG" || fail "Sunshine removal disables the canonical user unit before removing the package"
if uses_alias; then
fail "Sunshine removal does not disable the sunshine alias"
fi
pass "Sunshine removal disables the canonical user unit before removing the package"
grep -Fq 'o.launch_on_start("my-service")' "$autostart" || fail "Sunshine removal leaves other autostart entries"
if grep -Fq "$entry" "$autostart"; then
fail "Sunshine removal strips a leftover Hyprland autostart line"
fi
pass "Sunshine removal strips a leftover Hyprland autostart line"

reset_home
OMARCHY_TEST_DISABLE_STATUS=1
HOME="$home" bash "$ROOT/bin/omarchy-remove-service-sunshine" >/dev/null
grep -Fxq "systemctl --user disable --now $unit" "$OMARCHY_TEST_LOG" || fail "Sunshine removal tries to disable the canonical user unit"
grep -Fxq 'omarchy-pkg-drop sunshine' "$OMARCHY_TEST_LOG" || fail "Sunshine removal still removes the package when disable fails"
pass "Sunshine removal still removes the package when disable fails"
OMARCHY_TEST_DISABLE_STATUS=0

reset_home
printf '%s\n' "$entry" >>"$autostart"
HOME="$home" bash -euo pipefail "$ROOT/migrations/1789703649.sh" >/dev/null
grep -Fq 'o.launch_on_start("my-service")' "$autostart" ||
fail "Sunshine migration leaves other autostart entries"
if grep -Fq "$entry" "$autostart"; then
fail "Sunshine migration removes the duplicate autostart line"
fi
pass "Sunshine migration removes the duplicate autostart line"

HOME="$home" bash -euo pipefail "$ROOT/migrations/1789703649.sh" >/dev/null
grep -Fq 'o.launch_on_start("my-service")' "$autostart" ||
fail "Sunshine migration is idempotent"
pass "Sunshine migration is idempotent"