Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- if [ "${USER}" != "root" ]; then
- echo "Error: Run with sudo/root"
- exit 1;
- fi
- FILE_PREFIX="NVidia GameStream"
- SCRIPT_PATH="/home/pi/RetroPie/roms/ports"
- MOONLIGHT_SCRIPT="/opt/retropie/supplementary/moonlight/moonlight.sh"
- MOONLIGHT_ZES_SCRIPT="/opt/retropie/supplementary/moonlight/moonlight-zes.sh"
- IFS=$'\n'
- function get_nickname() {
- case $1 in
- "192.168.11.8")
- echo "DESKTOP-ZEFIE";
- ;;
- *)
- echo $1;
- ;;
- esac
- }
- function make_script() {
- local OUT="${1}"
- echo "Creating ${OUT}"
- echo '#!/bin/bash' > "${OUT}"
- echo "GAME_NAME=\"${2}\"" >> "${OUT}"
- echo ". ${MOONLIGHT_ZES_SCRIPT}" >> "${OUT}"
- chmod 755 "${OUT}"
- }
- function make_zes_script() {
- local OUT="${1}"
- echo "Creating ${OUT}"
- echo '#!/bin/bash' > "${OUT}"
- echo 'if [ -z "${GAME_NAME}" ]; then' >> "${OUT}"
- echo -e "\t\"${MOONLIGHT_SCRIPT}\" stream" >> "${OUT}"
- echo "else" >> "${OUT}"
- echo -e "\t\"${MOONLIGHT_SCRIPT}\" stream -app \"\${GAME_NAME}\"" >> "${OUT}"
- echo "fi" >> "${OUT}"
- }
- if [ ! -f "${MOONLIGHT_ZES_SCRIPT}" ]; then
- make_zes_script "${MOONLIGHT_ZES_SCRIPT}"
- fi
- cd "${SCRIPT_PATH}"
- echo "Clearing old scripts (if any)..."
- rm -f "${FILE_PREFIX}"*.sh
- for g in $("${MOONLIGHT_SCRIPT}" list); do
- if [[ $g =~ ^[0-9] ]]; then
- GAME_NAME=$(echo "${g}" | cut -d' ' -f2-)
- FILE_NAME="${FILE_PREFIX} ($(echo "${GAME_NAME}" | tr -cd '\11\12\15\40-\176' | sed 's/://g') on ${HOST}).sh"
- make_script "${SCRIPT_PATH}/${FILE_NAME}" "${GAME_NAME}";
- fi
- if [[ $g =~ ^Connect ]]; then
- HOST=$(get_nickname $(echo "${g}" | cut -d' ' -f3 | sed 's/\.\.\.$//'))
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement