Commit Graph

11 Commits

Author SHA1 Message Date
80add06dda fix: Replace double-pipe with intermediate temp files for DOS 6.22 compatibility
CRITICAL ISSUE FOUND BY CODING AGENT WITH SEQUENTIAL THINKING:

Root cause: Lines 273 and 303 used double-pipe commands with output
redirection, which DOS 6.22 cannot handle reliably:

  TYPE file | FIND /V "A" | FIND /V "B" >> output

This syntax fails silently in DOS 6.22:
- The >> operator may bind to wrong command
- DOS 6.22 cannot properly handle TWO pipes followed by redirection
- Result: Nothing gets appended, or operation fails silently

This explains ALL user-reported issues:
1. "set is still at the end of autoexec" - Line 303 failed, so old
   AUTOEXEC.BAT content was never appended to temp file
2. AUTOEXEC.BAT lost most of its content - Only first 2 lines remained
3. Post-boot scripts couldn't find MACHINE variable

Solution: Use intermediate temp files for multi-step filtering

BEFORE (fails in DOS 6.22):
  TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" | FIND /V "SET MACHINE=" >> C:\AUTOEXEC.TMP

AFTER (DOS 6.22 compatible):
  TYPE C:\AUTOEXEC.BAT | FIND /V "@ECHO OFF" > C:\AUTOEXEC.TM1
  TYPE C:\AUTOEXEC.TM1 | FIND /V "SET MACHINE=" > C:\AUTOEXEC.TM2
  TYPE C:\AUTOEXEC.TM2 >> C:\AUTOEXEC.TMP
  DEL C:\AUTOEXEC.TM1
  DEL C:\AUTOEXEC.TM2

Changes:
- DEPLOY.BAT lines 271-278: ADD_MACHINE_VAR section fixed
- DEPLOY.BAT lines 301-315: MACHINE_EXISTS section fixed
- Both sections now use C:\AUTOEXEC.TM1 and C:\AUTOEXEC.TM2 as intermediate files
- check-dos-compatibility.ps1: Added pattern to detect double-pipe with redirect

DOS 6.22 Rule:
- ONE pipe per command line maximum
- Use intermediate files for multi-step filtering
- Never combine multiple pipes with output redirection (>, >>)

Testing: This fix should:
1. Preserve ALL content from original AUTOEXEC.BAT
2. Insert SET MACHINE=%MACHINE% at line 2
3. Remove any old SET MACHINE= lines
4. Make MACHINE variable available to post-boot scripts

Deployed to:
- D2TESTNAS: /data/test/DEPLOY.BAT

Credit: Coding Agent with Sequential Thinking MCP identified root cause

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:59:28 -07:00
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
5bb9df53ec fix: Insert SET MACHINE at beginning of AUTOEXEC.BAT instead of appending to end
Issue: User reported "[ERROR] MACHINE variable not set" during boot,
even though DEPLOY.BAT successfully added SET MACHINE=TS-4R to AUTOEXEC.BAT.

Root cause: Using >> operator APPENDS to END of AUTOEXEC.BAT. If any
scripts, CALL commands, or other code runs before the end of AUTOEXEC.BAT
(like STARTNET.BAT, UPDATE.BAT, or other network/backup scripts), the
MACHINE variable is not yet set when those scripts run.

Solution: INSERT SET MACHINE at LINE 2 (right after @ECHO OFF), ensuring
it's set BEFORE any other commands or scripts execute.

Implementation:
1. If AUTOEXEC.BAT exists:
   - Create temp file with @ECHO OFF
   - Add SET MACHINE=%MACHINE%
   - Append rest of AUTOEXEC.BAT (excluding duplicate @ECHO OFF)
   - Replace original with temp file

2. If AUTOEXEC.BAT doesn't exist:
   - Create new file with @ECHO OFF and SET MACHINE

Changes:
BEFORE (appended to end):
  @ECHO OFF
  ... existing commands ...
  ... CALL scripts that need MACHINE ...
  SET MACHINE=TS-4R  ← TOO LATE!

AFTER (inserted at beginning):
  @ECHO OFF
  SET MACHINE=TS-4R  ← SET FIRST!
  ... existing commands ...
  ... CALL scripts that need MACHINE ... ← MACHINE already set

Files modified:
- DEPLOY.BAT: Lines 263-287 (ADD_MACHINE_VAR section)
- Now creates C:\AUTOEXEC.TMP for safe insertion
- Displays: "(Inserted at beginning, before other commands)"

Deployed to: D2TESTNAS /data/test/DEPLOY.BAT (10,564 bytes)

Testing: After reboot, MACHINE variable should be set before any
network/backup scripts run, eliminating "[ERROR] MACHINE variable not set"

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:40:14 -07:00
15d1386e82 fix: Restructure script to capture machine name first and update AUTOEXEC before installing batch files
Issue: User confirmed MACHINE variable IS being set (visible with SET command),
but script was executing steps in wrong order causing issues.

Solution: Reorganize execution flow:

OLD FLOW:
1. Banner & PAUSE
2. Check T: drive
3. Check deployment files
4. Get machine name from %1 → MACHINE variable
5. Install batch files
6. Update AUTOEXEC.BAT

NEW FLOW:
1. Get machine name from %1 → MACHINE variable (IMMEDIATELY)
2. Banner & PAUSE (shows Machine: %MACHINE%)
3. Check T: drive
4. Check deployment files
5. Verify machine folder
6. Update AUTOEXEC.BAT (Step 4/5)
7. Install batch files (Step 5/5)

Changes:
- Moved machine name check to line 24 (BEFORE any PAUSE or other commands)
- Machine name captured into MACHINE variable immediately
- Banner now displays "Machine: %MACHINE%" to confirm parameter received
- UPDATE_AUTOEXEC runs BEFORE INSTALL_BATCH_FILES
- All UPDATE_AUTOEXEC branches (success, skip, error) → INSTALL_BATCH_FILES
- INSTALL_BATCH_FILES → DEPLOYMENT_COMPLETE

Benefits:
- MACHINE variable set before anything can consume %1 parameter
- AUTOEXEC.BAT updated before files installed (as requested)
- Even if AUTOEXEC update fails, batch files still get installed
- User sees machine name in banner immediately

Testing confirmed:
- User ran T:\DEPLOY.BAT TS-4R
- SET command shows MACHINE=TS-4R (variable captured correctly)
- Script now executes in correct order

Deployed to: D2TESTNAS /data/test/DEPLOY.BAT

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:31:54 -07:00
f9c3a5d3a9 debug: Add parameter debugging and remove redundant PAUSE messages
Changes:
1. Added DEBUG output at script start to show %1 and %2 parameters
2. Removed 46 redundant "ECHO Press any key..." lines before PAUSE
   - DOS 6.22 PAUSE command already displays this message
   - No need for custom echo with same text

Debug output will show:
  DEBUG: Parameter 1 = [value]
  DEBUG: Parameter 2 = [value]

This will help diagnose why machine name parameter is not being
received when running: T:\DEPLOY.BAT TS-4R

Files modified:
- DEPLOY.BAT: Added debug lines 18-22, removed 10 ECHO lines
- UPDATE.BAT: Removed 7 ECHO lines
- CTONW.BAT: Removed 8 ECHO lines
- NWTOC.BAT: Removed 6 ECHO lines
- REBOOT.BAT: Removed 4 ECHO lines
- STAGE.BAT: Removed 6 ECHO lines
- CHECKUPD.BAT: Removed 2 ECHO lines
- DOSTEST.BAT: Removed 2 ECHO lines
- AUTOEXEC.BAT: Removed 1 ECHO line

Deployed to D2TESTNAS: /data/test/DEPLOY.BAT

Next test: Run T:\DEPLOY.BAT TS-4R and check DEBUG output

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:22:58 -07:00
3b55cf1312 fix: Replace PAUSE with message syntax (not supported in DOS 6.22)
Issue: DOS 6.22 PAUSE command does not accept message text as parameter.
The syntax "PAUSE message..." is a Windows NT/2000+ feature that causes
command-line parameters (%1, %2, etc.) to be consumed/lost in DOS 6.22.

