diff --git a/RESTIC_SOURCE_FILES/legacy_restic_builder.cmd b/RESTIC_SOURCE_FILES/legacy_restic_builder.cmd index 36bfc18..f0d8cf2 100644 --- a/RESTIC_SOURCE_FILES/legacy_restic_builder.cmd +++ b/RESTIC_SOURCE_FILES/legacy_restic_builder.cmd @@ -1,41 +1,90 @@ @echo off -:: Blatantly copied from https://github.com/restic/restic/issues/4636#issuecomment-1896455557 +:: Blatantly copied from https://gist.github.com/DRON-666/6e29eb6a8635fae9ab822782f34d8fd6 +:: with some mods to specify restic versions and produce both 32 and 64 bit executables SET RESTIC_VERSION=0.18.0 +SET GO_BINARIES_VERSION=1.21.3 +SET GO23_VERSION=1.23.8 +SET GO24_VERSION=1.24.2 + +SET LOG_FILE=%~n0.log +SET BUILD_DIR=%~dp0BUILD +IF NOT EXIST "%BUILD_DIR%" MKDIR "%BUILD_DIR%" || GOTO ERROR +PUSHD BUILD set RESTIC_URL=https://github.com/restic/restic/releases/download/v%RESTIC_VERSION%/restic-%RESTIC_VERSION%.tar.gz -set GO_BIN_URL=https://go.dev/dl/go1.21.3.windows-amd64.zip -set GO_SRC_URL=https://go.dev/dl/go1.21.6.src.tar.gz -set BAD_COMMIT_URL=https://github.com/golang/go/commit/9e43850a3298a9b8b1162ba0033d4c53f8637571.diff -set BUSYBOX_URL=https://frippery.org/files/busybox/busybox64.exe -set BUSYBOX="%~dp0busybox64.exe" -if not exist %BUSYBOX% powershell -Command (New-Object System.Net.WebClient^).DownloadFile('"%BUSYBOX_URL%"','"%BUSYBOX%"'^) -if not exist go1.*.windows-amd64.zip (%BUSYBOX% wget %GO_BIN_URL% || GOTO ERROR) -if not exist go (%BUSYBOX% unzip -q go1.*.windows-amd64.zip || GOTO ERROR) -if not exist go1.*.src.tar.gz (%BUSYBOX% wget %GO_SRC_URL% || GOTO ERROR) -if not exist src (md src && %BUSYBOX% tar x -z --strip-components 1 -C src -f go1.*.src.tar.gz || GOTO ERROR) -pushd src -if not exist *.diff (%BUSYBOX% wget %BAD_COMMIT_URL% && %BUSYBOX% patch -p 1 -R -i *.diff || GOTO ERROR) -pushd src -if not exist ..\bin\go.exe (set GOROOT_BOOTSTRAP=%~dp0go&& call make.bat || GOTO ERROR) -popd && popd -if not exist restic-%RESTIC_VERSION%.tar.gz (%BUSYBOX% wget %RESTIC_URL% || GOTO ERROR) -if not exist restic-%RESTIC_VERSION% (md restic-%RESTIC_VERSION% && %BUSYBOX% tar x -z --strip-components 1 -C restic-%RESTIC_VERSION% -f restic-%RESTIC_VERSION%.tar.gz || GOTO ERROR) -set GOARCH=amd64 -pushd restic-%RESTIC_VERSION% && set path=%~dp0\src\bin&& go.exe run build.go && move /y restic.exe ../restic_%RESTIC_VERSION%_windows_legacy_%GOARCH%.exe && popd -set GOARCH=386 -pushd restic-%RESTIC_VERSION% && set path=%~dp0\src\bin&& go.exe run build.go && move /y restic.exe ../restic_%RESTIC_VERSION%_windows_legacy_%GOARCH%.exe && popd -GOTO END +set GO21_BIN_URL=https://go.dev/dl/go%GO_BINARIES_VERSION%.windows-amd64.zip +set GO23_SRC_URL=https://go.dev/dl/go%GO23_VERSION%.src.tar.gz +set GO24_SRC_URL=https://go.dev/dl/go%GO24_VERSION%.src.tar.gz +set PATCH_URL=https://gist.github.com/DRON-666/6e29eb6a8635fae9ab822782f34d8fd6/raw/win7sup.diff +set BUSYBOX_URL=https://web.archive.org/web/20250314144220id_/https://frippery.org/files/busybox/busybox64.exe +set BUSYBOX="%BUILD_DIR%\busybox64.exe" +set GOTOOLCHAIN=local + +call:Log "Running legacy restic builder" + +call:Log "Fetching busybox" +if not exist %BUSYBOX% (powershell -Command (New-Object System.Net.WebClient^).DownloadFile('"%BUSYBOX_URL%"','%BUSYBOX%'^) || GOTO ERROR) +call:Log "Fetching GO %GO_BINARIES_VERSION% binaries which are Window 7 compatible" +call:process %GO21_BIN_URL% %BUILD_DIR%\go +call:Log "Building Go %GO23_VERSION% with Windows 7 support patch" +call:process %GO23_SRC_URL% %BUILD_DIR%\go23 %PATCH_URL% %BUILD_DIR%\go +call:Log "Building Go %GO24_VERSION% with Windows 7 support patch" +call:process %GO24_SRC_URL% %BUILD_DIR%\go24 %PATCH_URL% %BUILD_DIR%\go23 +call:Log "Downloading restic %RESTIC_VERSION% source code" +call:process %RESTIC_URL% restic-%RESTIC_VERSION% + +call:build_restic 386 +call:build_restic amd64 +goto END + +:GetTime +:: US Date /T returns Day MM/DD/YYYY whereas other languges may DD/MM/YYYY, Try to catch both +FOR /F "tokens=1,2,3,4 delims=/" %%a IN ('Date /T') DO ( +IF "%%d"=="" set now_date=%%a-%%b-%%c +IF NOT "%%d"=="" set now_date=%%a-%%b-%%c-%%d +) +set now_time=%TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2% +set start_date=%now_date%-%TIME:~0,2%_%TIME:~3,2%_%TIME:~6,2% +GOTO:EOF + +:Log +call:GetTime +echo %now_date% - %now_time% %~1 >> "%LOG_FILE%" +IF "%DEBUG%"=="yes" echo %~1 +GOTO:EOF + +:process +:: Download and extract archives +if not exist %~nx1 (%BUSYBOX% wget %~1 || GOTO ERROR) +if not exist %~2 if /I "%~x1"==".zip" (%BUSYBOX% unzip -q %~nx1 || GOTO ERROR) else (md %~2 && %BUSYBOX% tar x -z --strip-components 1 -C %~2 -f %~nx1 || GOTO ERROR) +if "%~3"=="" goto :EOF +:: Patch go sources +if not exist %~nx3 (%BUSYBOX% wget %~3 || GOTO ERROR) +if not exist %~2\patched (pushd %~2 && %BUSYBOX% patch -p 0 -i "%BUILD_DIR%\%~nx3" && %BUSYBOX% sed -E -i "s/^go1.+[0-9]$/\0-win7sup/" VERSION && md patched && popd || GOTO ERROR) +:: Build go from sources - Don't put a space between '%4' and '&&' or else it will be interpreted as fullpath +if not exist %~2\bin\go.exe (pushd %~2\src && set GOROOT_BOOTSTRAP=%4&& call make.bat && popd || GOTO ERROR) +GOTO:EOF + +:build_restic +if NOT "%~1"=="" SET GOARCH=%~1 +call:Log "Building restic %RESTIC_VERSION% %GOARCH% with Windows 7 Support" +:: Setting path without previous paths prevents further runs and calling binaries like powershell +set PATH=%BUILD_DIR%\go24\bin;%PATH% +if not exist restic_%RESTIC_VERSION%_windows_legacy_%GOARCH%.exe (PUSHD %BUILD_DIR%\restic-%RESTIC_VERSION% && go.exe run build.go && move /y restic.exe ../restic_%RESTIC_VERSION%_windows_legacy_%GOARCH%.exe && popd || GOTO ERROR) +restic_%RESTIC_VERSION%_windows_legacy_%GOARCH%.exe version +GOTO:EOF :ERROR -echo Build failure +call:Log "Build failure" GOTO EXIT :END -echo Build success +call:Log "Build success" GOTO EXIT :EXIT +POPD ::exit /b 1 \ No newline at end of file