fix: Actually update existing SET MACHINE= line in AUTOEXEC.BAT instead of prompting user
Issue: When AUTOEXEC.BAT already contained "SET MACHINE=" line, DEPLOY.BAT would detect it and show "Manual edit required" message, then do nothing - leaving the old value in place. User reported: "set is still at the end of autoexec" - confirming the old SET MACHINE line was not being updated. Solution: MACHINE_EXISTS section now automatically replaces the old SET MACHINE= line with new value and inserts it at line 2 (after @ECHO OFF). Changes: BEFORE (manual edit prompt): :MACHINE_EXISTS - Show warning - Ask "Update MACHINE variable? (Y/N)" - Display "Manual edit required" instructions - User must manually edit AUTOEXEC.BAT - GOTO INSTALL_BATCH_FILES AFTER (automatic update): :MACHINE_EXISTS - Show current value - Create temp file with @ECHO OFF - Add SET MACHINE=%MACHINE% at line 2 - Filter out old @ECHO OFF and SET MACHINE= lines - Replace original with updated version - Display confirmation message - GOTO INSTALL_BATCH_FILES Implementation: 1. Create C:\AUTOEXEC.TMP with @ECHO OFF 2. Add SET MACHINE=%MACHINE% at line 2 3. TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" | FIND /V "SET MACHINE=" (removes duplicate @ECHO OFF and all old SET MACHINE= lines) 4. COPY temp file over original 5. DELETE temp file Files modified: - DEPLOY.BAT: Lines 289-312 (MACHINE_EXISTS section) - Removed CHOICE prompt and manual edit instructions - Now automatically updates AUTOEXEC.BAT - Created deploy-to-ad2.ps1 for deploying to AD2 Benefits: - No user intervention required - SET MACHINE always at line 2 (before any scripts run) - Old/wrong machine name automatically replaced - Consistent behavior whether SET MACHINE exists or not Deployed to: - D2TESTNAS: /data/test/DEPLOY.BAT - AD2: C:/scripts/sync-copies/bat-files/*.BAT (in progress) Testing: Run T:\DEPLOY.BAT TS-4R on machine that already has AUTOEXEC.BAT with SET MACHINE=OLD_NAME - should automatically update to SET MACHINE=TS-4R at line 2. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
29
DEPLOY.BAT
29
DEPLOY.BAT
@@ -287,23 +287,28 @@ ECHO.
|
||||
GOTO INSTALL_BATCH_FILES
|
||||
|
||||
:MACHINE_EXISTS
|
||||
ECHO [WARNING] MACHINE variable already exists in AUTOEXEC.BAT
|
||||
ECHO [INFO] MACHINE variable already exists in AUTOEXEC.BAT
|
||||
ECHO.
|
||||
ECHO Current AUTOEXEC.BAT contains:
|
||||
ECHO Current value:
|
||||
TYPE C:\AUTOEXEC.BAT | FIND "SET MACHINE="
|
||||
ECHO.
|
||||
ECHO Update MACHINE variable to %MACHINE%? (Y/N)
|
||||
CHOICE /C:YN /N
|
||||
IF ERRORLEVEL 2 GOTO INSTALL_BATCH_FILES
|
||||
ECHO Updating to: SET MACHINE=%MACHINE%
|
||||
ECHO.
|
||||
|
||||
REM Remove old SET MACHINE= line and insert new one at beginning
|
||||
ECHO @ECHO OFF > C:\AUTOEXEC.TMP
|
||||
ECHO SET MACHINE=%MACHINE% >> C:\AUTOEXEC.TMP
|
||||
|
||||
REM Append rest of AUTOEXEC.BAT, excluding @ECHO OFF and old SET MACHINE= lines
|
||||
TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" | FIND /V "SET MACHINE=" >> C:\AUTOEXEC.TMP
|
||||
|
||||
REM Replace original with updated version
|
||||
COPY C:\AUTOEXEC.TMP C:\AUTOEXEC.BAT >NUL
|
||||
DEL C:\AUTOEXEC.TMP
|
||||
|
||||
ECHO [OK] Updated AUTOEXEC.BAT with new machine name
|
||||
ECHO (Replaced old value, inserted at beginning)
|
||||
ECHO.
|
||||
ECHO Manual edit required:
|
||||
ECHO 1. Edit C:\AUTOEXEC.BAT
|
||||
ECHO 2. Find line: SET MACHINE=...
|
||||
ECHO 3. Change to: SET MACHINE=%MACHINE%
|
||||
ECHO 4. Save and reboot
|
||||
ECHO.
|
||||
PAUSE
|
||||
GOTO INSTALL_BATCH_FILES
|
||||
|
||||
:AUTOEXEC_ERROR
|
||||
|
||||
Reference in New Issue
Block a user