Create missing ports in RetroPie (moonlight example)

# create the launch config directory
mkdir /opt/retropie/configs/ports/moonlight

# create the launch config
cat <<EOF > /opt/retropie/configs/ports/moonlight/emulators.cfg
moonlight = "/opt/retropie/configs/ports/moonlight/moonlight.sh"
default = "moonlight"
EOF

# create launch script
cat <<EOF > /opt/retropie/configs/ports/moonlight/moonlight.sh
#!/bin/bash
tvservice -e "DMT 82"
/opt/retropie/supplementary/moonlight/bin/moonlight stream -mapping /opt/retropie/supplementary/moonlight/share/moonlight/gamecontrollerdb.txt -verbose -1080 -fps 60 -app Desktop -platform pi
EOF

# set permissions
chmod +x /opt/retropie/configs/ports/moonlight/moonlight.sh
chown pi:pi /opt/retropie/configs/ports/moonlight -R

# create the ports launch file
cat <<EOF > /home/pi/RetroPie/roms/ports/moonlight.sh
#!/bin/bash
"/opt/retropie/supplementary/runcommand/runcommand.sh" 0 _PORT_ "moonlight" ""
EOF

chown pi:pi /home/pi/RetroPie/roms/ports/moonlight.sh
chmod +x /home/pi/RetroPie/roms/ports/moonlight.sh

# create an on-end script to reset the Pi resolution
cat <<EOF > /opt/retropie/configs/all/runcommand-onend.sh
#!/bin/bash
tvservice -p
EOF

chown pi:pi /opt/retropie/configs/all/runcommand-onend.sh
chmod +x /opt/retropie/configs/all/runcommand-onend.sh