Files
Omarchy-Stream/lib/config.sh
Levi Woodard d6b0919149 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.
2026-05-18 10:17:11 -06:00

62 lines
1.9 KiB
Bash

#!/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"
}