Advertisement
zefie

RetroPie Moonlight GameStream Generator

Nov 18th, 2020 (edited)
1,453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.93 KB | None | 0 0
  1. #!/bin/bash
  2. if [ "${USER}" != "root" ]; then
  3.         echo "Error: Run with sudo/root"
  4.         exit 1;
  5. fi
  6.  
  7. FILE_PREFIX="NVidia GameStream"
  8. SCRIPT_PATH="/home/pi/RetroPie/roms/ports"
  9. MOONLIGHT_SCRIPT="/opt/retropie/supplementary/moonlight/moonlight.sh"
  10. MOONLIGHT_ZES_SCRIPT="/opt/retropie/supplementary/moonlight/moonlight-zes.sh"
  11.  
  12.  
  13. IFS=$'\n'
  14.  
  15. function get_nickname() {
  16.         case $1 in
  17.                 "192.168.11.8")
  18.                         echo "DESKTOP-ZEFIE";
  19.                         ;;
  20.                 *)
  21.                         echo $1;
  22.                         ;;
  23.         esac
  24. }
  25.  
  26. function make_script() {
  27.         local OUT="${1}"
  28.         echo "Creating ${OUT}"
  29.         echo '#!/bin/bash' > "${OUT}"
  30.         echo "GAME_NAME=\"${2}\"" >> "${OUT}"
  31.         echo ". ${MOONLIGHT_ZES_SCRIPT}" >> "${OUT}"
  32.         chmod 755 "${OUT}"
  33. }
  34.  
  35. function make_zes_script() {
  36.         local OUT="${1}"
  37.         echo "Creating ${OUT}"
  38.         echo '#!/bin/bash' > "${OUT}"
  39.         echo 'if [ -z "${GAME_NAME}" ]; then' >> "${OUT}"
  40.         echo -e "\t\"${MOONLIGHT_SCRIPT}\" stream" >> "${OUT}"
  41.         echo "else" >> "${OUT}"
  42.         echo -e "\t\"${MOONLIGHT_SCRIPT}\" stream -app \"\${GAME_NAME}\"" >> "${OUT}"
  43.         echo "fi" >> "${OUT}"
  44. }
  45.  
  46.  
  47. if [ ! -f "${MOONLIGHT_ZES_SCRIPT}" ]; then
  48.         make_zes_script "${MOONLIGHT_ZES_SCRIPT}"
  49. fi
  50.  
  51. cd "${SCRIPT_PATH}"
  52. echo "Clearing old scripts (if any)..."
  53. rm -f "${FILE_PREFIX}"*.sh
  54.  
  55. for g in $("${MOONLIGHT_SCRIPT}" list); do
  56.         if [[ $g =~ ^[0-9] ]]; then
  57.                 GAME_NAME=$(echo "${g}" | cut -d' ' -f2-)
  58.                 FILE_NAME="${FILE_PREFIX} ($(echo "${GAME_NAME}" | tr -cd '\11\12\15\40-\176' | sed 's/://g') on ${HOST}).sh"
  59.                 make_script "${SCRIPT_PATH}/${FILE_NAME}" "${GAME_NAME}";
  60.         fi
  61.  
  62.         if [[ $g =~ ^Connect ]]; then
  63.                 HOST=$(get_nickname $(echo "${g}" | cut -d' ' -f3 | sed 's/\.\.\.$//'))
  64.         fi
  65. done
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement