@ECHO OFF
REM ATESYNC.BAT - ATE Sync Orchestrator (ARCHBAT equivalent)
REM Version: 1.1 - DOS 6.22 compatible
REM Last modified: 2026-01-21
REM
REM Called from AUTOEXEC.BAT after network is up
REM Usage: ATESYNC TS-27
REM   or:  ATESYNC (uses MACHINE environment variable)

REM Get machine name from parameter or environment
IF NOT "%1"=="" SET MACHINE=%1
IF "%MACHINE%"=="" GOTO NO_MACHINE

REM Verify T: drive is available
IF NOT EXIST T:\*.* GOTO NO_DRIVE

REM Verify machine folder exists on network
IF NOT EXIST T:\%MACHINE%\*.* GOTO CREATE_MACHINE

:START_SYNC
ECHO.
ECHO ************************************************************
ECHO ATESYNC: %MACHINE%
ECHO ************************************************************
ECHO.

REM Step 1: Upload test results FIRST (before downloading updates)
ECHO Sending test results to network...
CALL CTONW.BAT
ECHO.

REM Step 2: Download software updates
ECHO Getting updates from network...
CALL NWTOC.BAT
ECHO.

ECHO ************************************************************
ECHO ATESYNC Complete: %MACHINE%
ECHO ************************************************************
ECHO.
GOTO END

:CREATE_MACHINE
ECHO Creating machine folder T:\%MACHINE%
MD T:\%MACHINE%
IF NOT EXIST T:\%MACHINE%\*.* GOTO MACHINE_ERROR
MD T:\%MACHINE%\LOGS
MD T:\%MACHINE%\LOGS\5BLOG
MD T:\%MACHINE%\LOGS\7BLOG
MD T:\%MACHINE%\LOGS\8BLOG
MD T:\%MACHINE%\LOGS\DSCLOG
MD T:\%MACHINE%\LOGS\HVLOG
MD T:\%MACHINE%\LOGS\PWRLOG
MD T:\%MACHINE%\LOGS\SCTLOG
MD T:\%MACHINE%\LOGS\VASLOG
MD T:\%MACHINE%\ProdSW
MD T:\%MACHINE%\Reports
ECHO Machine folder created
GOTO START_SYNC

:NO_MACHINE
ECHO.
ECHO ************************************************************
ECHO ERROR: MACHINE not set
ECHO.
ECHO Usage: ATESYNC TS-27
ECHO    or: SET MACHINE=TS-27
ECHO        ATESYNC
ECHO ************************************************************
PAUSE
GOTO END

:NO_DRIVE
ECHO.
ECHO ERROR: T: drive not available
ECHO Run STARTNET.BAT first
PAUSE
GOTO END

:MACHINE_ERROR
ECHO.
ECHO ERROR: Could not create T:\%MACHINE%
ECHO Check network permissions
PAUSE
GOTO END

:END
