From 17cf2e537740c2b573c4de2b75dae566eceb49c8 Mon Sep 17 00:00:00 2001 From: ahadda5 Date: Mon, 2 Aug 2021 20:09:09 +0400 Subject: [PATCH] Fixing .bat file issues (#9266) * replacing [] with "" for ifs using !! vs %% for var with delayed expansion Check first for 404 then download. * remove the goto after if are fixed Co-authored-by: Raul Jordan Co-authored-by: Nishant Das --- prysm.bat | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/prysm.bat b/prysm.bat index 06fd6640c..f35995cf3 100644 --- a/prysm.bat +++ b/prysm.bat @@ -62,63 +62,62 @@ set BEACON_CHAIN_REAL=%wrapper_dir%\beacon-chain-%prysm_version%-%system%-%arch% set VALIDATOR_REAL=%wrapper_dir%\validator-%prysm_version%-%system%-%arch% set CLIENT_STATS_REAL=%wrapper_dir%\client-stats-%prysm_version%-%system%-%arch% -if [%1]==[beacon-chain] ( - if exist %BEACON_CHAIN_REAL% ( +if "%~1"=="beacon-chain" ( + if exist "%BEACON_CHAIN_REAL%" ( echo Beacon chain is up to date. ) else ( echo Downloading beacon chain %prysm_version% to %BEACON_CHAIN_REAL% %reason% - for /f "delims=" %%i in ('curl --silent -w "%%{http_code}" -L https://prysmaticlabs.com/releases/beacon-chain-%prysm_version%-%system%-%arch% -o %BEACON_CHAIN_REAL%') do set http=%%i - if %http%==400 ( + for /f "delims=" %%i in ('curl --silent -o nul -w "%%{http_code}" https://prysmaticlabs.com/releases/beacon-chain-%prysm_version%-%system%-%arch% ') do set "http=%%i" && echo %%i + if "!http!"=="404" ( echo No prysm beacon chain found for %prysm_version% - exit \b 1 - ) + exit /b 1 + ) + curl -L https://prysmaticlabs.com/releases/beacon-chain-%prysm_version%-%system%-%arch% -o %BEACON_CHAIN_REAL% curl --silent -L https://prysmaticlabs.com/releases/beacon-chain-%prysm_version%-%system%-%arch%.sha256 -o %wrapper_dir%\beacon-chain-%prysm_version%-%system%-%arch%.sha256 curl --silent -L https://prysmaticlabs.com/releases/beacon-chain-%prysm_version%-%system%-%arch%.sig -o %wrapper_dir%\beacon-chain-%prysm_version%-%system%-%arch%.sig ) - goto startprocess ) -if [%1]==[validator] ( - if exist %VALIDATOR_REAL% ( +if "%~1"=="validator" ( + if exist "%VALIDATOR_REAL%" ( echo Validator is up to date. ) else ( echo Downloading validator %prysm_version% to %VALIDATOR_REAL% %reason% - for /f "delims=" %%i in ('curl --silent -w "%%{http_code}" -L https://prysmaticlabs.com/releases/validator-%prysm_version%-%system%-%arch% -o %VALIDATOR_REAL%') do set http=%%i - if %http%==400 ( + for /f "delims=" %%i in ('curl --silent -o nul -w "%%{http_code}" https://prysmaticlabs.com/releases/validator-%prysm_version%-%system%-%arch% ') do set "http=%%i" && echo %%i + if "!http!"=="404" ( echo No prysm validator found for %prysm_version% - exit \b 1 + exit /b 1 ) + curl -L https://prysmaticlabs.com/releases/validator-%prysm_version%-%system%-%arch% -o %VALIDATOR_REAL% curl --silent -L https://prysmaticlabs.com/releases/validator-%prysm_version%-%system%-%arch%.sha256 -o %wrapper_dir%\validator-%prysm_version%-%system%-%arch%.sha256 curl --silent -L https://prysmaticlabs.com/releases/validator-%prysm_version%-%system%-%arch%.sig -o %wrapper_dir%\validator-%prysm_version%-%system%-%arch%.sig ) - goto startprocess ) -if [%1]==[client-stats] ( +if "%~1"=="client-stats" ( if exist %CLIENT_STATS_REAL% ( echo Client-stats is up to date. ) else ( echo Downloading client-stats %prysm_version% to %CLIENT_STATS_REAL% %reason% - for /f "delims=" %%i in ('curl --silent -w "%%{http_code}" -L https://prysmaticlabs.com/releases/client-stats-%prysm_version%-%system%-%arch% -o %CLIENT_STATS_REAL%') do set http=%%i - if %http%==400 ( + for /f "delims=" %%i in ('curl --silent -o nul -w "%%{http_code}" https://prysmaticlabs.com/releases/client-stats-%prysm_version%-%system%-%arch% ') do set "http=%%i" && echo %%i + if "!http!"=="404" ( echo No prysm client stats found for %prysm_version% - exit \b 1 + exit /b 1 ) + curl -L https://prysmaticlabs.com/releases/client-stats-%prysm_version%-%system%-%arch% -o %CLIENT_STATS_REAL% curl --silent -L https://prysmaticlabs.com/releases/client-stats-%prysm_version%-%system%-%arch%.sha256 -o %wrapper_dir%\client-stats-%prysm_version%-%system%-%arch%.sha256 curl --silent -L https://prysmaticlabs.com/releases/client-stats-%prysm_version%-%system%-%arch%.sig -o %wrapper_dir%\client-stats-%prysm_version%-%system%-%arch%.sig ) - goto startprocess ) -if [%1]==[slasher] ( +if "%~1"=="slasher" ( echo The slasher binary is no longer available. Please use the --slasher flag with your beacon node. See: https://docs.prylabs.network/docs/prysm-usage/slasher/ exit /b 1 ) -:startprocess -if [%1]==[beacon-chain] ( set process=%BEACON_CHAIN_REAL%) -if [%1]==[validator] ( set process=%VALIDATOR_REAL%) -if [%1]==[client-stats] ( set process=%CLIENT_STATS_REAL%) +if "%~1"=="beacon-chain" ( set process=%BEACON_CHAIN_REAL%) +if "%~1"=="validator" ( set process=%VALIDATOR_REAL%) +if "%~1"=="client-stats" ( set process=%CLIENT_STATS_REAL%) REM GPG not natively available on Windows, external module required echo WARN GPG verification is not natively available on Windows. @@ -129,9 +128,9 @@ for /f "delims=" %%A in ('certutil -hashfile %process% SHA256 ^| find /v "hash"' set SHA256Hash=%%A ) set /p ExpectedSHA256=<%process%.sha256 -if [%ExpectedSHA256:~0,64%]==[%SHA256Hash%] ( +if "%ExpectedSHA256:~0,64%"=="%SHA256Hash%" ( echo SHA256 Hash Match! -) else if [%PRYSM_ALLOW_UNVERIFIED_BINARIES%]==[1] ( +) else if "%PRYSM_ALLOW_UNVERIFIED_BINARIES%"=="1" ( echo WARNING Failed to verify Prysm binary. echo Detected PRYSM_ALLOW_UNVERIFIED_BINARIES=1 echo Proceeding...