From 13bf3da767d33a3502e04095b5c5da1dffb498f6 Mon Sep 17 00:00:00 2001 From: Mike Swanson Date: Mon, 19 Jan 2026 17:47:36 -0700 Subject: [PATCH] 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 --- DEPLOY.BAT | 29 +++++++++++++---------- deploy-to-ad2.ps1 | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 deploy-to-ad2.ps1 diff --git a/DEPLOY.BAT b/DEPLOY.BAT index 11bf299..aaaaba4 100644 --- a/DEPLOY.BAT +++ b/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 diff --git a/deploy-to-ad2.ps1 b/deploy-to-ad2.ps1 new file mode 100644 index 0000000..1c25bf8 --- /dev/null +++ b/deploy-to-ad2.ps1 @@ -0,0 +1,59 @@ +# Deploy fixed BAT files to AD2 via WinRM +# This prevents sync from overwriting our DOS 6.22 fixes + +$BATFiles = @( + "DEPLOY.BAT", + "UPDATE.BAT", + "NWTOC.BAT", + "CTONW.BAT", + "CHECKUPD.BAT", + "REBOOT.BAT", + "STAGE.BAT", + "DOSTEST.BAT", + "AUTOEXEC.BAT", + "STARTNET.BAT" +) + +Write-Host "[INFO] Deploying fixed BAT files to AD2" -ForegroundColor Cyan +Write-Host "" + +# Create credential +$Password = ConvertTo-SecureString "AZC0mpGuru!2024" -AsPlainText -Force +$Credential = New-Object System.Management.Automation.PSCredential("guru", $Password) + +# Create session +Write-Host "Connecting to AD2..." -ForegroundColor White +$Session = New-PSSession -ComputerName ad2 -Credential $Credential -ErrorAction Stop +Write-Host "[OK] Connected to AD2" -ForegroundColor Green +Write-Host "" + +$TotalCopied = 0 + +foreach ($File in $BATFiles) { + $LocalPath = "D:\ClaudeTools\$File" + + if (-not (Test-Path $LocalPath)) { + Write-Host "[SKIP] $File - not found locally" -ForegroundColor Yellow + continue + } + + Write-Host "Copying: $File" -ForegroundColor White + + try { + Copy-Item $LocalPath -Destination "C:\scripts\sync-copies\bat-files\" -ToSession $Session -ErrorAction Stop + Write-Host " [OK] Copied to AD2" -ForegroundColor Green + $TotalCopied++ + } catch { + Write-Host " [ERROR] Failed: $_" -ForegroundColor Red + } +} + +# Close session +Remove-PSSession $Session + +Write-Host "" +Write-Host "[SUCCESS] Copied $TotalCopied files to AD2" -ForegroundColor Green +Write-Host "" +Write-Host "AD2 path: C:\scripts\sync-copies\bat-files\" -ForegroundColor Cyan +Write-Host "Next sync will deploy these fixed versions to NAS" -ForegroundColor Cyan +Write-Host ""