@echo off

set dst=c:\cmigrate

echo *************************************************
echo 		packer deploy
echo.
echo Script will do flow works
echo 1. remove old version of packer && correctvolume
echo 2. copy new packer.exe and config to c:\
echo 3. import CA
echo 4. install packer.exe && correctvolume.exe as system service
echo 5. start packer && correctvolume service
echo *************************************************
echo.

echo *************************************************
echo 1. remove old version of packer && correctvolume
echo *************************************************
nssm-2.24\win32\nssm.exe>nul 2>nul stop packer
nssm-2.24\win32\nssm.exe>nul 2>nul remove packer confirm
nssm-2.24\win32\nssm.exe>nul 2>nul stop correctvolume
nssm-2.24\win32\nssm.exe>nul 2>nul remove correctvolume confirm
timeout /t 3 /nobreak> nul
if exist %dst% (
	rd>nul 2>nul /Q/S %dst%
)
echo.

echo *************************************************
echo 2. copy new packer.exe and config to c:\
echo *************************************************
mkdir %dst%
mkdir "%dst%\log"
mkdir "%dst%\conf"
mkdir "%dst%\nssm-2.24"
xcopy /e "conf" "%dst%\conf"
xcopy /e "nssm-2.24" "%dst%\nssm-2.24"
xcopy "packer.exe" "%dst%"
xcopy "redhat.cer" "%dst%"
xcopy "sync.exe" "%dst%"
echo.

echo *************************************************
echo 3. import CA
echo *************************************************
certutil -addstore -f -enterprise "TrustedPublisher" %dst%\redhat.cer
%dst%\sync.exe c
ping 0.0.0.0 -n 5 > null
%dst%\sync.exe c
echo .

echo *************************************************
echo 4. install packer.exe && correctvolume as system service
echo *************************************************
%dst%\nssm-2.24\win32\nssm.exe>nul 2>nul install packer %dst%\packer.exe start=automic
%dst%\nssm-2.24\win32\nssm.exe>nul 2>nul install correctvolume %dst%\correctvolume.exe start=automic
echo.

echo *************************************************
echo 5. start packer && correctvolume service
echo *************************************************
%dst%\nssm-2.24\win32\nssm.exe>nul 2>nul start packer
%dst%\nssm-2.24\win32\nssm.exe>nul 2>nul start correctvolume

pause
