install.bat
4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
@echo off
rem StoreEdge installer (run as administrator):
rem install.bat default instance: C:\autoRestore\StoreEdge, Windows service StoreEdge
rem install.bat dev one more instance on the same computer: C:\autoRestore\StoreEdge-dev, service StoreEdge-dev
rem (own config.ini / device token / logs / login state / version; other instances are not touched)
rem 1. copy the package to the install folder (keeps existing config.ini / logs / data / run)
rem default instance only: an old installation in C:\StoreEdge is moved: its service is removed, config.ini, run\,
rem logs\ and edge_data\ copied over (the old folder is kept)
rem 2. pick the WinSW build (.NET 3.5 on Win7 -> NET2, otherwise NET4) and register the Windows service
rem 3. run the setup wizard (cloud address + device token, connection test, pull config from the cloud)
rem 4. start the service: auto start at boot, no window, auto restart on crash
rem A manual install always runs the code in this package (remote updates in app\ are ignored until the next update).
setlocal
net session >nul 2>&1
if errorlevel 1 (
echo [ERROR] Please right-click install.bat and choose "Run as administrator".
pause
exit /b 1
)
set "INST=%~1"
set "SVC=StoreEdge"
if "%INST%"=="" goto inst_ok
echo %INST%| findstr /r /x "[abcdefghijklmnopqrstuvwxyz0123456789_-]*" >nul
if errorlevel 1 (
echo [ERROR] Instance name "%INST%" may only use lower-case letters, digits, - and _ ^(for example: install.bat dev^).
pause
exit /b 3
)
set "SVC=StoreEdge-%INST%"
:inst_ok
set "SRC=%~dp0"
set "DEST=C:\autoRestore\%SVC%\"
set "OLD=C:\StoreEdge\"
echo Installing instance %SVC% to %DEST%
if /i not "%SRC%"=="%DEST%" (
if not exist "%DEST%" mkdir "%DEST%"
if "%INST%"=="" if exist "%OLD%StoreEdge.exe" if /i not "%SRC%"=="%OLD%" (
echo Found the old installation in %OLD% - moving it to %DEST% ...
"%OLD%StoreEdge.exe" stop >nul 2>&1
"%OLD%StoreEdge.exe" uninstall >nul 2>&1
if not exist "%DEST%config.ini" if exist "%OLD%config.ini" copy /Y "%OLD%config.ini" "%DEST%config.ini" >nul
if not exist "%DEST%run\" if exist "%OLD%run\" xcopy "%OLD%run" "%DEST%run\" /E /I /Y /Q >nul
rem logs and result folders are audit records: copy them too (the old folder is never deleted)
if not exist "%DEST%logs\" if exist "%OLD%logs\" xcopy "%OLD%logs" "%DEST%logs\" /E /I /Y /Q >nul
if not exist "%DEST%edge_data\" if exist "%OLD%edge_data\" xcopy "%OLD%edge_data" "%DEST%edge_data\" /E /I /Y /Q >nul
echo The old folder %OLD% is kept; delete it by hand after checking the new installation.
)
echo Copying files to %DEST% ...
if exist "%DEST%%SVC%.exe" "%DEST%%SVC%.exe" stop >nul 2>&1
xcopy "%SRC%*" "%DEST%" /E /I /Y /Q /EXCLUDE:%SRC%service\xcopy_exclude.txt >nul
if errorlevel 1 (
echo [ERROR] Copy failed.
pause
exit /b 2
)
if "%INST%"=="" if not exist "%DEST%config.ini" if exist "%SRC%config.ini" copy /Y "%SRC%config.ini" "%DEST%config.ini" >nul
)
cd /d "%DEST%"
if exist %SVC%.exe %SVC%.exe stop >nul 2>&1
if exist run\version.json del /Q run\version.json
reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" /v Install 2>nul | find "0x1" >nul
if not errorlevel 1 (
copy /Y service\WinSW.NET2.exe %SVC%.exe >nul
) else (
copy /Y service\WinSW.NET4.exe %SVC%.exe >nul
)
set PYTHONNOUSERSITE=1
if "%INST%"=="" (
copy /Y service\StoreEdge.xml StoreEdge.xml >nul
python38\python.exe main.py setup
) else (
rem the wizard writes [local] instance into config.ini and generates %SVC%.xml
python38\python.exe main.py setup --instance %INST%
)
if errorlevel 3 (
echo.
echo [ERROR] Configuration problem ^(see above^). The service was not installed / started.
pause
exit /b 3
)
if errorlevel 1 (
echo.
echo [WARN] The wizard reported problems ^(see above^). Press any key to install the service anyway, or close this window to fix them first.
pause >nul
)
%SVC%.exe status | find /i "NonExistent" >nul
if not errorlevel 1 %SVC%.exe install
%SVC%.exe start
timeout /t 5 /nobreak >nul
python38\python.exe main.py status
echo.
echo Installed to %DEST% . The service %SVC% starts automatically at boot. Use status.bat in that folder to check it.
pause