From 6a6129a52509ae5dfd030fc06756d83db0c52f0d Mon Sep 17 00:00:00 2001 From: bones_was_here Date: Wed, 26 Feb 2025 11:56:50 +1000 Subject: [PATCH] rsync: improve status messages, fix target selection Fixes printing the wrong message "release" when updating from an autobuild zip. That code can't distinguish between rsync and release reliably (because an autobuild zip has the release-style pk3 names) and doesn't need to. Fixes the "secret trick" potentially clobbering the filesystem: downloading update-to-autobuild.sh separately to /home/user/Downloads/ and running from there it downloaded Xonotic to ~/Downloads/Xonotic/, but if run again it detected that new Xonotic/ directory and set the rsync target to ../../.. (ie /). That fallback target is no longer supported as it's a bit odd to download a complete copy via the updater, but it can still be done by creating the script parent directories. Moves the main "Do you want to continue" after other messages so the user is better informed about what they're confirming. --- misc/tools/rsync-updater/README.txt | 6 +- .../rsync-updater/update-to-autobuild.sh | 65 +++++++++---------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/misc/tools/rsync-updater/README.txt b/misc/tools/rsync-updater/README.txt index 0bf88feb..03ffa311 100644 --- a/misc/tools/rsync-updater/README.txt +++ b/misc/tools/rsync-updater/README.txt @@ -19,6 +19,6 @@ On Linux or Mac the "~/.xonotic/data/" directory Secret trick: if you create any file/directory named "Xonotic-high" in this directory before running the updater, this script will -download Xonotic with uncompressed textures. Otherwise it will -download regular Xonotic. To change from Xonotic-high to regular -create any file/directory named "Xonotic" and run the script again. +download Xonotic with jpeg textures. Otherwise it will +download regular Xonotic. To change from Xonotic-high (jpeg) to regular +create any file/directory named "Xonotic" in this directory and run the script again. diff --git a/misc/tools/rsync-updater/update-to-autobuild.sh b/misc/tools/rsync-updater/update-to-autobuild.sh index 1a6f19f8..d75df770 100755 --- a/misc/tools/rsync-updater/update-to-autobuild.sh +++ b/misc/tools/rsync-updater/update-to-autobuild.sh @@ -5,22 +5,10 @@ cd "${0%/*}" || exit 1 [ -t 2 ] && [ -t 1 ] && [ -t 0 ] && interactive=true || interactive=false if ! command -v rsync > /dev/null; then - echo >&2 "FATAL: rsync not found, please install the rsync package" + printf >&2 "\033[1;31mFATAL: rsync not found, please install the rsync package!\033[m\n" exit 1 fi -if [ "$1" = "-y" ] || [ "$1" = "--yes" ]; then - choice=y -elif [ $interactive = false ]; then - printf >&2 "\033[1;31mFATAL: non-interactive mode requires the \033[1;37m--yes\033[1;31m argument to acknowledge that this script will DELETE any custom files in the Xonotic directory.\033[m\n" - exit 1 -fi -until [ "$choice" = y ] || [ "$choice" = Y ]; do - printf "This script will DELETE any custom files in the Xonotic folder. Do you want to continue [Y/N]? " - read -r choice - [ "$choice" = n ] || [ "$choice" = N ] && exit 1 -done - case "${0##*/}" in update-to-autobuild.sh) buildtype=autobuild @@ -45,30 +33,27 @@ fi package="Xonotic" target="../../.." if [ -d "../../../.git" ]; then - echo >&2 "NOTE: this is a git repository download. Using the regular update method." + printf >&2 "\033[1;33mNOTE: this is a git repository. Using the git update method.\033[m\n" exec ../../../all update -elif [ -e "Xonotic" ]; then - echo "found manually created 'Xonotic' file" -elif [ -e "Xonotic-high" ]; then - echo "found manually created 'Xonotic-high' file" - package="Xonotic-high" -elif [ -d "../../../data" ]; then - if [ -f ../../../data/xonotic-rsync-data-high.pk3 ]; then - echo "found rsync high data files" - package="Xonotic-high" - elif [ -f ../../../data/xonotic-*-data-high.pk3 ]; then - echo "found release high data files" +elif PWD="${PWD%/}" && [ "$PWD" != "${PWD%/misc/tools/rsync-updater}" ]; then + if [ -f ../../../data/xonotic-*-data-high.pk3 ]; then + echo "Found Xonotic-high data files" package="Xonotic-high" - elif [ -f ../../../data/xonotic-rsync-data.pk3 ]; then - echo "found Xonotic rsync data files" elif [ -f ../../../data/xonotic-*-data.pk3 ]; then - echo "found Xonotic release data files" + echo "Found Xonotic data files" else - echo >&2 "FATAL: unrecognized Xonotic build. This update script cannot be used." - exit 1 + printf "\033[1;31mNOTE: found misc/tools/rsync-updater parent directories but no data files!\033[m\n" fi else - target="Xonotic/" + printf >&2 "\033[1;31mFATAL: unrecognized Xonotic build. This update script cannot be used.\033[m\n" + exit 1 +fi +if [ -e "Xonotic" ]; then + printf "\033[1;35mFound manually created 'Xonotic' package override\033[m\n" + package="Xonotic" +elif [ -e "Xonotic-high" ]; then + printf "\033[1;35mFound manually created 'Xonotic-high' package override\033[m\n" + package="Xonotic-high" fi url="beta.xonotic.org/$buildtype-$package" @@ -110,11 +95,11 @@ else excludes="$excludes --exclude=/xonotic-osx-*" ;; *) - printf >&2 "\e[1;31m" + printf >&2 "\033[1;31m" printf >&2 "WARNING: Could not detect architecture\n" printf >&2 "WARNING: Xonotic does NOT provide pre-built %s executables\n" "$(uname):$(uname -m)" printf >&2 "WARNING: Please run make. More info is available at\n" - printf >&2 "WARNING: \e[1;36mhttps://gitlab.com/xonotic/xonotic/-/wikis/Compiling\e[m\n" + printf >&2 "WARNING: \033[1;36mhttps://gitlab.com/xonotic/xonotic/-/wikis/Compiling\033[m\n" excludes="$excludes --exclude=/Xonotic*.app" excludes="$excludes --exclude=/xonotic-osx-*" excludes="$excludes --exclude=/xonotic-linux64-*" @@ -124,5 +109,19 @@ fi resolvedtarget=$(cd $target && [ "${PWD#$HOME}" != "$PWD" ] && printf "~${PWD#$HOME}" || printf "$PWD") printf "Updating \033[1;34m$resolvedtarget\033[m from \033[0;36m$url \033[m...\n" + +targetname=$(cd "$target" && printf "${PWD##*/}") +if [ "$1" = "-y" ] || [ "$1" = "--yes" ]; then + choice=y +elif [ $interactive = false ]; then + printf >&2 "\033[1;31mFATAL: non-interactive mode requires the \033[1;37m--yes\033[1;31m argument to acknowledge that this will DELETE any custom files in the \"$targetname\" directory.\033[m\n" + exit 1 +fi +until [ "$choice" = y ] || [ "$choice" = Y ]; do + printf "\033[1mThis will DELETE any custom files in the \"$targetname\" folder, continue? [Y/N] \033[m" + read -r choice + [ "$choice" = n ] || [ "$choice" = N ] && exit 1 +done + # exec ensures this script stops before it's updated to prevent potential glitches exec rsync $options $excludes "rsync://$url/" "$target" -- 2.39.5