Commit Graph

1 Commits

Author SHA1 Message Date
13bf3da767 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>
2026-01-19 17:47:36 -07:00