@@ -8,14 +8,6 @@ title CompAI Device Setup
88setlocal EnableExtensions EnableDelayedExpansion
99color 0A
1010
11- echo ------------------------------------------------------------
12- echo CompAI Device Setup
13- echo Organization: ${ orgId }
14- echo Employee: ${ employeeId }
15- echo Date: %date% %time%
16- echo ------------------------------------------------------------
17- echo.
18-
1911REM =========================
2012REM Variables
2113REM =========================
@@ -35,15 +27,18 @@ set "nl=^
3527REM --- bootstrap log (updated once CHOSEN_DIR is known) ---
3628set "LOG_FILE=%~dp0setup.log"
3729
38- REM --- log a message to console and log ---
30+ goto :main
31+
32+ REM =======================================================
33+ REM Subroutines (placed AFTER main to avoid early execution)
34+ REM =======================================================
3935:log_msg
4036setlocal EnableDelayedExpansion
4137set "msg=%~1"
4238echo [%date% %time%] !msg!
4339>>"%LOG_FILE%" echo [%date% %time%] !msg!
4440endlocal & exit /b 0
4541
46- REM --- run a command with logging and error capture ---
4742:log_run
4843setlocal EnableDelayedExpansion
4944set "cmdline=%*"
@@ -58,11 +53,13 @@ if not "!rc!"=="0" (
5853endlocal & set "LAST_RC=%rc%"
5954exit /b %LAST_RC%
6055
56+ REM =========================
57+ REM Main
58+ REM =========================
59+ :main
6160call :log_msg "Script starting"
6261
63- REM =========================
6462REM Admin check
65- REM =========================
6663whoami /groups | find "S-1-16-12288" >nul 2>&1
6764if errorlevel 1 (
6865 color 0E
@@ -74,9 +71,7 @@ if errorlevel 1 (
7471 exit /b 5
7572)
7673
77- REM =========================
7874REM Relaunch persistent window
79- REM =========================
8075if not "%PERSIST%"=="1" (
8176 set "PERSIST=1"
8277 call :log_msg "Re-launching in a persistent window"
@@ -92,9 +87,7 @@ cd /d "%~dp0"
9287call :log_msg "New current directory: %cd%"
9388echo.
9489
95- REM =========================
9690REM Choose writable directory
97- REM =========================
9891call :log_msg "Choosing destination directory; primary=%PRIMARY_DIR% fallback=%FALLBACK_DIR%"
9992if exist "%PRIMARY_DIR%\\NUL" set "CHOSEN_DIR=%PRIMARY_DIR%"
10093if not defined CHOSEN_DIR call :log_run mkdir "%PRIMARY_DIR%"
@@ -131,9 +124,7 @@ if not defined CHOSEN_DIR (
131124echo Logs will be written to: %LOG_FILE%
132125echo.
133126
134- REM =========================
135127REM Write marker files
136- REM =========================
137128if defined CHOSEN_DIR (
138129 call :log_msg "Writing organization marker file"
139130 call :log_msg "Preparing to write org marker to !MARKER_DIR!!ORG_ID!"
@@ -164,9 +155,7 @@ if defined CHOSEN_DIR (
164155 )
165156)
166157
167- REM =========================
168158REM Permissions
169- REM =========================
170159if defined CHOSEN_DIR (
171160 call :log_msg "Setting permissions on marker directory"
172161 call :log_run icacls "!MARKER_DIR!" /inheritance:e
@@ -178,9 +167,7 @@ if defined CHOSEN_DIR (
178167 call :log_run icacls "!MARKER_DIR!!EMPLOYEE_ID!" /grant *S-1-5-18:R *S-1-5-32-544:R
179168)
180169
181- REM =========================
182170REM Verify
183- REM =========================
184171echo.
185172echo Verifying markers...
186173if defined CHOSEN_DIR (
@@ -198,9 +185,7 @@ if defined CHOSEN_DIR (
198185)
199186rem Skipping registry checks per request
200187
201- REM =========================
202188REM Result / Exit
203- REM =========================
204189echo.
205190echo ------------------------------------------------------------
206191if "%HAS_ERROR%"=="0" (
@@ -227,7 +212,11 @@ echo ------------------------------------------------------------
227212echo.
228213echo Press any key to close this window. This will not affect installation.
229214pause
230- if "%HAS_ERROR%"=="0" (exit /b 0) else (exit /b %EXIT_CODE%)` ;
215+ if "%HAS_ERROR%"=="0" (exit /b 0) else (exit /b %EXIT_CODE%)
216+
217+ REM End of main
218+ goto :eof
219+ ` ;
231220
232221 return script . replace ( / \n / g, '\r\n' ) ;
233222}
0 commit comments