Optimize installer: preflight checks, tuned conf, doctor, faster default

Layers a few things on top of the initial scaffold:

- Default to sunshine-bin (precompiled, ~seconds) instead of building from
  source. --from-source restores the old behavior.
- Add lib/preflight.sh: catches the gotchas before any work is done —
  Wayland session, NVIDIA driver responsive, nvidia-drm.modeset, amdgpu
  loaded, pipewire-pulse present, SSH-without-session warning.
- Add lib/config.sh: writes a tuned ~/.config/sunshine/sunshine.conf with
  per-vendor encoder settings (NVENC P1+ll+cbr, VAAPI ultralowlatency,
  QuickSync veryfast), KMS capture, pulse audio sink. Uses a
  "# managed-by: omarchy-moonlight" marker; removing it hands ownership
  back to the user and the installer won't touch the file again.
- Add lib/verify.sh: post-install verification of every step
  (cap_sys_admin set, group resolves, udev rule present, /dev/uinput
  exists, encoder reachable, service active, :47990 listening). Same
  checks are reachable standalone via --doctor.
- Install runtime helpers (pipewire-pulse, vulkan-tools, libva-utils)
  alongside Sunshine for diagnostics + audio.
- Uninstall handles both sunshine + sunshine-bin and the -bin moonlight
  variant.
- README documents the tuning table, the new flags, and the modeset
  troubleshooting path.
This commit is contained in:
2026-05-18 10:17:11 -06:00
parent a9dcbc1db8
commit d6b0919149
7 changed files with 339 additions and 35 deletions

61
lib/config.sh Normal file
View File

@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Write a tuned ~/.config/sunshine/sunshine.conf for low-latency LAN streaming.
# Only overwrites if (a) no config exists, or (b) our managed marker is present.
SUNSHINE_CONF_DIR="$HOME/.config/sunshine"
SUNSHINE_CONF="$SUNSHINE_CONF_DIR/sunshine.conf"
MANAGED_MARKER="# managed-by: omarchy-moonlight"
write_sunshine_config() {
mkdir -p "$SUNSHINE_CONF_DIR"
if [[ -f "$SUNSHINE_CONF" ]] && ! grep -qF "$MANAGED_MARKER" "$SUNSHINE_CONF"; then
ok "Existing sunshine.conf is user-managed — leaving it alone"
info " To re-apply tuned defaults, delete $SUNSHINE_CONF and re-run install.sh"
return 0
fi
local encoder_block
case "$GPU_VENDOR" in
nvidia)
encoder_block=$'encoder = nvenc\nnvenc_preset = p1\nnvenc_tune = ll\nnvenc_rc = cbr\nnvenc_coder = auto'
;;
amd)
encoder_block=$'encoder = vaapi\namd_quality = speed\namd_rc = cbr\namd_usage = ultralowlatency'
;;
intel)
encoder_block=$'encoder = quicksync\nqsv_preset = veryfast\nqsv_coder = auto'
;;
*)
encoder_block=$'# encoder auto-detected by Sunshine'
;;
esac
info "Writing tuned $SUNSHINE_CONF (GPU: $GPU_VENDOR)"
cat >"$SUNSHINE_CONF" <<EOF
$MANAGED_MARKER
# Generated by omarchy-moonlight install.sh on $(date -Iseconds)
# Delete this marker line to take ownership; the installer will then leave the file alone.
#
# Tuned for low-latency LAN streaming on Hyprland/Wayland with KMS capture.
# Tune further via the web UI at https://localhost:47990
sunshine_name = ${HOSTNAME_SHORT}
# Capture: KMS (DRM) — the right choice on Wayland.
capture = kms
# Encoder tuned for $GPU_VENDOR
$encoder_block
# Threading — more threads helps high-bitrate H.265/AV1.
min_threads = 4
# Use the PipeWire pulse compatibility layer for audio.
audio_sink = pulse
# Keyboard / mouse / gamepad pass-through via /dev/uinput.
# (Requires user to be in the 'input' group; install.sh handles this.)
EOF
ok "Wrote sunshine.conf"
}

View File

@@ -1,17 +1,20 @@
#!/usr/bin/env bash
# Install Sunshine, Moonlight, and GPU-specific hardware-encode dependencies.
# Default to source build (canonical AUR package). Override with SUNSHINE_PKG=sunshine-bin
# in the environment for the precompiled build (much faster install).
: "${SUNSHINE_PKG:=sunshine}"
# Default to the precompiled AUR build for a fast install (~seconds instead of
# the ~10 minute source compile). Override with SUNSHINE_PKG=sunshine to build
# from source.
: "${SUNSHINE_PKG:=sunshine-bin}"
: "${MOONLIGHT_PKG:=moonlight-qt}"
install_sunshine() {
# Ensure runtime deps useful for capture/diagnostics across vendors.
yay_install pipewire-pulse vulkan-tools libva-utils
yay_install "$SUNSHINE_PKG"
}
install_moonlight() {
# moonlight-qt is in the AUR (also a -bin variant). yay handles both.
yay_install moonlight-qt
yay_install "$MOONLIGHT_PKG"
}
install_gpu_encoder_packages() {

98
lib/preflight.sh Normal file
View File

@@ -0,0 +1,98 @@
#!/usr/bin/env bash
# Preflight: catch problems before we install anything.
# Fail fast and loud, with remediation hints.
preflight_all() {
preflight_session
preflight_remote_session
preflight_gpu
preflight_kms_modeset
preflight_audio
}
preflight_session() {
if [[ "${SESSION_TYPE:-}" != "wayland" ]]; then
warn "Session type '$SESSION_TYPE' — KMS capture works at the DRM level so it can still succeed,"
warn "but this installer's defaults assume Hyprland on Wayland."
else
ok "Wayland session detected"
fi
}
preflight_remote_session() {
# Sunshine's user service needs the local Wayland session to be reachable.
# If we're over pure SSH (no forwarded DBUS / WAYLAND_DISPLAY), the service start
# at the end of the install will fail. Warn now so the user knows.
if [[ -n "${SSH_CONNECTION:-}" && -z "${WAYLAND_DISPLAY:-}" && -z "${DISPLAY:-}" ]]; then
warn "Running over SSH without a graphical session. Packages will install,"
warn "but the systemd --user service will only come up cleanly once you log in"
warn "to Hyprland on the console. That's fine — just log in afterwards."
fi
}
preflight_gpu() {
case "$GPU_VENDOR" in
nvidia)
if ! command -v nvidia-smi >/dev/null 2>&1; then
warn "nvidia-smi not found yet — nvidia-utils will be installed shortly."
return 0
fi
if ! nvidia-smi -L >/dev/null 2>&1; then
err "nvidia-smi exists but can't talk to the driver. Driver not loaded?"
err "Check: 'lsmod | grep nvidia' and 'dmesg | grep -i nvidia'"
exit 1
fi
ok "NVIDIA driver responsive ($(nvidia-smi -L | head -n1))"
;;
amd)
if ! lsmod | grep -q '^amdgpu'; then
warn "amdgpu kernel module not loaded. Hardware encode (VAAPI) will likely fail until it is."
else
ok "amdgpu kernel module loaded"
fi
;;
intel)
ok "Intel GPU — will install intel-media-driver"
;;
esac
}
preflight_kms_modeset() {
# KMS capture needs nvidia-drm.modeset=1 on NVIDIA. Driver 560+ defaults to 1,
# but if the user is on something older or has explicitly set 0, capture will fail.
[[ "$GPU_VENDOR" == "nvidia" ]] || return 0
# Cmdline check is read-only and reliable when explicitly set.
if grep -q 'nvidia-drm.modeset=1' /proc/cmdline; then
ok "nvidia-drm.modeset=1 set on kernel cmdline"
return 0
fi
if grep -q 'nvidia-drm.modeset=0' /proc/cmdline; then
err "nvidia-drm.modeset=0 is set on the kernel cmdline. KMS capture WILL fail."
err "Remove it (e.g., from /boot/loader/entries/*.conf or /etc/kernel/cmdline + reinstall-kernels)"
err "and reboot before running this installer."
exit 1
fi
# Not on cmdline — check the runtime parameter. On 560+ this defaults to Y.
# /sys file is root-readable; modinfo gives the default without sudo.
local default=""
if command -v modinfo >/dev/null 2>&1; then
default="$(modinfo -F parm nvidia_drm 2>/dev/null | awk -F: '/^modeset:/ {print $2}' | head -n1 || true)"
fi
if [[ -n "$default" ]]; then
info "nvidia_drm modeset default per modinfo: ${default## }"
fi
warn "nvidia-drm.modeset=1 not explicitly set on cmdline."
warn "Modern drivers (≥560) default to enabled, so this is usually fine — but if KMS"
warn "capture fails after install, add 'nvidia-drm.modeset=1' to your kernel cmdline."
}
preflight_audio() {
# Sunshine captures audio via the PulseAudio API; on Omarchy that's pipewire-pulse.
if pkg_installed pipewire-pulse; then
ok "pipewire-pulse present (audio capture path OK)"
else
warn "pipewire-pulse is not installed. Audio capture may not work until it is."
fi
}

