@ECHO OFF
REM DOSTEST.BAT - Test DOS batch file deployment
REM Run this on the DOS machine after deploying new files
REM Version: 1.2 - DOS 6.22 compatible (removed brackets, 2>NUL, NUL checks)
REM Last modified: 2026-01-21

ECHO.
ECHO ==============================================================
ECHO   DOS 6.22 Configuration Test Script
ECHO ==============================================================
ECHO.

REM ==================================================================
REM TEST 1: Check MACHINE variable
REM ==================================================================

ECHO (TEST 1) Checking MACHINE variable...

IF "%MACHINE%"=="" GOTO TEST1_FAIL
ECHO OK: MACHINE=%MACHINE%
GOTO TEST2

:TEST1_FAIL
ECHO FAIL: MACHINE variable not set
ECHO Fix: Add "SET MACHINE=TS-4R" to C:\AUTOEXEC.BAT
ECHO.
PAUSE
GOTO TEST2

REM ==================================================================
REM TEST 2: Check required files exist
REM ==================================================================

:TEST2
ECHO.
ECHO (TEST 2) Checking required files...

IF NOT EXIST C:\AUTOEXEC.BAT ECHO FAIL: C:\AUTOEXEC.BAT missing
IF EXIST C:\AUTOEXEC.BAT ECHO OK: C:\AUTOEXEC.BAT exists

IF NOT EXIST C:\STARTNET.BAT ECHO FAIL: C:\STARTNET.BAT missing
IF EXIST C:\STARTNET.BAT ECHO OK: C:\STARTNET.BAT exists

IF NOT EXIST C:\BAT\*.* ECHO WARN: C:\BAT directory missing - run MD C:\BAT
IF EXIST C:\BAT\*.* ECHO OK: C:\BAT directory exists

REM ==================================================================
REM TEST 3: Check PATH variable
REM ==================================================================

ECHO.
ECHO (TEST 3) Checking PATH...
ECHO PATH=%PATH%

REM ==================================================================
REM TEST 4: Check T: drive
REM ==================================================================

ECHO.
ECHO (TEST 4) Checking T: drive...

IF NOT EXIST T:\*.* GOTO TEST4_FAIL

ECHO OK: T: drive accessible
GOTO TEST5

:TEST4_FAIL
ECHO FAIL: T: drive not accessible
ECHO Fix: Run C:\STARTNET.BAT to map network drives
GOTO TEST5

REM ==================================================================
REM TEST 5: Check X: drive
REM ==================================================================

:TEST5
ECHO.
ECHO (TEST 5) Checking X: drive...

IF NOT EXIST X:\*.* GOTO TEST5_FAIL

ECHO OK: X: drive accessible
GOTO TEST6

:TEST5_FAIL
ECHO FAIL: X: drive not accessible
ECHO Fix: Run C:\STARTNET.BAT to map network drives
GOTO TEST6

REM ==================================================================
REM TEST 6: Check if backup directory can be created
REM ==================================================================

:TEST6
ECHO.
ECHO (TEST 6) Checking backup directory creation...

IF "%MACHINE%"=="" GOTO TEST6_SKIP

REM Only test if T: is available
IF NOT EXIST T:\*.* GOTO TEST6_SKIP

REM Try to create machine directory
IF NOT EXIST T:\%MACHINE%\*.* MD T:\%MACHINE%
IF NOT EXIST T:\%MACHINE%\*.* GOTO TEST6_FAIL

REM Try to create test subdirectory
IF NOT EXIST T:\%MACHINE%\TEST\*.* MD T:\%MACHINE%\TEST
IF NOT EXIST T:\%MACHINE%\TEST\*.* GOTO TEST6_FAIL

ECHO OK: Can create T:\%MACHINE%\TEST
ECHO OK: Backup directory structure works

REM Clean up test directory
RD T:\%MACHINE%\TEST

GOTO SUMMARY

:TEST6_FAIL
ECHO FAIL: Cannot create directory on T: drive
ECHO Check: T: drive is writable
GOTO SUMMARY

:TEST6_SKIP
ECHO SKIP: Cannot test (T: unavailable or MACHINE not set)
GOTO SUMMARY

REM ==================================================================
REM SUMMARY
REM ==================================================================

:SUMMARY
ECHO.
ECHO ==============================================================
ECHO   Test Summary
ECHO ==============================================================
ECHO.

IF "%MACHINE%"=="" GOTO SUMMARY_FAIL
IF NOT EXIST C:\BAT\*.* GOTO SUMMARY_FAIL
IF NOT EXIST T:\*.* GOTO SUMMARY_FAIL

ECHO OK: All critical tests passed
ECHO.
ECHO Configuration appears correct.
ECHO.
ECHO Next step: Run UPDATE to test backup
ECHO   C:\>UPDATE
ECHO.
GOTO END

:SUMMARY_FAIL
ECHO FAIL: One or more tests failed
ECHO.
ECHO Please fix the failed tests before running UPDATE
ECHO.
ECHO Common fixes:
ECHO   1. Reboot machine (load AUTOEXEC.BAT changes)
ECHO   2. Run C:\STARTNET.BAT (map network drives)
ECHO   3. Check network cable is connected
ECHO   4. Create C:\BAT directory: MD C:\BAT
ECHO.

:END
ECHO ==============================================================
ECHO.
PAUSE
