From: bones_was_here Date: Wed, 19 Mar 2025 19:52:42 +0000 (+1000) Subject: rsync: mostly replace Windows batch script with POSIX shell script X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7b84afe6da493cab30d94b3933638961f19e568c;p=xonotic%2Fxonotic.git rsync: mostly replace Windows batch script with POSIX shell script This makes advanced features easier to implement because the language is more powerful and standardised, and allows most of the code to be shared by all platforms. The Linux script is better so this brings various improvements. Fixes minor inconsistencies in Windows file excludes. --- diff --git a/misc/tools/all/release.subr b/misc/tools/all/release.subr index 428b3bff..7fafe363 100644 --- a/misc/tools/all/release.subr +++ b/misc/tools/all/release.subr @@ -681,7 +681,7 @@ case "$cmd" in release-rsync) release_common # make sure everything we need is installed and updated - verbose "$d0"/misc/tools/msys2-linux.sh --schroot=sid rsync + verbose "$d0"/misc/tools/msys2-linux.sh --schroot=sid rsync dash targetroot="$PWD/Xonotic" verbose cd "$HOME/msys64" # see msys2-linux.sh verbose cp --parents \ @@ -693,6 +693,8 @@ case "$cmd" in usr/bin/msys-zstd-1.dll \ usr/bin/rsync.exe \ "$targetroot/misc/tools/rsync-updater/" + # msys2 sh.exe is currently bash + verbose cp usr/bin/dash.exe "$targetroot/misc/tools/rsync-updater/usr/bin/sh.exe" ;; release) release_common diff --git a/misc/tools/rsync-updater/update-to-autobuild.bat b/misc/tools/rsync-updater/update-to-autobuild.bat index 0c8491ae..1c7aeb97 100644 --- a/misc/tools/rsync-updater/update-to-autobuild.bat +++ b/misc/tools/rsync-updater/update-to-autobuild.bat @@ -1,116 +1,29 @@ @echo off setlocal -if "%1" == "did-copy" goto copied +if "%did_copy%" == "true" goto copied cd %~dp0 +:: Windows can't update .exe and .dll files while they're running, +:: it can update the .bat file but that can cause execution glitches. +:: Shell scripts can also glitch if updated while running +:: but can be protected, which update-to-autobuild.sh and rsync-ssl are. rmdir /s /q %TEMP%\xonotic-rsync-updater 2>NUL mkdir %TEMP%\xonotic-rsync-updater copy /b %~nx0 %TEMP%\xonotic-rsync-updater\ >NUL :: windows has no cp -r equivalent, this seems least-bad robocopy usr %TEMP%\xonotic-rsync-updater\usr /e >NUL -%TEMP%\xonotic-rsync-updater\%~n0 did-copy +set did_copy=true +%TEMP%\xonotic-rsync-updater\%~n0 %* :: can only get here if above batch file couldn't be created pause exit /b :copied +set PATH=%TEMP%\xonotic-rsync-updater\usr\bin;%PATH% +:: $PATH $PWD $TEMP and $TMP get automatic cygwin path conversion but $0 doesn't, +:: sourcing the main script and setting a custom $0 also works around broken symlink support. +sh -c ". ./update-to-autobuild.sh" ./%~n0.sh %* -set /p choice=This script will DELETE any custom files in the Xonotic folder. Do you want to continue [Y/N]? -if /i not "%choice%" == "Y" goto end - -set buildtype=release -if "%~n0" == "update-to-autobuild" set buildtype=autobuild - -set options=-Prtzil --delete-after --delete-excluded --stats - -if exist ..\..\..\.git goto xonoticdatagit -if exist Xonotic goto xonoticswitchtonormal -if exist Xonotic-high goto xonoticswitchtohigh -if exist ..\..\..\data goto xonoticdata -goto xonotic -:xonoticdatagit - echo NOTE: this is a git repository download. Using the regular update method. - ..\..\..\all update - goto end -:xonoticswitchtohigh - set PATH=misc\tools\rsync-updater;%PATH% - cd ..\..\.. - if exist misc\tools\rsync-updater\rsync.exe goto xonoticdatahighfuzzy - echo FATAL: rsync not in misc\tools\rsync-updater. This update script cannot be used. - goto end -:xonoticswitchtonormal - set PATH=misc\tools\rsync-updater;%PATH% - cd ..\..\.. - if exist misc\tools\rsync-updater\rsync.exe goto xonoticdatanormalfuzzy - echo FATAL: rsync not in misc\tools\rsync-updater. This update script cannot be used. - goto end -:xonoticdata - if exist ..\..\..\misc\tools\rsync-updater\rsync.exe goto xonoticdatarsync - echo FATAL: rsync not in misc\tools\rsync-updater. This update script cannot be used. - goto end -:xonoticdatarsync - set PATH=misc\tools\rsync-updater;%PATH% - cd ..\..\.. - if exist data\xonotic-rsync-data-high.pk3 goto xonoticdatahigh - if exist data\xonotic-*-data-high.pk3 goto xonoticdatahighfuzzy - if exist data\xonotic-rsync-data.pk3 goto xonoticdatanormal - if exist data\xonotic-*-data.pk3 goto xonoticdatanormalfuzzy - echo FATAL: unrecognized Xonotic build. This update script cannot be used. - goto end -:xonoticdatahigh - set package=Xonotic-high - goto endxonoticdata -:xonoticdatahighfuzzy - set package=Xonotic-high - set options=%options% -y - goto endxonoticdata -:xonoticdatanormal - set package=Xonotic - goto endxonoticdata -:xonoticdatanormalfuzzy - set package=Xonotic - set options=%options% -y - goto endxonoticdata -:endxonoticdata - set target=./ - goto endxonotic -:xonotic - set package=Xonotic - set target=Xonotic/ - goto endxonotic -:endxonotic -set url=beta.xonotic.org/%buildtype%-%package% - -set excludes= -if not "%XONOTIC_INCLUDE_ALL%" == "" goto endbit -set excludes=%excludes% --exclude=/xonotic-linux* -set excludes=%excludes% --exclude=/xonotic-osx-* -set excludes=%excludes% --exclude=/Xonotic*.app -set excludes=%excludes% --exclude=/gmqcc/gmqcc.linux* -set excludes=%excludes% --exclude=/gmqcc/gmqcc.osx - -if "%ProgramFiles(x86)%" == "" goto bit32 -:bit64 - if not "%XONOTIC_INCLUDE_32BIT%" == "" goto endbit - set excludes=%excludes% --exclude=/xonotic-x86.exe - set excludes=%excludes% --exclude=/xonotic-x86-dedicated.exe - set excludes=%excludes% --exclude=/gmqcc/gmqcc.exe - set excludes=%excludes% --exclude=/bin32 - set excludes=%excludes% --exclude=/*.dll - goto endbit -:bit32 - set excludes=%excludes% --exclude=/xonotic.exe - set excludes=%excludes% --exclude=/xonotic-dedicated.exe - set excludes=%excludes% --exclude=/gmqcc/gmqcc-x64.exe - set excludes=%excludes% --exclude=/bin64 - goto endbit -:endbit - -cd %target% -echo Updating %CD% from %url% ... -%TEMP%\xonotic-rsync-updater\usr\bin\rsync %options% %excludes% rsync://%url%/ %target% - -:end pause :: hack: delete running batch file without error by deleting after batch exit (goto) 2>NUL & rmdir /s /q %TEMP%\xonotic-rsync-updater diff --git a/misc/tools/rsync-updater/update-to-autobuild.sh b/misc/tools/rsync-updater/update-to-autobuild.sh index c48629fb..930aebab 100755 --- a/misc/tools/rsync-updater/update-to-autobuild.sh +++ b/misc/tools/rsync-updater/update-to-autobuild.sh @@ -30,7 +30,10 @@ case "${0##*/}" in ;; esac -options="-Prtzil --executability --delete-after --delete-excluded --stats" +options="-Prtzil --delete-after --delete-excluded --stats" +if [ "$OS" != "Windows_NT" ]; then + options="$options --executability" +fi package="Xonotic" target="../../.." @@ -67,7 +70,29 @@ fi url="beta.xonotic.org/$buildtype-$package" excludes= -if [ -z "$XONOTIC_INCLUDE_ALL" ]; then +if [ -n "$XONOTIC_INCLUDE_ALL" ]; then + : noot noot +elif [ "$OS" = "Windows_NT" ]; then + excludes="$excludes --exclude=/xonotic-linux*" + excludes="$excludes --exclude=/xonotic-osx-*" + excludes="$excludes --exclude=/Xonotic*.app" + excludes="$excludes --exclude=/gmqcc/gmqcc.linux*" + excludes="$excludes --exclude=/gmqcc/gmqcc.osx" + + if [ "$PROCESSOR_ARCHITECTURE" = AMD64 ]; then + if [ -z "$XONOTIC_INCLUDE_32BIT" ]; then + excludes="$excludes --exclude=/xonotic-x86.exe" + excludes="$excludes --exclude=/xonotic-x86-dedicated.exe" + excludes="$excludes --exclude=/xonotic-x86-wgl.exe" + excludes="$excludes --exclude=/bin32" + fi + else + excludes="$excludes --exclude=/xonotic.exe" + excludes="$excludes --exclude=/xonotic-dedicated.exe" + excludes="$excludes --exclude=/xonotic-wgl.exe" + excludes="$excludes --exclude=/bin64" + fi +else excludes="$excludes --exclude=/*.exe" excludes="$excludes --exclude=/bin32" excludes="$excludes --exclude=/*.dll" diff --git a/misc/tools/rsync-updater/update-to-release.bat b/misc/tools/rsync-updater/update-to-release.bat index 115a32db..1c7aeb97 100644 --- a/misc/tools/rsync-updater/update-to-release.bat +++ b/misc/tools/rsync-updater/update-to-release.bat @@ -1,116 +1,29 @@ @echo off setlocal -if "%1" == "did-copy" goto copied +if "%did_copy%" == "true" goto copied cd %~dp0 +:: Windows can't update .exe and .dll files while they're running, +:: it can update the .bat file but that can cause execution glitches. +:: Shell scripts can also glitch if updated while running +:: but can be protected, which update-to-autobuild.sh and rsync-ssl are. rmdir /s /q %TEMP%\xonotic-rsync-updater 2>NUL mkdir %TEMP%\xonotic-rsync-updater copy /b %~nx0 %TEMP%\xonotic-rsync-updater\ >NUL :: windows has no cp -r equivalent, this seems least-bad robocopy usr %TEMP%\xonotic-rsync-updater\usr /e >NUL -%TEMP%\xonotic-rsync-updater\%~n0 did-copy +set did_copy=true +%TEMP%\xonotic-rsync-updater\%~n0 %* :: can only get here if above batch file couldn't be created pause exit /b :copied +set PATH=%TEMP%\xonotic-rsync-updater\usr\bin;%PATH% +:: $PATH $PWD $TEMP and $TMP get automatic cygwin path conversion but $0 doesn't, +:: sourcing the main script and setting a custom $0 also works around broken symlink support. +sh -c ". ./update-to-autobuild.sh" ./%~n0.sh %* -set /p choice=This script will DELETE any custom files in the Xonotic folder. Do you want to continue [Y/N]? -if /i not "%choice%" == "Y" goto end - -set buildtype=release -if "%~n0" == "update-to-autobuild" set buildtype=autobuild - -set options=-Prtzil --delete-after --delete-excluded --stats - -if exist ..\..\..\.git goto xonoticdatagit -if exist ..\..\..\data goto xonoticdata -if exist Xonotic goto xonoticswitchtonormal -if exist Xonotic-high goto xonoticswitchtohigh -goto xonotic -:xonoticdatagit - echo NOTE: this is a git repository download. Using the regular update method. - ..\..\..\all update - goto end -:xonoticswitchtohigh - set PATH=misc\tools\rsync-updater;%PATH% - cd ..\..\.. - if exist misc\tools\rsync-updater\rsync.exe goto xonoticdatahighfuzzy - echo FATAL: rsync not in misc\tools\rsync-updater. This update script cannot be used. - goto end -:xonoticswitchtonormal - set PATH=misc\tools\rsync-updater;%PATH% - cd ..\..\.. - if exist misc\tools\rsync-updater\rsync.exe goto xonoticdatanormalfuzzy - echo FATAL: rsync not in misc\tools\rsync-updater. This update script cannot be used. - goto end -:xonoticdata - if exist ..\..\..\misc\tools\rsync-updater\rsync.exe goto xonoticdatarsync - echo FATAL: rsync not in misc\tools\rsync-updater. This update script cannot be used. - goto end -:xonoticdatarsync - set PATH=misc\tools\rsync-updater;%PATH% - cd ..\..\.. - if exist data\xonotic-rsync-data-high.pk3 goto xonoticdatahigh - if exist data\xonotic-*-data-high.pk3 goto xonoticdatahighfuzzy - if exist data\xonotic-rsync-data.pk3 goto xonoticdatanormal - if exist data\xonotic-*-data.pk3 goto xonoticdatanormalfuzzy - echo FATAL: unrecognized Xonotic build. This update script cannot be used. - goto end -:xonoticdatahigh - set package=Xonotic-high - goto endxonoticdata -:xonoticdatahighfuzzy - set package=Xonotic-high - set options=%options% -y - goto endxonoticdata -:xonoticdatanormal - set package=Xonotic - goto endxonoticdata -:xonoticdatanormalfuzzy - set package=Xonotic - set options=%options% -y - goto endxonoticdata -:endxonoticdata - set target=./ - goto endxonotic -:xonotic - set package=Xonotic - set target=Xonotic/ - goto endxonotic -:endxonotic -set url=beta.xonotic.org/%buildtype%-%package% - -set excludes= -if not "%XONOTIC_INCLUDE_ALL%" == "" goto endbit -set excludes=%excludes% --exclude=/xonotic-linux* -set excludes=%excludes% --exclude=/xonotic-osx-* -set excludes=%excludes% --exclude=/Xonotic*.app -set excludes=%excludes% --exclude=/gmqcc/gmqcc.linux* -set excludes=%excludes% --exclude=/gmqcc/gmqcc.osx - -if "%ProgramFiles(x86)%" == "" goto bit32 -:bit64 - if not "%XONOTIC_INCLUDE_32BIT%" == "" goto endbit - set excludes=%excludes% --exclude=/xonotic-x86.exe - set excludes=%excludes% --exclude=/xonotic-x86-dedicated.exe - set excludes=%excludes% --exclude=/gmqcc/gmqcc.exe - set excludes=%excludes% --exclude=/bin32 - set excludes=%excludes% --exclude=/*.dll - goto endbit -:bit32 - set excludes=%excludes% --exclude=/xonotic.exe - set excludes=%excludes% --exclude=/xonotic-dedicated.exe - set excludes=%excludes% --exclude=/gmqcc/gmqcc-x64.exe - set excludes=%excludes% --exclude=/bin64 - goto endbit -:endbit - -cd %target% -echo Updating %CD% from %url% ... -%TEMP%\xonotic-rsync-updater\usr\bin\rsync %options% %excludes% rsync://%url%/ %target% - -:end pause :: hack: delete running batch file without error by deleting after batch exit (goto) 2>NUL & rmdir /s /q %TEMP%\xonotic-rsync-updater