updater.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. trap 'error_handler ${LINENO}' ERR
  22. # Wait for Ryujinx to exit.
  23. # If the main process is still acitve, we wait for 1 second and check it again.
  24. # After the fifth time checking, this script exits with status 1.
  25. attempt=0
  26. while true; do
  27. if lsof -p "$APP_PID" +r 1 &>/dev/null || ps -p "$APP_PID" &>/dev/null; then
  28. if [ "$attempt" -eq 4 ]; then
  29. exit 1
  30. fi
  31. sleep 1
  32. else
  33. break
  34. fi
  35. (( attempt++ ))
  36. done
  37. sleep 1
  38. # Now replace and reopen.
  39. rm -rf "$INSTALL_DIRECTORY"
  40. mv "$NEW_APP_DIRECTORY" "$INSTALL_DIRECTORY"
  41. if [ "$#" -le 3 ]; then
  42. open -a "$INSTALL_DIRECTORY"
  43. else
  44. open -a "$INSTALL_DIRECTORY" --args "${APP_ARGUMENTS[@]}"
  45. fi