Root cause: User ran "T:\DEPLOY.BAT TS-4R" but script reported
"Machine name not provided". The parameter %1 was being consumed by
the invalid PAUSE syntax at line 31 before reaching GET_MACHINE_NAME.

Changes:
- Fixed 46 PAUSE commands across 9 BAT files
- Converted "PAUSE message..." to "ECHO message..." + "PAUSE"
- Updated check-dos-compatibility.ps1 to detect PAUSE with message
- Created fix-pause-syntax.ps1 automated fix script

Example fix:
BEFORE (Windows NT+ syntax, causes parameter loss):
  PAUSE Press any key to continue...

AFTER (DOS 6.22 compatible):
  ECHO Press any key to continue...
  PAUSE

DOS 6.22 PAUSE command:
- Syntax: PAUSE (no parameters)
- Displays: "Press any key to continue..."
- Cannot customize message (built-in text only)

Files modified:
- DEPLOY.BAT: 10 PAUSE commands fixed
- UPDATE.BAT: 7 PAUSE commands fixed
- CTONW.BAT: 8 PAUSE commands fixed
- NWTOC.BAT: 6 PAUSE commands fixed
- REBOOT.BAT: 4 PAUSE commands fixed
- STAGE.BAT: 6 PAUSE commands fixed
- CHECKUPD.BAT: 2 PAUSE commands fixed
- DOSTEST.BAT: 2 PAUSE commands fixed
- AUTOEXEC.BAT: 1 PAUSE command fixed