87
lib/verify.sh Normal file
View File

@@ -0,0 +1,87 @@
#!/usr/bin/env bash
# Post-install verification — confirm each piece is actually wired up.
# Prints a checklist; non-fatal so the user sees the whole picture.
VERIFY_FAILURES=0
_check() {
local name="$1"; shift
if "$@" >/dev/null 2>&1; then
ok "$name"
else
err "$name"
VERIFY_FAILURES=$((VERIFY_FAILURES + 1))
fi
}
verify_install() {
step "Verifying install"
_check "sunshine binary on PATH" command -v sunshine
local bin
bin="$(command -v sunshine 2>/dev/null || true)"
if [[ -n "$bin" ]]; then
bin="$(readlink -f "$bin")"
if getcap "$bin" 2>/dev/null | grep -q cap_sys_admin; then
ok "sunshine has cap_sys_admin (KMS capture ready)"
else
err "sunshine missing cap_sys_admin — KMS capture will fail"
VERIFY_FAILURES=$((VERIFY_FAILURES + 1))
fi
fi
if id -nG "$USER" | tr ' ' '\n' | grep -qx input; then
ok "user '$USER' resolves with 'input' group in current shell"
else
warn "user '$USER' is NOT in 'input' group in this shell session."
warn " /etc/group is correct; you need to log out + back in (or 'newgrp input')."
fi
if grep -rqs 'KERNEL=="uinput"' /etc/udev/rules.d /usr/lib/udev/rules.d /run/udev/rules.d 2>/dev/null; then
ok "uinput udev rule present"
else
err "uinput udev rule missing"
VERIFY_FAILURES=$((VERIFY_FAILURES + 1))
fi
if [[ -c /dev/uinput ]]; then
ok "/dev/uinput exists"
else
warn "/dev/uinput not present yet — may appear on next reboot or 'modprobe uinput'"
fi
case "$GPU_VENDOR" in
nvidia)
if nvidia-smi --query-gpu=encoder.stats.sessionCount --format=csv,noheader >/dev/null 2>&1; then
ok "NVENC interface reachable via nvidia-smi"
else
warn "Could not query NVENC via nvidia-smi (driver may need a reboot after install)"
fi
;;
amd)
if command -v vainfo >/dev/null 2>&1 && vainfo 2>/dev/null | grep -qi 'VAEntrypointEncSlice\|VAProfileH264'; then
ok "VAAPI encoder profiles available"
else
warn "VAAPI encoder profiles not confirmed (install libva-utils to verify with 'vainfo')"
fi
;;
esac
if systemctl --user is-active --quiet sunshine.service; then
ok "sunshine.service is active"
if ss -ltn 2>/dev/null | grep -q ':47990 '; then
ok "web UI listening on :47990"
else
warn "web UI port 47990 not yet listening (service may still be starting)"
fi
else
warn "sunshine.service is not active"
warn " Inspect: journalctl --user -u sunshine -n 50 --no-pager"
fi
if [[ $VERIFY_FAILURES -gt 0 ]]; then
warn "$VERIFY_FAILURES check(s) failed — see ${BOLD}README.md${RESET}${YELLOW} 'Diagnostics' for fixes."
else
ok "All checks passed."
fi
}