/ distribution / macos / updater.sh
updater.sh
 1  #!/bin/bash
 2  
 3  set -e
 4  
 5  INSTALL_DIRECTORY=$1
 6  NEW_APP_DIRECTORY=$2
 7  APP_PID=$3
 8  APP_ARGUMENTS=("${@:4}")
 9  
10  error_handler() {
11      local lineno="$1"
12  
13      script="""
14      set alertTitle to \"Ryujinx - Updater error\"
15      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.\"
16      display dialog alertMessage with icon caution with title alertTitle buttons {\"Open Download Page\", \"Exit\"}
17      set the button_pressed to the button returned of the result
18  
19      if the button_pressed is \"Open Download Page\" then
20          open location \"https://ryujinx.org/download\"
21      end if
22      """
23  
24      osascript -e "$script"
25      exit 1
26  }
27  
28  trap 'error_handler ${LINENO}' ERR
29  
30  # Wait for Ryujinx to exit.
31  # If the main process is still acitve, we wait for 1 second and check it again.
32  # After the fifth time checking, this script exits with status 1.
33  
34  attempt=0
35  while true; do
36      if lsof -p "$APP_PID" +r 1 &>/dev/null || ps -p "$APP_PID" &>/dev/null; then
37          if [ "$attempt" -eq 4 ]; then
38              exit 1
39          fi
40          sleep 1
41      else
42          break
43      fi
44      (( attempt++ ))
45  done
46  
47  sleep 1
48  
49  # Now replace and reopen.
50  rm -rf "$INSTALL_DIRECTORY"
51  mv "$NEW_APP_DIRECTORY" "$INSTALL_DIRECTORY"
52  
53  if [ "$#" -le 3 ]; then
54      open -a "$INSTALL_DIRECTORY"
55  else
56      open -a "$INSTALL_DIRECTORY" --args "${APP_ARGUMENTS[@]}"
57  fi