patcher-wrapper 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. set -eu -o pipefail
  3. helpexit() {
  4. echo "$0 version action"
  5. exit 1
  6. }
  7. test -n "${1:-}" -a -n "${2:-}" || helpexit
  8. version=${1//.}
  9. action=$2
  10. GIT_URL="https://notabug.org/Krock/dawn.git"
  11. PATCHER_HOME="$HOME/.local/share/paimon-launcher/dawn"
  12. CACHE_TIME=5 # don't update patcher if it was updated within last 5 minutes
  13. TIMESTAMP_FILE="$PATCHER_HOME.timestamp"
  14. scripts_path=`cd "\`dirname \"$0\"\`"; echo "$PWD"`
  15. patcher_dir="$PATCHER_HOME/$version"
  16. # clone or update patcher dir
  17. if [ ! -d "$PATCHER_HOME/.git" ]; then
  18. echo "Cloning patcher..."
  19. mkdir -p "$(basename $PATCHER_HOME)"
  20. git clone $GIT_URL "$PATCHER_HOME"
  21. touch "$TIMESTAMP_FILE"
  22. else
  23. if [ ! -e "$TIMESTAMP_FILE" -o -n "`find \"$TIMESTAMP_FILE\" -mmin +$CACHE_TIME`" ]; then
  24. echo "Updating patcher..."
  25. git -C "$PATCHER_HOME" pull
  26. touch "$TIMESTAMP_FILE"
  27. fi
  28. fi
  29. get_sudo_content() {
  30. echo 'set -eu -o pipefail'
  31. sed '/# START OF SUDO DANGER ZONE/,/# END OF SUDO DANGER ZONE/!d' "$patcher_dir/patch.sh"
  32. }
  33. # unfortunately pkexec doesn't work with pipes like sudo, so we have no chance to execute script as is
  34. # we cut out the sudo part and executing it to test if superuser rights needed (exit code 42 then)
  35. # if so, we do the same part again with su rights provided by pkexec (or not)
  36. # after that we can start the script itself
  37. case $action in
  38. check)
  39. echo "SERVERS_BEGIN"
  40. sed '/servers=/,/EOF/!d;/EOF/d' "$patcher_dir/patch.sh"
  41. echo "SERVERS_END"
  42. # make script exit with code 42 in case it wants sudo
  43. check_script=`get_sudo_content | sed 's/ sudo / exit 42 # /g'`
  44. bash -c "$check_script"
  45. ;;
  46. block)
  47. block_script=`get_sudo_content`
  48. # User already accepted, so reply 'y'
  49. QUIET=1 "$scripts_path/sudo-wrapper" bash -c "$block_script" <<< 'y'
  50. ;;
  51. patch)
  52. # User already accepted, so reply 'y'
  53. echo "Starting $patcher_dir/patch.sh"
  54. bash "$patcher_dir/patch.sh" <<< 'y'
  55. if [ -f "$patcher_dir/patch_anti_logincrash.sh" ]; then
  56. # User already accepted, so reply 'y'
  57. bash "$patcher_dir/patch_anti_logincrash.sh" <<< 'y'
  58. fi
  59. echo
  60. echo "Note: removing 'start' from launcher.bat to make Start/Stop button work properly"
  61. sed -i 's/^start\s\+\(Gen\)/\1/' launcher.bat
  62. ;;
  63. revert)
  64. bash "$patcher_dir/patch_revert.sh"
  65. ;;
  66. *)
  67. echo "unsupported action $action"
  68. helpexit
  69. ;;
  70. esac