@@ -16,7 +16,9 @@ echo Date: %date% %time%
1616echo ------------------------------------------------------------
1717echo.
1818
19+ REM =========================
1920REM Variables
21+ REM =========================
2022set "ORG_ID=${ orgId } "
2123set "EMPLOYEE_ID=${ employeeId } "
2224set "PRIMARY_DIR=${ fleetDevicePath } "
@@ -26,6 +28,7 @@ set "LOG_FILE="
2628set "HAS_ERROR=0"
2729set "ERRORS="
2830set "EXIT_CODE=0"
31+ REM newline token (exactly this 2-line shape)
2932set "nl=^
3033"
3134
@@ -55,7 +58,11 @@ if not "!rc!"=="0" (
5558endlocal & set "LAST_RC=%rc%"
5659exit /b %LAST_RC%
5760
58- REM Require Administrator (check High Mandatory Level) and exit with instructions if not elevated
61+ call :log_msg "Script starting"
62+
63+ REM =========================
64+ REM Admin check
65+ REM =========================
5966whoami /groups | find "S-1-16-12288" >nul 2>&1
6067if errorlevel 1 (
6168 color 0E
@@ -67,13 +74,16 @@ if errorlevel 1 (
6774 exit /b 5
6875)
6976
70- REM Ensure this script runs in a persistent cmd session that stays open after completion
77+ REM =========================
78+ REM Relaunch persistent window
79+ REM =========================
7180if not "%PERSIST%"=="1" (
7281 set "PERSIST=1"
7382 call :log_msg "Re-launching in a persistent window"
7483 start "CompAI Device Setup" cmd /k "%~f0 %*"
7584 exit /b
7685)
86+
7787call :log_msg "Running with administrator privileges"
7888call :log_msg "Current directory: %cd%"
7989call :log_msg "Script path: %~f0"
@@ -82,20 +92,22 @@ cd /d "%~dp0"
8292call :log_msg "New current directory: %cd%"
8393echo.
8494
85- REM Choose a writable directory (primary first, then fallback) without parentheses blocks
95+ REM =========================
96+ REM Choose writable directory
97+ REM =========================
8698call :log_msg "Choosing destination directory; primary=%PRIMARY_DIR% fallback=%FALLBACK_DIR%"
87- if exist "%PRIMARY_DIR%\NUL" set "CHOSEN_DIR=%PRIMARY_DIR%"
99+ if exist "%PRIMARY_DIR%\\ NUL" set "CHOSEN_DIR=%PRIMARY_DIR%"
88100if not defined CHOSEN_DIR call :log_run mkdir "%PRIMARY_DIR%"
89- if not defined CHOSEN_DIR if exist "%PRIMARY_DIR%\NUL" set "CHOSEN_DIR=%PRIMARY_DIR%"
101+ if not defined CHOSEN_DIR if exist "%PRIMARY_DIR%\\ NUL" set "CHOSEN_DIR=%PRIMARY_DIR%"
90102
91103if not defined CHOSEN_DIR call :log_msg "Primary not available; trying fallback"
92- if not defined CHOSEN_DIR if exist "%FALLBACK_DIR%\NUL" set "CHOSEN_DIR=%FALLBACK_DIR%"
104+ if not defined CHOSEN_DIR if exist "%FALLBACK_DIR%\\ NUL" set "CHOSEN_DIR=%FALLBACK_DIR%"
93105if not defined CHOSEN_DIR call :log_run mkdir "%FALLBACK_DIR%"
94- if not defined CHOSEN_DIR if exist "%FALLBACK_DIR%\NUL" set "CHOSEN_DIR=%FALLBACK_DIR%"
106+ if not defined CHOSEN_DIR if exist "%FALLBACK_DIR%\\ NUL" set "CHOSEN_DIR=%FALLBACK_DIR%"
95107
96108if not defined CHOSEN_DIR (
97109 color 0E
98- echo WARNING: No writable directory found.
110+ call :log_msg " WARNING: No writable directory found"
99111 echo Primary attempted: "%PRIMARY_DIR%"
100112 echo Fallback attempted: "%FALLBACK_DIR%"
101113 echo [%date% %time%] No writable directory found. Primary: %PRIMARY_DIR%, Fallback: %FALLBACK_DIR% >> "%~dp0setup.log"
@@ -107,7 +119,7 @@ if not defined CHOSEN_DIR (
107119 set "MARKER_DIR=%CHOSEN_DIR%"
108120 if not "!MARKER_DIR:~-1!"=="\\" set "MARKER_DIR=!MARKER_DIR!\\"
109121
110- REM switch the log file to the chosen directory, carrying over bootstrap logs
122+ REM switch the log file to the chosen directory, carry over bootstrap logs
111123 set "FINAL_LOG=!MARKER_DIR!setup.log"
112124 if /i not "%LOG_FILE%"=="%FINAL_LOG%" (
113125 call :log_msg "Switching log to !FINAL_LOG!"
@@ -119,7 +131,9 @@ if not defined CHOSEN_DIR (
119131echo Logs will be written to: %LOG_FILE%
120132echo.
121133
134+ REM =========================
122135REM Write marker files
136+ REM =========================
123137if defined CHOSEN_DIR (
124138 call :log_msg "Writing organization marker file"
125139 call :log_msg "Preparing to write org marker to !MARKER_DIR!!ORG_ID!"
@@ -150,7 +164,9 @@ if defined CHOSEN_DIR (
150164 )
151165)
152166
153- REM Set permissive read ACLs for SYSTEM and Administrators
167+ REM =========================
168+ REM Permissions
169+ REM =========================
154170if defined CHOSEN_DIR (
155171 call :log_msg "Setting permissions on marker directory"
156172 call :log_run icacls "!MARKER_DIR!" /inheritance:e
@@ -162,13 +178,16 @@ if defined CHOSEN_DIR (
162178 call :log_run icacls "!MARKER_DIR!!EMPLOYEE_ID!" /grant *S-1-5-18:R *S-1-5-32-544:R
163179)
164180
181+ REM =========================
182+ REM Verify
183+ REM =========================
165184echo.
166185echo Verifying markers...
167186if defined CHOSEN_DIR (
168187 call :log_msg "Verifying marker exists: !MARKER_DIR!!EMPLOYEE_ID!"
169188 if not exist "!MARKER_DIR!!EMPLOYEE_ID!" (
170189 color 0E
171- echo WARNING: Employee marker file missing at !MARKER_DIR!!EMPLOYEE_ID!
190+ call :log_msg " WARNING: Employee marker file missing at !MARKER_DIR!!EMPLOYEE_ID!"
172191 echo [%date% %time%] Verification failed: employee marker file missing >> "!LOG_FILE!"
173192 set "HAS_ERROR=1"
174193 set "ERRORS=!ERRORS!- Employee marker file missing at !MARKER_DIR!!EMPLOYEE_ID!!.!nl!"
@@ -179,6 +198,9 @@ if defined CHOSEN_DIR (
179198)
180199rem Skipping registry checks per request
181200
201+ REM =========================
202+ REM Result / Exit
203+ REM =========================
182204echo.
183205echo ------------------------------------------------------------
184206if "%HAS_ERROR%"=="0" (
@@ -207,5 +229,5 @@ echo Press any key to close this window. This will not affect installation.
207229pause
208230if "%HAS_ERROR%"=="0" (exit /b 0) else (exit /b %EXIT_CODE%)` ;
209231
210- return script . replace ( / \\ n / g, '\r\n' ) ;
232+ return script . replace ( / \n / g, '\r\n' ) ;
211233}
0 commit comments