Files
ssh-manager/scripts/windows/start-local.bat
2026-04-16 23:28:26 +08:00

57 lines
1.6 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
setlocal enabledelayedexpansion
set "ROOT=%~dp0..\.."
for %%I in ("%ROOT%") do set "ROOT=%%~fI"
set "RUNTIME_DIR=%ROOT%\runtime"
set "DATA_DIR=%ROOT%\data"
set "ENV_FILE=%RUNTIME_DIR%\local-env.bat"
if not exist "%RUNTIME_DIR%" mkdir "%RUNTIME_DIR%"
if not exist "%DATA_DIR%" mkdir "%DATA_DIR%"
where java >nul 2>nul
if errorlevel 1 (
echo [ERROR] 未检测到 Java请先安装 JDK/JRE 8+
pause
exit /b 1
)
if not exist "%ENV_FILE%" (
echo 首次启动,正在生成本地运行密钥...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"$jwt=[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes(([Guid]::NewGuid().ToString('N')+[Guid]::NewGuid().ToString('N'))));" ^
"$bytes=New-Object byte[] 32; [Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes); $enc=[Convert]::ToBase64String($bytes);" ^
"$content=@('set SSHMANAGER_JWT_SECRET='+$jwt,'set SSHMANAGER_ENCRYPTION_KEY='+$enc); Set-Content -Path '%ENV_FILE%' -Value $content -Encoding ASCII"
if errorlevel 1 (
echo [ERROR] 生成本地密钥失败
pause
exit /b 1
)
)
call "%ENV_FILE%"
set "DATA_DIR=%DATA_DIR%"
set "APP_JAR="
for %%F in ("%ROOT%\backend\target\*.jar") do (
set "APP_JAR=%%~fF"
)
if not defined APP_JAR (
echo [ERROR] 未找到 backend\target\*.jar
echo 请先执行发布构建,或将打包后的 jar 放到 backend\target 目录。
pause
exit /b 1
)
echo 启动 SSH Manager...
echo 数据目录: %DATA_DIR%
echo 程序包: %APP_JAR%
echo 访问地址: http://localhost:48080
echo.
java -jar "%APP_JAR%"
endlocal