-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-multi-client.bat
More file actions
232 lines (206 loc) · 9.46 KB
/
Copy pathstart-multi-client.bat
File metadata and controls
232 lines (206 loc) · 9.46 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
@echo off
setlocal enabledelayedexpansion
:: start-multi-client.bat
:: Windows version of the VBSC startup script
:: Optimized for robustness and clarity
set "ROOT_DIR=%~dp0"
cd /d "%ROOT_DIR%"
:: Set ESC for colors (Modern Windows Terminal / CMD with ANSI support)
for /f "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do set "ESC=%%b"
set "GREEN=%ESC%[92m"
set "BLUE=%ESC%[94m"
set "YELLOW=%ESC%[93m"
set "RED=%ESC%[91m"
set "CYAN=%ESC%[36m"
set "NC=%ESC%[0m"
echo %CYAN%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━%NC%
echo %GREEN%🚀 VBSC Multi-Client Startup Script (Windows)%NC%
echo %CYAN%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━%NC%
:: 1. Check Dependencies
echo [%BLUE%INFO%NC%] Checking dependencies...
where mvn >nul 2>nul
if %errorlevel% neq 0 (
echo %RED%[ERROR] Maven (mvn^) not found.%NC%
echo Please install Maven and add it to your PATH.
pause
exit /b 1
)
where npm >nul 2>nul
if %errorlevel% neq 0 (
echo %RED%[ERROR] Node.js/NPM (npm^) not found.%NC%
echo Please install Node.js and add it to your PATH.
pause
exit /b 1
)
:: 2. Handle Vault Master Key Persistence
set "VAULT_KEY_FILE=%ROOT_DIR%.vault_master_key"
if exist "%VAULT_KEY_FILE%" goto :load_key
echo [%BLUE%INFO%NC%] Generating persistent Vault Master Key...
:: Use PowerShell to generate a clean ASCII alphanumeric string without BOM
powershell -Command "$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $res = -join (1..32 | ForEach-Object { $chars[(Get-Random -Maximum $chars.Length)] }); [System.IO.File]::WriteAllText('%VAULT_KEY_FILE%', $res)"
if %errorlevel% neq 0 (
echo %RED%[ERROR] Failed to generate Vault Master Key.%NC%
pause
exit /b 1
)
:load_key
set /p VAULT_MASTER_KEY=<"%VAULT_KEY_FILE%"
:: Trim any potential trailing spaces or characters
for /f "tokens=*" %%a in ("%VAULT_MASTER_KEY%") do set "VAULT_MASTER_KEY=%%a"
echo %GREEN%✓%NC% Persistent Vault Master Key loaded.
:: 3. Parse Arguments
set "CLEAN_CLIENTS=false"
set "CLEAN_VAULT_DB=false"
set "CLEAN_VAULT_IDENTITY=false"
set "CLEAN_ROOT_IDENTITY=false"
:parse_args
if "%~1"=="" goto :end_parse_args
if /i "%~1"=="--help" goto :show_help
if /i "%~1"=="-h" goto :show_help
if /i "%~1"=="--clean" set "CLEAN_CLIENTS=true" & set "CLEAN_VAULT_DB=true" & set "CLEAN_VAULT_IDENTITY=true"
if /i "%~1"=="--clean-all" set "CLEAN_CLIENTS=true" & set "CLEAN_VAULT_DB=true" & set "CLEAN_VAULT_IDENTITY=true"
if /i "%~1"=="--clean-full" set "CLEAN_CLIENTS=true" & set "CLEAN_VAULT_DB=true" & set "CLEAN_VAULT_IDENTITY=true" & set "CLEAN_ROOT_IDENTITY=true"
if /i "%~1"=="--fix-identity" set "CLEAN_VAULT_IDENTITY=true"
shift
goto :parse_args
:show_help
echo VBSC Multi-Client Startup Help
echo.
echo Usage: .\start-multi-client.bat [switches]
echo.
echo Switches:
echo --clean Reset client DBs and transparency logs (keep identities)
echo --clean-all Alias for --clean
echo --clean-full Total system reset (deletes root signing keys + data)
echo --fix-identity Re-sync local client identity with Vault
echo --help, -h Show this help message
exit /b 0
:end_parse_args
:: 4. Cleanup Logic
if "%CLEAN_CLIENTS%"=="true" (
echo [%YELLOW%CLEAN%NC%] Cleaning client SQLite databases...
del /q "%ROOT_DIR%new-client-side\*.sqlite" 2>nul
)
if "%CLEAN_ROOT_IDENTITY%"=="true" (
echo [%RED%RESET%NC%] Deleting Root Signing Identity...
del /q "%ROOT_DIR%vault-authority-service\vault.signing.bin" 2>nul
)
if "%CLEAN_VAULT_IDENTITY%"=="true" (
echo [%YELLOW%ROTATE%NC%] Cycling Encryption Identity...
del /q "%ROOT_DIR%vault-authority-service\vault.identity" 2>nul
)
if "%CLEAN_VAULT_DB%"=="true" (
echo [%YELLOW%CLEAN%NC%] Resetting MySQL Transparency Logs...
set "MYSQL_CMD=mysql"
set "MYSQL_FOUND=false"
where !MYSQL_CMD! >nul 2>nul
if !errorlevel! equ 0 (
set "MYSQL_FOUND=true"
) else (
if exist "C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe" (
set "MYSQL_CMD="C:\Program Files\MySQL\MySQL Server 8.0\bin\mysql.exe""
set "MYSQL_FOUND=true"
) else if exist "C:\Program Files\MySQL\MySQL Server 8.1\bin\mysql.exe" (
set "MYSQL_CMD="C:\Program Files\MySQL\MySQL Server 8.1\bin\mysql.exe""
set "MYSQL_FOUND=true"
) else (
echo %YELLOW%[WARN]%NC% mysql command not found, skipping DB reset.
)
)
if "!MYSQL_FOUND!"=="true" (
!MYSQL_CMD! -u root -p2003 -e "DROP DATABASE IF EXISTS vault_authority_db; CREATE DATABASE vault_authority_db;" 2>nul
if !errorlevel! equ 0 (
echo %GREEN%✓%NC% MySQL database reset.
) else (
echo %RED%[ERROR]%NC% MySQL reset failed. Check password or permissions.
)
)
)
if "%CLEAN_CLIENTS%"=="true" (
echo [%YELLOW%CLEAN%NC%] Resetting Server Messaging State...
rmdir /s /q "%ROOT_DIR%server-side\data" 2>nul
mkdir "%ROOT_DIR%server-side\data" 2>nul
echo [%YELLOW%CLEAN%NC%] Clearing Logs...
rmdir /s /q "%ROOT_DIR%server-side\logs" 2>nul
rmdir /s /q "%ROOT_DIR%vault-authority-service\logs" 2>nul
rmdir /s /q "%ROOT_DIR%new-client-side\logs" 2>nul
)
echo.
echo %YELLOW%Starting Services...%NC%
:: 5. Start Vault Authority
netstat -ano | findstr /C:":8081 " | findstr LISTENING >nul
if !errorlevel! neq 0 (
echo [%BLUE%1/6%NC%] Starting Vault Authority (8081^)...
start "Vault Authority" cmd /k "cd /d "%ROOT_DIR%vault-authority-service" && set "VAULT_MASTER_KEY=%VAULT_MASTER_KEY%" && mvn spring-boot:run"
timeout /t 5 >nul
) else (
echo %GREEN%✓%NC% Vault Authority already running on 8081.
)
:: 6. Start Vault Dashboard
netstat -ano | findstr /C:":5175 " | findstr LISTENING >nul
if !errorlevel! neq 0 (
echo [%BLUE%2/6%NC%] Starting Vault Dashboard (5175^)...
start "Vault Dashboard" cmd /k "cd /d "%ROOT_DIR%vault-authority-service\vault-dashboard" && npm run dev -- --port 5175"
timeout /t 3 >nul
) else (
echo %GREEN%✓%NC% Vault Dashboard already running on 5175.
)
:: 7. Start Server Relay
netstat -ano | findstr /C:":8443 " | findstr LISTENING >nul
if !errorlevel! neq 0 (
echo [%BLUE%3/6%NC%] Starting Server Relay (8443^)...
start "Server Relay" cmd /k "cd /d "%ROOT_DIR%server-side" && mvn spring-boot:run"
timeout /t 3 >nul
) else (
echo %GREEN%✓%NC% Server Relay already running on 8443.
)
:: 8. Alice (8082 + 5173)
netstat -ano | findstr /C:":8082 " | findstr LISTENING >nul
if !errorlevel! neq 0 (
echo [%BLUE%4/6%NC%] Starting Alice Backend (8082^)...
start "Alice Backend (8082^)" cmd /k "cd /d "%ROOT_DIR%new-client-side" && set "SERVER_PORT=8082" && set "SPRING_DATASOURCE_URL=jdbc:sqlite:alice_db.sqlite" && set "CLIENT_ID=client-alice" && mvn spring-boot:run"
)
netstat -ano | findstr /C:":5173 " | findstr LISTENING >nul
if !errorlevel! neq 0 (
echo [%BLUE%5/6%NC%] Starting Alice Frontend (5173^)...
start "Alice Frontend (5173^)" cmd /k "cd /d "%ROOT_DIR%new-client-side\frontend" && set "VITE_PROXY_TARGET=http://localhost:8082" && npm run dev"
)
:: 9. Bob (8083 + 5174)
netstat -ano | findstr /C:":8083 " | findstr LISTENING >nul
if !errorlevel! neq 0 (
echo [%BLUE%6/6%NC%] Starting Bob Backend (8083^)...
start "Bob Backend (8083^)" cmd /k "cd /d "%ROOT_DIR%new-client-side" && set "SERVER_PORT=8083" && set "SPRING_DATASOURCE_URL=jdbc:sqlite:bob_db.sqlite" && set "CLIENT_ID=client-bob" && mvn spring-boot:run"
)
netstat -ano | findstr /C:":5174 " | findstr LISTENING >nul
if !errorlevel! neq 0 (
echo Starting Bob Frontend (5174^)...
start "Bob Frontend (5174^)" cmd /k "cd /d "%ROOT_DIR%new-client-side\frontend" && set "VITE_PROXY_TARGET=http://localhost:8083" && set "PORT=5174" && npm run dev -- --port 5174"
)
echo.
echo %CYAN%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━%NC%
echo %GREEN%✅ All services started successfully!%NC%
echo %CYAN%━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━%NC%
echo.
echo %BLUE%Access Points:%NC%
echo Alice: %YELLOW%http://localhost:5173%NC%
echo Bob: %YELLOW%http://localhost:5174%NC%
echo Vault DB: %YELLOW%http://localhost:5175%NC%
echo.
echo %YELLOW%💡 Tips:%NC%
echo - Check the individual windows for logs/errors.
echo - Use --clean-all to reset client databases.
echo - Use --clean-full for a total system reset.
echo.
echo %RED%[EXIT] Press any key to SHUTDOWN all services and close terminals...%NC%
pause >nul
:: Cleanup: Kill all project-related windows
echo [STOP] Terminating Alice, Bob, Relay, Vault, and Admin...
taskkill /F /FI "WINDOWTITLE eq Alice Backend (8082)*" /T >nul 2>&1
taskkill /F /FI "WINDOWTITLE eq Alice Frontend (5173)*" /T >nul 2>&1
taskkill /F /FI "WINDOWTITLE eq Bob Backend (8083)*" /T >nul 2>&1
taskkill /F /FI "WINDOWTITLE eq Bob Frontend (5174)*" /T >nul 2>&1
taskkill /F /FI "WINDOWTITLE eq Server Relay (9443)*" /T >nul 2>&1
taskkill /F /FI "WINDOWTITLE eq Vault Authority (8081)*" /T >nul 2>&1
taskkill /F /FI "WINDOWTITLE eq Vault Dashboard (8084)*" /T >nul 2>&1
echo %GREEN%✓%NC% All terminals closed. System offline.
exit /b 0