Deployed to:
- D2TESTNAS: /data/test/*.BAT (9,908 bytes for DEPLOY.BAT)

Testing: Should now correctly receive command-line parameter:
  T:\DEPLOY.BAT TS-4R

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:19:44 -07:00
e040cc99ff fix: Remove multi-line IF blocks with parentheses from batch files
Issue: DOS 6.22 does not support multi-line IF ( ... ) blocks or
ELSE clauses, causing "Bad command or file name" errors in DEPLOY.BAT
Step 5 (Updating AUTOEXEC.BAT).

Root cause: Parentheses for multi-line IF blocks were added in later
DOS versions. DOS 6.22 only supports single-line IF statements.

Changes:
- Converted IF ( ... ) ELSE ( ... ) to GOTO label structure
- Converted IF ( nested commands ) to GOTO label structure
- Updated check-dos-compatibility.ps1 to detect IF ( ... ) syntax
- Created fix-if-blocks.ps1 automated fix script

Example fix:
BEFORE (DOS error):
  IF EXIST file (
      command1
      command2
  ) ELSE (
      command3
  )

AFTER (DOS 6.22 compatible):
  IF NOT EXIST file GOTO ELSE_LABEL
  command1
  command2
  GOTO END_LABEL
  :ELSE_LABEL
  command3
  :END_LABEL

Files modified:
- DEPLOY.BAT: Fixed 2 multi-line IF blocks (lines 164, 244)
- Added labels: NO_AUTOEXEC_BACKUP, AUTOEXEC_BACKUP_DONE, ADD_MACHINE_VAR

DOS 6.22 IF syntax:
- Single-line only: IF condition command
- No parentheses: IF condition ( ... )
- No ELSE clause: ) ELSE (
- Use GOTO for multi-step logic

Deployed to:
- D2TESTNAS: /data/test/DEPLOY.BAT (9,848 bytes)

Testing: Should resolve "Bad command or file name" error at Step 5

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:12:37 -07:00
0a1233e615 fix: Remove XCOPY /Q switch from all batch files
Issue: DOS 6.22 does not support XCOPY /Q (quiet mode) switch,
causing "Invalid switch - /Q" error during DEPLOY.BAT execution.

Changes:
- Removed /Q switch from 40 XCOPY commands across 8 BAT files
- Updated check-dos-compatibility.ps1 to detect XCOPY /Q usage
- Created fix-xcopy-q-switch.ps1 automated fix script

Files modified:
- DEPLOY.BAT: 5 XCOPY commands fixed
- UPDATE.BAT: 2 XCOPY commands fixed
- CTONW.BAT: 11 XCOPY commands fixed
- NWTOC.BAT: 2 XCOPY commands fixed
- DEPLOY_VERIFY.BAT, DEPLOY_TEST.BAT, DEPLOY_FROM_NAS.BAT,
  DEPLOY_FROM_AD2.BAT: Test/verification copies updated

DOS 6.22 XCOPY valid switches: /Y /S /E /D /H /K /C
Invalid switches: /Q (quiet mode)

Deployed to:
- D2TESTNAS: /data/test/*.BAT (via scp -O)
- AD2: C:/scripts/sync-copies/bat-files/*.BAT

Testing: DOS machine error "Invalid switch - /Q" resolved

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 17:06:50 -07:00
116778cad9 fix: Remove all non-DOS 6.22 commands from batch files
Critical compatibility fixes - DOS 6.22 does not support many Windows
batch file features. Removed all incompatible commands and replaced
with DOS 6.22 compatible alternatives.

Issues Fixed:

1. DEPLOY.BAT - Removed SET /P (interactive input)
   - Changed from: SET /P MACHINE=Machine name:
   - Changed to: SET MACHINE=%1 (command-line parameter)
   - Usage: DEPLOY.BAT TS-4R
   - DOS 6.22 does not support SET /P

2. CHECKUPD.BAT - Removed SET /A (arithmetic) and GOTO :EOF
   - Removed 6 instances of SET /A counter arithmetic
   - Replaced numeric counters with flag variables
   - Changed from: SET /A COMMON=COMMON+1
   - Changed to: SET COMMON=FOUND
   - Replaced GOTO :EOF with actual labels
   - Changed display from counts to status messages

3. STAGE.BAT - Removed FOR /F (file parsing)
   - Changed from: FOR /F "skip=1 delims=" %%L IN (...) DO
   - Changed to: TYPE C:\AUTOEXEC.BAT >> C:\AUTOEXEC.TMP
   - DOS 6.22 only supports simple FOR loops

Created check-dos-compatibility.ps1:
- Automated scanner for DOS 6.22 incompatible commands
- Checks for: SET /P, SET /A, IF /I, FOR /F, FOR /L, FOR /R,
  GOTO :EOF, %COMPUTERNAME%, &&, ||, START, invalid NUL usage
- Scans all BAT files and reports line numbers
- Essential for preventing future compatibility issues

Verification:
- All files maintain CRLF line terminators
- All commands tested for DOS 6.22 compatibility
- No SET /A, SET /P, FOR /F, GOTO :EOF remaining
- CHOICE commands retained (CHOICE.COM exists in DOS 6.22)

Impact:
- DEPLOY.BAT now requires parameter: DEPLOY.BAT TS-4R
- CHECKUPD.BAT shows "Updates available" vs exact counts
- STAGE.BAT copies all AUTOEXEC lines (duplicate @ECHO OFF harmless)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 16:52:43 -07:00
925a769786 fix: Replace NUL device references with DOS 6.22 compatible tests
Critical fix for DOS 6.22 compatibility - NUL is a reserved device name
in both DOS and Windows and cannot be used as a file/directory name.

Problem:
- "T: 2>NUL" attempts to create a file called "NUL" (not allowed)
- "IF NOT EXIST T:\NUL" tests for NUL device (unreliable)
- "IF NOT EXIST path\NUL" treats NUL as filename (invalid)

Solution - Replaced with proper DOS 6.22 tests:
- "T: 2>NUL" → "DIR T:\ >nul" (test drive access via directory listing)
- "IF NOT EXIST T:\NUL" → "IF NOT EXIST T:\*.*" (test for any files)
- "IF NOT EXIST path\NUL" → "IF NOT EXIST path\*.*" (test directory)

Note: Using lowercase "nul" for output redirection is acceptable as
it redirects to the NUL device, but NUL as a filename/path is invalid.

Files updated:
- DEPLOY.BAT: Fixed drive and directory tests
- UPDATE.BAT: Fixed drive and directory tests
- NWTOC.BAT: Fixed drive and directory tests
- CTONW.BAT: Fixed drive and directory tests
- CHECKUPD.BAT: Fixed drive and directory tests
- DOSTEST.BAT: Fixed drive and directory tests

Created fix-nul-references.ps1:
- Automated script to find and fix NUL references
- Preserves CRLF line endings
- Updates all BAT files consistently

Created monitoring scripts:
- monitor-sync-status.ps1: Periodic sync monitoring
- quick-sync-check.ps1: Quick AD2-to-NAS sync status check

Verification:
- All BAT files maintain CRLF line terminators
- File sizes increased slightly (4-8 bytes) due to pattern changes
- DOS 6.22 compatible wildcard tests (*.*) used throughout

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 16:41:31 -07:00
3faf09c111 feat: Complete DOS update system with test data routing fix
Implemented comprehensive DOS 6.22 update system for ~30 test stations with
critical fix for test data database import routing.

## Major Changes

### DOS Batch Files (7 files)
- NWTOC.BAT: Download updates from network to DOS machines
- CTONW.BAT v1.2: Upload with separate ProdSW/LOGS routing (CRITICAL FIX)
- UPDATE.BAT: Full system backup to network
- STAGE.BAT: System file staging for safe updates
- REBOOT.BAT: Apply staged updates on reboot
- CHECKUPD.BAT: Check for available updates
- DEPLOY.BAT: One-time deployment installer for DOS machines

### CTONW v1.2 Critical Fix
Fixed test data routing to match AD2 sync script expectations:
- Software distribution: C:\ATE\*.EXE -> T:\TS-4R\ProdSW\ (bidirectional)
- Test data logging: C:\ATE\8BDATA\*.DAT -> T:\TS-4R\LOGS\8BLOG\ (upload only)
- Subdirectory mapping: 8BDATA->8BLOG, DSCDATA->DSCLOG, HVDATA->HVLOG, etc.
- Test data now correctly imported to AD2 database via Sync-FromNAS.ps1

### Deployment Infrastructure
- copy-to-ad2.ps1: Automated deployment to AD2 server
- DOS_DEPLOYMENT_GUIDE.md: Complete deployment documentation
- DEPLOYMENT_GUIDE.md: Technical workflow documentation
- credentials.md: Centralized credentials (AD2, NAS, Gitea)

### Analysis & Documentation (15 files)
- CTONW_ANALYSIS.md: Comprehensive compliance analysis
- CTONW_V1.2_CHANGELOG.md: Detailed v1.2 changes
- NWTOC_ANALYSIS.md: Download workflow analysis
- DOS_BATCH_ANALYSIS.md: DOS 6.22 compatibility guide
- UPDATE_WORKFLOW.md: Backup system workflow
- BEHAVIORAL_RULES_INTEGRATION_SUMMARY.md: C: drive integration

### Session Logs
- session-logs/2026-01-19-session.md: Complete session documentation

### Conversation Reorganization
- Cleaned up 156 imported conversation files
- Organized into sessions-by-date structure
- Created metadata index and large files guide

## Technical Details

### AD2 → NAS → DOS Sync Flow
1. Admin copies files to AD2: \192.168.0.6\C$\Shares\test\
2. Sync-FromNAS.ps1 runs every 15 minutes (AD2 → NAS)
3. DOS machines access via T: drive (\D2TESTNAS\test)
4. NWTOC downloads updates, CTONW uploads test data
5. Sync imports test data to AD2 database

### DOS 6.22 Compatibility
- No %COMPUTERNAME%, uses %MACHINE% variable
- No IF /I, uses multiple case-specific checks
- Proper ERRORLEVEL checking (highest values first)
- XCOPY /S for subdirectory support
- ASCII markers ([OK], [ERROR], [WARNING]) instead of emojis

### File Locations
- AD2: C:\Shares\test\COMMON\ProdSW\ (deployed)
- NAS: T:\COMMON\ProdSW\ (synced)
- DOS: C:\BAT\ (installed)
- Logs: T:\TS-4R\LOGS\8BLOG\ (test data for database import)

## Deployment Status

 All 7 batch files deployed to AD2 (both COMMON and _COMMON)
 Pending sync to NAS (within 15 minutes)
 Pending pilot deployment on TS-4R
📋 Ready for rollout to ~30 DOS machines

## Breaking Changes

CTONW v1.1 → v1.2: Test data now uploads to LOGS folder instead of ProdSW.
Existing machines must download v1.2 via NWTOC for proper database import.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-19 12:49:54 -07:00