updater.sh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. set -e
  3. INSTALL_DIRECTORY=$1
  4. NEW_APP_DIRECTORY=$2
  5. APP_PID=$3
  6. APP_ARGUMENTS="${@:4}"
  7. error_handler() {
  8. local lineno="$1"
  9. script="""
  10. set alertTitle to \"Ryujinx - Updater error\"
  11. set alertMessage to \"An error occurred during Ryujinx update (updater.sh:$lineno)\n\nPlease download the update manually from our website if the problem persists.\"
  12. display dialog alertMessage with icon caution with title alertTitle buttons {\"Open Download Page\", \"Exit\"}
  13. set the button_pressed to the button returned of the result
  14. if the button_pressed is \"Open Download Page\" then
  15. open location \"https://ryujinx.org/download\"
  16. end if
  17. """
  18. osascript -e "$script"
  19. exit 1
  20. }
  21. # Wait for Ryujinx to exit
  22. # NOTE: in case no fds are open, lsof could be returning with a process still living.
  23. # We wait 1s and assume the process stopped after that
  24. lsof -p $APP_PID +r 1 &>/dev/null
  25. sleep 1
  26. trap 'error_handler ${LINENO}' ERR
  27. # Now replace and reopen.
  28. rm -rf "$INSTALL_DIRECTORY"
  29. mv "$NEW_APP_DIRECTORY" "$INSTALL_DIRECTORY"
  30. if [ "$#" -le 3 ]; then
  31. open -a "$INSTALL_DIRECTORY"
  32. else
  33. open -a "$INSTALL_DIRECTORY" --args "$APP_ARGUMENTS"
  34. fi