@echo off cd /d %~dp0 setlocal EnableDelayedExpansion rem @setlocal enableextensions enabledelayedexpansion rem NET SESSION >nul 2>&1 rem IF %ERRORLEVEL% NEQ 0 ( rem echo "Please run update.bat as administrator" rem goto :error_download rem ) set service_name= set download_params= if exist environment.bat call environment.bat for /F "tokens=1* delims==" %%A in (data\config.ini) do ( if "%%A"=="update.url" set updates_url=%%B ) echo Using update url "!updates_url!" if "%~n0"=="update" ( echo Downloading new update script from "!updates_url!/update.bat" if exist update_current.bat del update_current.bat for /F "tokens=*" %%z in ('curl -w "%%{http_code}" !download_params! !updates_url!/update.bat --show-error --output update_current.bat') do SET http_code=%%z if errorlevel 1 ( echo "Cannot download update script. curl return code is %ERRORLEVEL%" goto :error_download ) :: code 000 returned when loading updated from a shared folder if "!http_code!"=="000" set http_code=200 if not "!http_code!"=="200" ( echo "Cannot download update script. Response code is !http_code!" goto :error_download ) if not exist update_current.bat ( echo Cannot download update script. Expected file update_current.bat, but nothing found. goto :error_download ) pause start update_current.bat exit /B ) echo Downloading current release info from "!updates_url!/version.txt" if exist version.new del version.new for /F "tokens=*" %%i in ('curl -w "%%{http_code}" !download_params! !updates_url!/version.txt --show-error --output version.new') do set http_code=%%i if errorlevel 1 ( echo "Cannot download current release info. curl return code is !ERRORLEVEL!" goto :error_download ) :: code 000 returned when loading updated from a shared folder if "!http_code!"=="000" set http_code=200 if not "!http_code!"=="200" ( echo "Cannot download current release version info. Response code is !http_code!" goto :error_download ) if not exist version.new ( echo Cannot download update version. Expected file version.new, but nothing found. goto :error_download ) for /f "skip=2 tokens=1,2 delims==" %%a in (version.new) do ( if "X%%a"=="Xversion.info" set version=%%b if "X%%a"=="Xproduct.name" set product_name=%%b ) IF "!version!"=="" ( echo "Cannot read new version information" goto :error_download ) IF "!product_name!"=="" ( echo "Cannot read product name" goto :error_download ) for /f "skip=2 tokens=1,2 delims==" %%a in (version.txt) do ( if "X%%a"=="Xversion.info" set current_version=%%b ) if "%current_version%"=="" ( echo "Cannot read current version number" goto :error_download ) if not "x!current_version!" == "x!version!" goto :s_files_are_different echo Current version is up to date goto :end_ok :s_files_are_different echo. echo Y Update DBMaster from !current_version! to !version!? echo C Cancel echo. choice /c:CY /M "Choose an option" if errorlevel 2 goto update copy /Y %~nx0 update.bat > nul goto :end_skip_update :update if not "a%service_name%"=="a" net stop %service_name% if exist dbmaster.lock ( ren dbmaster.lock tmp > nul if errorlevel 1 ( echo DBMaster application is running. Please close browser window and application before updating goto :end_error ) del tmp ) if "%PROCESSOR_ARCHITECTURE%"=="x86" ( set architecture=x86 ) else ( set architecture=x64 ) if exist jre ( rem set jre=-jre set jre= ) else ( set jre= ) set download_src="!updates_url!/%product_name%-!version!-windows-%architecture%%jre%.zip" del /q %product_name%*.zip (remove previous downloads) echo Downloading newer version from %download_src% for /F "tokens=*" %%x in ('curl -w "%%{http_code}" !download_params! %download_src% --output %product_name%-!version!.zip') do SET http_code=%%x if errorlevel 1 ( echo "Cannot download installation. curl return code is %ERRORLEVEL%" goto :error_download ) :: code 000 returned when loading updated from a shared folder if "!http_code!"=="000" set http_code=200 if not "!http_code!"=="200" ( echo Cannot download installation. Response code is !http_code! for request %download_src% goto :error_download ) if not exist %product_name%-!version!.zip ( echo Cannot download installation. Expected file %product_name%-!version!-windows-%architecture%%jre%.zip, but nothing found. goto :error_download ) setlocal DisableDelayedExpansion mkdir backups 7z.exe a -r backups\data-backup-%current_version%.zip data move *.war backups if exist webapp ( move webapp backups\webapp-%current_version% if errorlevel 1 ( echo "Cannot move existing web application files" goto :error_download ) ) if exist jre ( move jre backups\jre-%current_version% if errorlevel 1 ( echo "Cannot move existing jre files" goto :error_download ) ) :: delete shared libs for future updates del /q "lib\*slf4j*.jar" del /q "lib\*logback*.jar" del /q "lib\*jetty*.jar" del /q "lib\*servlet-api*.jar" del /q "services\*slf4j*.jar" del /q "services\*felix*.jar" del /q "shared\*bundlerepository*.jar" 7z.exe x -y %product_name%-%version%.zip -x!7z.exe -x!7z.dll -x!plugins -x!update.bat 7z.exe x -y %product_name%-%version%.zip -i!plugins/dbmaster-api-*.jar if exist dbmaster.log move dbmaster.log backups\dbmaster-%version%.log if exist wrapper.log.0 move wrapper.log.0 backups\wrapper-%version%.log if not "a%service_name%"=="a" net start %service_name% copy /Y %~nx0 update.bat > nul echo DBMaster upgrade was completed succesfully goto :end_ok :error_download :end_error :end_ok pause :end_skip_update @echo on if exist version.new del version.new if exist update_current.bat del update_current.bat