|
| 1 | +@echo off |
| 2 | +REM Part of ASRFacet-Rb - authorized testing only |
| 3 | +setlocal EnableExtensions |
| 4 | + |
| 5 | +set "SCRIPT_DIR=%~dp0" |
| 6 | +set "SCRIPT_NAME=%~nx0" |
| 7 | +set "PS_SCRIPT=%SCRIPT_DIR%asrfacet-rb-installer-windows.ps1" |
| 8 | +set "PS_EXE=" |
| 9 | +set "MODE=" |
| 10 | +set "FLAG_YES=" |
| 11 | +set "FLAG_NOPROMPT=" |
| 12 | +set "FLAG_KEEPTEMP=" |
| 13 | +set "FLAG_VERBOSE=" |
| 14 | +set "PS_ARGS=" |
| 15 | + |
| 16 | +if not exist "%PS_SCRIPT%" ( |
| 17 | + echo [FAIL] Missing installer script: %PS_SCRIPT% |
| 18 | + exit /b 1 |
| 19 | +) |
| 20 | + |
| 21 | +:parse_args |
| 22 | +if "%~1"=="" goto :args_done |
| 23 | + |
| 24 | +if /I "%~1"=="-h" goto :usage |
| 25 | +if /I "%~1"=="--help" goto :usage |
| 26 | +if /I "%~1"=="/?" goto :usage |
| 27 | + |
| 28 | +if /I "%~1"=="install" goto :set_mode_install |
| 29 | +if /I "%~1"=="test" goto :set_mode_test |
| 30 | +if /I "%~1"=="update" goto :set_mode_update |
| 31 | +if /I "%~1"=="uninstall" goto :set_mode_uninstall |
| 32 | + |
| 33 | +if /I "%~1"=="--yes" ( |
| 34 | + set "FLAG_YES=1" |
| 35 | + shift |
| 36 | + goto :parse_args |
| 37 | +) |
| 38 | + |
| 39 | +if /I "%~1"=="--no-prompt" ( |
| 40 | + set "FLAG_NOPROMPT=1" |
| 41 | + shift |
| 42 | + goto :parse_args |
| 43 | +) |
| 44 | + |
| 45 | +if /I "%~1"=="--keep-temp" ( |
| 46 | + set "FLAG_KEEPTEMP=1" |
| 47 | + shift |
| 48 | + goto :parse_args |
| 49 | +) |
| 50 | + |
| 51 | +if /I "%~1"=="--verbose" ( |
| 52 | + set "FLAG_VERBOSE=1" |
| 53 | + shift |
| 54 | + goto :parse_args |
| 55 | +) |
| 56 | + |
| 57 | +echo [FAIL] Unknown argument: %~1 |
| 58 | +echo [INFO] Run "%SCRIPT_NAME% --help" for usage. |
| 59 | +exit /b 1 |
| 60 | + |
| 61 | +:set_mode_install |
| 62 | +if defined MODE goto :multiple_mode |
| 63 | +set "MODE=install" |
| 64 | +shift |
| 65 | +goto :parse_args |
| 66 | + |
| 67 | +:set_mode_test |
| 68 | +if defined MODE goto :multiple_mode |
| 69 | +set "MODE=test" |
| 70 | +shift |
| 71 | +goto :parse_args |
| 72 | + |
| 73 | +:set_mode_update |
| 74 | +if defined MODE goto :multiple_mode |
| 75 | +set "MODE=update" |
| 76 | +shift |
| 77 | +goto :parse_args |
| 78 | + |
| 79 | +:set_mode_uninstall |
| 80 | +if defined MODE goto :multiple_mode |
| 81 | +set "MODE=uninstall" |
| 82 | +shift |
| 83 | +goto :parse_args |
| 84 | + |
| 85 | +:multiple_mode |
| 86 | +echo [FAIL] Multiple modes provided. Use one of: install, test, update, uninstall. |
| 87 | +exit /b 1 |
| 88 | + |
| 89 | +:args_done |
| 90 | +if defined MODE set "PS_ARGS=%PS_ARGS% -Mode %MODE%" |
| 91 | +if defined FLAG_YES set "PS_ARGS=%PS_ARGS% -Yes" |
| 92 | +if defined FLAG_NOPROMPT set "PS_ARGS=%PS_ARGS% -NoPrompt" |
| 93 | +if defined FLAG_KEEPTEMP set "PS_ARGS=%PS_ARGS% -KeepTemp" |
| 94 | +if defined FLAG_VERBOSE set "PS_ARGS=%PS_ARGS% -VerboseInstaller" |
| 95 | + |
| 96 | +where powershell >nul 2>nul |
| 97 | +if not errorlevel 1 set "PS_EXE=powershell" |
| 98 | + |
| 99 | +if not defined PS_EXE where pwsh >nul 2>nul |
| 100 | +if not defined PS_EXE if not errorlevel 1 set "PS_EXE=pwsh" |
| 101 | + |
| 102 | +if not defined PS_EXE ( |
| 103 | + echo [FAIL] Neither powershell nor pwsh was found in PATH. |
| 104 | + exit /b 1 |
| 105 | +) |
| 106 | + |
| 107 | +if /I "%PS_EXE%"=="powershell" goto :run_powershell |
| 108 | +goto :run_pwsh |
| 109 | + |
| 110 | +:run_powershell |
| 111 | +echo [INFO] Running installer with PowerShell. |
| 112 | +powershell -NoProfile -ExecutionPolicy Bypass -File "%PS_SCRIPT%" %PS_ARGS% |
| 113 | +set "EXIT_CODE=%ERRORLEVEL%" |
| 114 | +goto :finish |
| 115 | + |
| 116 | +:run_pwsh |
| 117 | +echo [INFO] Running installer with PowerShell Core (pwsh). |
| 118 | +pwsh -NoProfile -File "%PS_SCRIPT%" %PS_ARGS% |
| 119 | +set "EXIT_CODE=%ERRORLEVEL%" |
| 120 | +goto :finish |
| 121 | + |
| 122 | +:finish |
| 123 | +if not "%EXIT_CODE%"=="0" ( |
| 124 | + echo [FAIL] Installer failed with exit code %EXIT_CODE%. |
| 125 | +) else ( |
| 126 | + echo [ OK ] Installer completed successfully. |
| 127 | +) |
| 128 | +exit /b %EXIT_CODE% |
| 129 | + |
| 130 | +:usage |
| 131 | +echo ASRFacet-Rb Website Installer (Windows CMD) |
| 132 | +echo. |
| 133 | +echo Usage: |
| 134 | +echo %SCRIPT_NAME% [install^|test^|update^|uninstall] [--yes] [--no-prompt] [--keep-temp] [--verbose] |
| 135 | +echo. |
| 136 | +echo Options: |
| 137 | +echo --yes Run non-interactively where possible |
| 138 | +echo --no-prompt Alias for non-interactive flow |
| 139 | +echo --keep-temp Keep downloaded temp files for troubleshooting |
| 140 | +echo --verbose Print command-level progress |
| 141 | +echo --help, -h Show this help |
| 142 | +exit /b 0 |
0 commit comments