zcbot/windows-node/install-windows-node.bat

186 lines
6.1 KiB
Batchfile

@echo off
setlocal EnableExtensions
cd /d "%~dp0"
set "NODE_EXE=%~dp0Zcbot.WindowsNode.exe"
set "ORIGIN_REQUIREMENTS=%~dp0adapters\origin.plot@v2\requirements.txt"
set "ORIGIN_RUNTIME_DIR=%ProgramData%\Zcbot\WindowsNode\runtimes\origin"
set "ORIGIN_RUNTIME_PYTHON=%ORIGIN_RUNTIME_DIR%\Scripts\python.exe"
set "ANSYS_REQUIREMENTS=%~dp0adapters\ansys.mechanical.static_structural@v2\requirements.txt"
set "ANSYS_RUNTIME_DIR=%ProgramData%\Zcbot\WindowsNode\runtimes\ansys"
set "ANSYS_RUNTIME_PYTHON=%ANSYS_RUNTIME_DIR%\Scripts\python.exe"
echo [INFO] Installing zcbot Windows Node...
if not exist "%NODE_EXE%" (
echo [ERR] Zcbot.WindowsNode.exe was not found beside this installer.
goto :failed
)
call :detect_origin
if errorlevel 1 (
echo [WARN] Origin/OriginPro was not detected; skipped the Origin runtime.
goto :install_ansys
)
echo [INFO] Origin/OriginPro detected.
if not exist "%ORIGIN_REQUIREMENTS%" (
echo [ERR] Origin worker requirements are missing: %ORIGIN_REQUIREMENTS%
goto :failed
)
if not exist "%ORIGIN_RUNTIME_PYTHON%" (
echo [INFO] Creating Origin Python runtime...
call :create_python_runtime "%ORIGIN_RUNTIME_DIR%" "%~1"
if errorlevel 1 (
echo [ERR] Failed to create the Origin Python runtime.
goto :failed
)
)
if not exist "%ORIGIN_RUNTIME_PYTHON%" (
echo [ERR] Python venv did not create its interpreter: %ORIGIN_RUNTIME_PYTHON%
goto :failed
)
"%ORIGIN_RUNTIME_PYTHON%" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)"
if errorlevel 1 (
echo [ERR] Existing Origin runtime is not Python 3.12: %ORIGIN_RUNTIME_PYTHON%
goto :failed
)
echo [INFO] Installing Origin worker dependencies...
"%ORIGIN_RUNTIME_PYTHON%" -m pip install --requirement "%ORIGIN_REQUIREMENTS%"
if errorlevel 1 (
echo [ERR] Failed to install the Origin worker dependencies.
goto :failed
)
"%ORIGIN_RUNTIME_PYTHON%" -c "import originpro, openpyxl, numpy, pymupdf; print('[OK] Origin worker Python packages are available.')"
if errorlevel 1 (
echo [ERR] Origin runtime import verification failed.
goto :failed
)
echo [OK] Origin runtime installed: %ORIGIN_RUNTIME_PYTHON%
:install_ansys
call :detect_ansys_242
if errorlevel 1 (
echo [WARN] ANSYS Mechanical 2024 R2 was not detected; skipped the ANSYS runtime.
goto :install_startup
)
echo [INFO] ANSYS Mechanical 2024 R2 detected.
if not exist "%ANSYS_REQUIREMENTS%" (
echo [ERR] ANSYS worker requirements are missing: %ANSYS_REQUIREMENTS%
goto :failed
)
if not exist "%ANSYS_RUNTIME_PYTHON%" (
echo [INFO] Creating ANSYS Python runtime...
call :create_python_runtime "%ANSYS_RUNTIME_DIR%" "%~1"
if errorlevel 1 (
echo [ERR] Failed to create the ANSYS Python runtime.
goto :failed
)
)
if not exist "%ANSYS_RUNTIME_PYTHON%" (
echo [ERR] Python venv did not create its interpreter: %ANSYS_RUNTIME_PYTHON%
goto :failed
)
"%ANSYS_RUNTIME_PYTHON%" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)"
if errorlevel 1 (
echo [ERR] Existing ANSYS runtime is not Python 3.12: %ANSYS_RUNTIME_PYTHON%
goto :failed
)
echo [INFO] Installing ANSYS worker dependencies...
"%ANSYS_RUNTIME_PYTHON%" -m pip install --requirement "%ANSYS_REQUIREMENTS%"
if errorlevel 1 (
echo [ERR] Failed to install the ANSYS worker dependencies.
goto :failed
)
"%ANSYS_RUNTIME_PYTHON%" -c "from ansys.mechanical.core import App; print('[OK] ANSYS worker Python packages are available.')"
if errorlevel 1 (
echo [ERR] ANSYS runtime import verification failed.
goto :failed
)
echo [OK] ANSYS runtime installed: %ANSYS_RUNTIME_PYTHON%
:install_startup
echo [INFO] Registering startup task for %USERDOMAIN%\%USERNAME%...
schtasks.exe /Create /TN "Zcbot Windows Node" /SC ONLOGON /RU "%USERDOMAIN%\%USERNAME%" /RL LIMITED /IT /TR "\"%NODE_EXE%\"" /F
if errorlevel 1 (
echo [ERR] Failed to register the Windows Node startup task.
goto :failed
)
echo [OK] Windows Node installation completed.
echo [INFO] Start Zcbot.WindowsNode.exe to register or connect the node.
goto :finish_ok
:detect_origin
reg.exe query "HKCR\Origin.ApplicationSI\CLSID" >nul 2>&1
if not errorlevel 1 exit /b 0
reg.exe query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "OriginLab" /d >nul 2>&1
if not errorlevel 1 exit /b 0
reg.exe query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "OriginLab" /d >nul 2>&1
if not errorlevel 1 exit /b 0
reg.exe query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "OriginLab" /d >nul 2>&1
if not errorlevel 1 exit /b 0
exit /b 1
:detect_ansys_242
if defined AWP_ROOT242 if exist "%AWP_ROOT242%\aisol\bin\winx64\AnsysWBU.exe" exit /b 0
if exist "C:\Program Files\ANSYS Inc\v242\aisol\bin\winx64\AnsysWBU.exe" exit /b 0
exit /b 1
:create_python_runtime
if not "%~2"=="" (
if not exist "%~2" (
echo [ERR] Python executable was not found: %~2
exit /b 1
)
"%~2" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)"
if errorlevel 1 (
echo [ERR] The specified Python must be Python 3.12: %~2
exit /b 1
)
echo [INFO] Using Python 3.12: %~2
"%~2" -m venv "%~1"
exit /b %ERRORLEVEL%
)
where.exe py.exe >nul 2>&1
if not errorlevel 1 (
py.exe -3.12 -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)" >nul 2>&1
if not errorlevel 1 (
echo [INFO] Using Python 3.12 through py.exe.
py.exe -3.12 -m venv "%~1"
exit /b %ERRORLEVEL%
)
)
where.exe python.exe >nul 2>&1
if not errorlevel 1 (
python.exe -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)" >nul 2>&1
if not errorlevel 1 (
echo [INFO] Using Python 3.12 from PATH.
python.exe -m venv "%~1"
exit /b %ERRORLEVEL%
)
)
echo [ERR] Python 3.12 was not found.
echo [INFO] Add Python 3.12 to PATH or run: install-windows-node.bat "C:\path\python.exe"
exit /b 1
:failed
echo.
echo [ERR] Installation failed.
echo [INFO] Press any key to close this window.
pause >nul
exit /b 1
:finish_ok
echo.
echo [INFO] Press any key to close this window.
pause >nul
exit /b 0