123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #!/bin/bash
- set -eu -o pipefail
- helpexit() {
- echo "$0 version action"
- exit 1
- }
- test -n "${1:-}" -a -n "${2:-}" || helpexit
- version=${1//.}
- action=$2
- GIT_URL="https://notabug.org/Krock/dawn.git"
- PATCHER_HOME="$HOME/.local/share/paimon-launcher/dawn"
- CACHE_TIME=5 # don't update patcher if it was updated within last 5 minutes
- TIMESTAMP_FILE="$PATCHER_HOME.timestamp"
- scripts_path=`cd "\`dirname \"$0\"\`"; echo "$PWD"`
- patcher_dir="$PATCHER_HOME/$version"
- patchsh="$patcher_dir/patch.sh"
- # clone or update patcher dir
- if [ ! -d "$PATCHER_HOME/.git" ]; then
- echo "Cloning patcher..."
- mkdir -p "$(dirname $PATCHER_HOME)"
- git clone $GIT_URL "$PATCHER_HOME"
- touch "$TIMESTAMP_FILE"
- else
- if [ ! -e "$TIMESTAMP_FILE" -o -n "`find \"$TIMESTAMP_FILE\" -mmin +$CACHE_TIME`" ]; then
- echo "Updating patcher..."
- git -C "$PATCHER_HOME" pull
- touch "$TIMESTAMP_FILE"
- fi
- fi
- get_sudo_content() {
- echo 'set -eu -o pipefail'
- echo "cd '"""$PWD"""'"
- sed "1,/DO NOT REMOVE START/!d" "$patchsh" | sed "s:^DIR=.*$:DIR='$patcher_dir':"
- sed '/# START OF SUDO DANGER ZONE/,/# END OF SUDO DANGER ZONE/!d' "$patchsh"
- }
- # unfortunately pkexec doesn't work with pipes like sudo, so we have no chance to execute script as is
- # we cut out the sudo part and executing it to test if superuser rights needed (exit code 42 then)
- # if so, we do the same part again with su rights provided by pkexec (or not)
- # after that we can start the script itself
- case $action in
- check)
- echo "SERVERS_BEGIN"
- sed '/servers=/,/EOF/!d;/EOF/d' "$patchsh"
- echo "SERVERS_END"
- # make script exit with code 42 in case it wants sudo
- check_script=`get_sudo_content | sed 's/ sudo / exit 42 # /g'`
- bash -c "$check_script"
- ;;
- block)
- block_script=`get_sudo_content`
- # User already accepted, so reply 'y'
- QUIET=1 "$scripts_path/sudo-wrapper" bash -c "$block_script" <<< 'y'
- ;;
- patch*)
- # User already accepted, so reply 'y'
- echo "Starting $patchsh"
- if [ "$action" = "patch-untested" ]
- then
- sed '0,/exit 1/{/exit 1/d}' "$patchsh" >"$patchsh.tmp"
- bash "$patchsh.tmp" <<< 'y'
- rm "$patchsh.tmp"
- else
- bash "$patchsh" <<< 'y'
- fi
- if [ -f "$patcher_dir/patch_anti_logincrash.sh" ]; then
- # User already accepted, so reply 'y'
- bash "$patcher_dir/patch_anti_logincrash.sh" <<< 'y'
- fi
- echo
- echo "Note: removing 'start' from launcher.bat to make Start/Stop button work properly"
- sed -i 's/^start\s\+\(Gen\)/\1/' launcher.bat
- ;;
- revert)
- bash "$patcher_dir/patch_revert.sh"
- ;;
- *)
- echo "unsupported action $action"
- helpexit
- ;;
- esac
|