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>
This commit is contained in:
93
DEPLOY.BAT
93
DEPLOY.BAT
@@ -15,14 +15,22 @@ REM Version: 1.0 - DOS 6.22 compatible
|
||||
REM Last modified: 2026-01-19
|
||||
|
||||
CLS
|
||||
REM DEBUG: Show parameters passed to script
|
||||
ECHO.
|
||||
ECHO DEBUG: Parameter 1 = [%1]
|
||||
ECHO DEBUG: Parameter 2 = [%2]
|
||||
ECHO.
|
||||
|
||||
REM ==================================================================
|
||||
REM STEP 1: Get machine name from command line (MUST BE FIRST!)
|
||||
REM ==================================================================
|
||||
|
||||
REM Check if machine name provided as parameter
|
||||
IF "%1"=="" GOTO MACHINE_NAME_MISSING
|
||||
|
||||
REM Save parameter to variable immediately (before anything can consume it)
|
||||
SET MACHINE=%1
|
||||
|
||||
ECHO ==============================================================
|
||||
ECHO DOS Update System - One-Time Deployment
|
||||
ECHO ==============================================================
|
||||
ECHO Machine: %MACHINE%
|
||||
ECHO ==============================================================
|
||||
ECHO.
|
||||
ECHO This script will install the new update system on this machine.
|
||||
ECHO.
|
||||
@@ -37,11 +45,27 @@ ECHO.
|
||||
PAUSE
|
||||
ECHO.
|
||||
|
||||
GOTO CHECK_T_DRIVE
|
||||
|
||||
:MACHINE_NAME_MISSING
|
||||
ECHO.
|
||||
ECHO [ERROR] Machine name not provided
|
||||
ECHO.
|
||||
ECHO Usage: DEPLOY.BAT machine-name
|
||||
ECHO Example: DEPLOY.BAT TS-4R
|
||||
ECHO.
|
||||
ECHO Machine name must match folder on T: drive.
|
||||
ECHO Example: If this is TS-4R, T:\TS-4R\ must exist
|
||||
ECHO.
|
||||
PAUSE
|
||||
GOTO END
|
||||
|
||||
REM ==================================================================
|
||||
REM STEP 1: Verify T: drive is accessible
|
||||
REM STEP 2: Verify T: drive is accessible
|
||||
REM ==================================================================
|
||||
|
||||
ECHO [STEP 1/5] Checking network drive...
|
||||
:CHECK_T_DRIVE
|
||||
ECHO [STEP 2/5] Checking network drive...
|
||||
ECHO.
|
||||
|
||||
DIR T:\ >nul
|
||||
@@ -74,11 +98,11 @@ PAUSE
|
||||
GOTO END
|
||||
|
||||
REM ==================================================================
|
||||
REM STEP 2: Verify deployment files exist on network
|
||||
REM STEP 3: Verify deployment files exist on network
|
||||
REM ==================================================================
|
||||
|
||||
:CHECK_DEPLOY_FILES
|
||||
ECHO [STEP 2/5] Verifying deployment files...
|
||||
ECHO [STEP 3/5] Verifying deployment files...
|
||||
ECHO.
|
||||
|
||||
IF NOT EXIST T:\COMMON\ProdSW\NWTOC.BAT GOTO MISSING_FILES
|
||||
@@ -90,7 +114,7 @@ IF NOT EXIST T:\COMMON\ProdSW\CHECKUPD.BAT GOTO MISSING_FILES
|
||||
ECHO [OK] All deployment files found on network
|
||||
ECHO Location: T:\COMMON\ProdSW\
|
||||
ECHO.
|
||||
GOTO GET_MACHINE_NAME
|
||||
GOTO VERIFY_MACHINE_FOLDER
|
||||
|
||||
:MISSING_FILES
|
||||
ECHO [ERROR] Deployment files not found on network
|
||||
@@ -110,18 +134,11 @@ PAUSE
|
||||
GOTO END
|
||||
|
||||
REM ==================================================================
|
||||
REM STEP 3: Get machine name from command line
|
||||
REM STEP 4: Verify machine folder on network
|
||||
REM ==================================================================
|
||||
|
||||
:GET_MACHINE_NAME
|
||||
ECHO [STEP 3/5] Configure machine name...
|
||||
ECHO.
|
||||
|
||||
REM Check if machine name provided as parameter
|
||||
IF "%1"=="" GOTO MACHINE_NAME_MISSING
|
||||
|
||||
SET MACHINE=%1
|
||||
ECHO Machine name: %MACHINE%
|
||||
:VERIFY_MACHINE_FOLDER
|
||||
ECHO [STEP 4/5] Verifying machine folder...
|
||||
ECHO.
|
||||
|
||||
REM Verify machine folder exists on network
|
||||
@@ -131,19 +148,7 @@ IF NOT EXIST T:\%MACHINE%\*.* GOTO MACHINE_FOLDER_ERROR
|
||||
|
||||
ECHO [OK] Machine folder ready: T:\%MACHINE%\
|
||||
ECHO.
|
||||
GOTO BACKUP_AUTOEXEC
|
||||
|
||||
:MACHINE_NAME_MISSING
|
||||
ECHO [ERROR] Machine name not provided
|
||||
ECHO.
|
||||
ECHO Usage: DEPLOY.BAT machine-name
|
||||
ECHO Example: DEPLOY.BAT TS-4R
|
||||
ECHO.
|
||||
ECHO Machine name must match folder on T: drive.
|
||||
ECHO Example: If this is TS-4R, T:\TS-4R\ must exist
|
||||
ECHO.
|
||||
PAUSE
|
||||
GOTO END
|
||||
GOTO UPDATE_AUTOEXEC
|
||||
|
||||
:MACHINE_FOLDER_ERROR
|
||||
ECHO.
|
||||
@@ -158,14 +163,14 @@ PAUSE
|
||||
GOTO END
|
||||
|
||||
REM ==================================================================
|
||||
REM STEP 4: Backup current AUTOEXEC.BAT and install batch files
|
||||
REM STEP 5: Install batch files to C:\BAT
|
||||
REM ==================================================================
|
||||
|
||||
:BACKUP_AUTOEXEC
|
||||
ECHO [STEP 4/5] Installing update system files...
|
||||
:INSTALL_BATCH_FILES
|
||||
ECHO [STEP 5/5] Installing batch files...
|
||||
ECHO.
|
||||
|
||||
REM Backup current AUTOEXEC.BAT
|
||||
REM Backup current AUTOEXEC.BAT first
|
||||
IF NOT EXIST C:\AUTOEXEC.BAT GOTO NO_AUTOEXEC_BACKUP
|
||||
|
||||
ECHO Backing up AUTOEXEC.BAT...
|
||||
@@ -210,7 +215,7 @@ ECHO [OK] CHECKUPD.BAT
|
||||
ECHO.
|
||||
ECHO [OK] All update system files installed
|
||||
ECHO.
|
||||
GOTO UPDATE_AUTOEXEC
|
||||
GOTO DEPLOYMENT_COMPLETE
|
||||
|
||||
:BACKUP_ERROR
|
||||
ECHO.
|
||||
@@ -242,11 +247,11 @@ PAUSE
|
||||
GOTO END
|
||||
|
||||
REM ==================================================================
|
||||
REM STEP 5: Update AUTOEXEC.BAT with MACHINE variable
|
||||
REM STEP 4: Update AUTOEXEC.BAT with MACHINE variable
|
||||
REM ==================================================================
|
||||
|
||||
:UPDATE_AUTOEXEC
|
||||
ECHO [STEP 5/5] Updating AUTOEXEC.BAT...
|
||||
ECHO [STEP 4/5] Updating AUTOEXEC.BAT...
|
||||
ECHO.
|
||||
|
||||
REM Check if MACHINE variable already exists in AUTOEXEC.BAT
|
||||
@@ -263,7 +268,7 @@ IF ERRORLEVEL 1 GOTO AUTOEXEC_ERROR
|
||||
|
||||
ECHO [OK] Added to AUTOEXEC.BAT: SET MACHINE=%MACHINE%
|
||||
ECHO.
|
||||
GOTO DEPLOYMENT_COMPLETE
|
||||
GOTO INSTALL_BATCH_FILES
|
||||
|
||||
:MACHINE_EXISTS
|
||||
ECHO [WARNING] MACHINE variable already exists in AUTOEXEC.BAT
|
||||
@@ -273,7 +278,7 @@ TYPE C:\AUTOEXEC.BAT | FIND "SET MACHINE="
|
||||
ECHO.
|
||||
ECHO Update MACHINE variable to %MACHINE%? (Y/N)
|
||||
CHOICE /C:YN /N
|
||||
IF ERRORLEVEL 2 GOTO DEPLOYMENT_COMPLETE
|
||||
IF ERRORLEVEL 2 GOTO INSTALL_BATCH_FILES
|
||||
|
||||
ECHO.
|
||||
ECHO Manual edit required:
|
||||
@@ -283,7 +288,7 @@ ECHO 3. Change to: SET MACHINE=%MACHINE%
|
||||
ECHO 4. Save and reboot
|
||||
ECHO.
|
||||
PAUSE
|
||||
GOTO DEPLOYMENT_COMPLETE
|
||||
GOTO INSTALL_BATCH_FILES
|
||||
|
||||
:AUTOEXEC_ERROR
|
||||
ECHO.
|
||||
@@ -293,7 +298,7 @@ ECHO You must manually add this line to C:\AUTOEXEC.BAT:
|
||||
ECHO SET MACHINE=%MACHINE%
|
||||
ECHO.
|
||||
PAUSE
|
||||
GOTO DEPLOYMENT_COMPLETE
|
||||
GOTO INSTALL_BATCH_FILES
|
||||
|
||||
REM ==================================================================
|
||||
REM DEPLOYMENT COMPLETE
|
||||
|
||||
Reference in New Issue
Block a user