From 4a01471334ff46f602555872744b1262da836f5e Mon Sep 17 00:00:00 2001 From: xinsheng Ren <285808407@qq.com> Date: Thu, 9 Feb 2023 16:39:51 +0800 Subject: [PATCH] make_install.bat: (#19658) (#19876) 1. copy files failed if svc-deleting is still outstanding 2. unnecessary duplication of C:\TDengine in %PATH% Co-authored-by: freemine --- packaging/tools/make_install.bat | 57 +++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/packaging/tools/make_install.bat b/packaging/tools/make_install.bat index bf7418ad79..f5ed1cdf66 100644 --- a/packaging/tools/make_install.bat +++ b/packaging/tools/make_install.bat @@ -2,12 +2,20 @@ for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a" -goto %1 +if "%1" NEQ "" goto %1 + :needAdmin if exist C:\\TDengine\\data\\dnode\\dnodeCfg.json ( echo The default data directory C:/TDengine/data contains old data of tdengine 2.x, please clear it before installing! ) + +rem // stop and delete service +mshta vbscript:createobject("shell.application").shellexecute("%~s0",":stop_delete","","runas",1)(window.close) +echo This might take a few moment to accomplish deleting service taosd/taosadapter ... +call :check_svc taosd +call :check_svc taosadapter + set source_dir=%2 set source_dir=%source_dir:/=\\% set binary_dir=%3 @@ -87,7 +95,6 @@ if %Enterprise% == TRUE ( copy %binary_dir%\\build\\bin\\taosd.exe %target_dir% > nul copy %binary_dir%\\build\\bin\\udfd.exe %target_dir% > nul - if exist %binary_dir%\\build\\bin\\taosadapter.exe ( copy %binary_dir%\\build\\bin\\taosadapter.exe %target_dir% > nul ) @@ -107,22 +114,23 @@ goto :eof :hasAdmin -sc query "taosd" && sc stop taosd && sc delete taosd -sc query "taosadapter" && sc stop taosadapter && sc delete taosd +call :stop_delete +call :check_svc taosd +call :check_svc taosadapter copy /y C:\\TDengine\\driver\\taos.dll C:\\Windows\\System32 > nul if exist C:\\TDengine\\driver\\taosws.dll ( copy /y C:\\TDengine\\driver\\taosws.dll C:\\Windows\\System32 > nul ) -sc query "taosd" >nul || sc create "taosd" binPath= "C:\\TDengine\\taosd.exe --win_service" start= DEMAND -sc query "taosadapter" >nul || sc create "taosadapter" binPath= "C:\\TDengine\\taosadapter.exe" start= DEMAND +rem // create services +sc create "taosd" binPath= "C:\\TDengine\\taosd.exe --win_service" start= DEMAND +sc create "taosadapter" binPath= "C:\\TDengine\\taosadapter.exe" start= DEMAND set "env=HKLM\System\CurrentControlSet\Control\Session Manager\Environment" for /f "tokens=2*" %%I in ('reg query "%env%" /v Path ^| findstr /i "\"') do ( - rem // make addition persistent through reboots - reg add "%env%" /f /v Path /t REG_EXPAND_SZ /d "%%J;C:\TDengine" + call :append_if_not_exists %%J rem // apply change to the current process for %%a in ("%%J;C:\TDengine") do path %%~a @@ -132,3 +140,36 @@ rem // use setx to set a temporary throwaway value to trigger a WM_SETTINGCHANGE rem // applies change to new console windows without requiring a reboot (setx /m foo bar & reg delete "%env%" /f /v foo) >NUL 2>NUL +goto :end + +:append_if_not_exists +set "_origin_paths=%*" +set "_paths=%*" +set "_found=0" +:loop +for /f "tokens=1* delims=;" %%x in ("%_paths%") do ( + if "%%x" EQU "C:\TDengine" ( + set "_found=1" + ) else ( + set "_paths=%%y" + goto :loop + ) +) +if "%_found%" == "0" ( + rem // make addition persistent through reboots + reg add "%env%" /f /v Path /t REG_EXPAND_SZ /d "%_origin_paths%;C:\TDengine" +) +exit /B 0 + +:stop_delete +sc stop taosd +sc delete taosd +sc stop taosadapter +sc delete taosadapter +exit /B 0 + +:check_svc +sc query %1 >nul 2>nul && goto :check_svc %1 +exit /B 0 + +:end