setlocal EnableDelayedExpansion
cd /d %~dp0
rem **************** (0) up to admin
PUSHD %~DP0 & cd /d "%~dp0"
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :target","","runas",1)(window.close)&goto :eof
:target
rem **************** (1) get install_dir
for /f "tokens=3" %%i in ('reg query " HKEY_CLASSES_ROOT\meshview" /v "install_dir" ') do (
set install_dir=%%i
)
echo %install_dir%
echo %install_dir%\meshview
rem **************** (2) read config get old date ; read application read new date
CALL :readconfig ./application.yml version myversion
echo "now is %myversion%"
set newversion=%myversion%
CALL :readconfig %install_dir%/meshview/config/application.yml version myversion
echo "now is %myversion%"
set oldversion=%myversion%
rem **************** (3) update mysql
set olddate=%oldversion:~-8%
set newdate=%newversion:~-8%
echo %olddate%
echo %newdate%
call :sqlhandle %olddate% %newdate%
%install_dir%\mysql-5.7.27-winx64\bin\mysql.exe -uroot -p123456 -s -f mesh < ./updatesql.txt 2 >> update.log
rem ****************(4) stop app; update app and static html ;
taskkill /f /im javaw.exe
xcopy /Y app\mesh-nmp.jar %install_dir%\meshview\mesh-nmp.jar
xcopy nginx\dist\* %install_dir%\meshview\static\ /s/e/i/y
pause
rem ****************(5) refresh config start app
call ./updateContent.bat %install_dir%\meshview\config\application.yml %oldversion% %newversion%
taskkill /f /im javaw.exe
@echo on
cd /d %install_dir%\meshview
echo %install_dir%\meshview
start "mesh-view" javaw -jar "./mesh-nmp.jar"
rem ============================+++readfile==============================
:readconfig
@echo off
for /f "tokens=1,2 delims=:" %%a IN ( %1 ) Do (
rem echo %%a
set tt=%%a
rem echo !tt!
CALL:intercept_all tt
if !tt!==%2 ( echo %%a & set %3=%%b && echo !%3! )
)
goto:eof
:intercept_all
set "str= ab c&>! "
setlocal
set "str=!%1%!"
set "str=%str: =%"
(endlocal
set "%1=%str%"
)
goto:eof
rem ============================readfile+++==============================
rem ============================+++sqlhandler==============================
:sqlhandle
@echo off
for /L %%a in (%1 1 %2) do (
rem echo %%a
if exist update/%%a (
echo %%a is a dictory
for /r %%i in ( .\update\%%a\*.sql ) do (
echo %%i
type %%i >> updatesql.txt
)
) else (
echo ./update/%%a is not exists
)
)
goto:eof
rem ============================sqlhandler+++==============================
pause
读文件及组合出增量文件的函数如下。
注意区分 call *.bat function 是可以回来 的
goto function
./*.bat 都是回不到本脚本文件环境的。