Skip to content

Instantly share code, notes, and snippets.

@kg333
Created March 13, 2026 20:44
Show Gist options
  • Select an option

  • Save kg333/56bba696beceea94e15315abe8b349b5 to your computer and use it in GitHub Desktop.

Select an option

Save kg333/56bba696beceea94e15315abe8b349b5 to your computer and use it in GitHub Desktop.
A bash script fix for Fedora Linux and Sunshine on Nvidia drivers. Monitors sometimes change their numeration - this checks for a specific monitor and swaps the output if needed.
#!/bin/bash
SUNSHINE_CONFIG=/home/username/.config/sunshine/sunshine.conf
# read the currently configured monitor
outputmon=$(grep output_name $SUNSHINE_CONFIG | cut -d ' ' -f 3)
echo "Output monitor is $outputmon."
# read the log for the currently detected output for the DisplayPort
dpmon=$(journalctl --user -u sunshine | tac | grep -m 1 DP- | cut -d ' ' -f 10)
echo "Displayport is monitor $dpmon."
# if they don't match, change the config file and restart Sunshine
if [ $outputmon -ne $dpmon ]; then
echo "Mismatch detected, fixing Sunshine!"
if [ $outputmon -eq "0" ]; then
sed -i 's/output_name = 0/output_name = 1/g' $SUNSHINE_CONFIG
else
sed -i 's/output_name = 1/output_name = 0/g' $SUNSHINE_CONFIG
fi
echo "Rebooting Sunshine now..."
systemctl --user restart sunshine.service
else
echo "Output monitor is correct for main display."
fi
[Unit]
Description=Sunshine is a self-hosted game stream host for Moonlight.
StartLimitIntervalSec=500
StartLimitBurst=5
[Service]
ExecStartPre=/bin/sleep 5
ExecStart=/usr/bin/sunshine
ExecStartPost=/bin/sleep 10
ExecStartPost=/home/username/.config/sunshine/sunshine-output-fix.sh
Restart=on-failure
RestartSec=5s
[Install]
#WantedBy=graphical-session.target
WantedBy=default.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment