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>
60 lines
1.7 KiB
PowerShell
60 lines
1.7 KiB
PowerShell
# 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 ""
|