@echo off
setlocal
if "%1" == "" goto usage
echo.
echo The entire c:\nt directory and subdirectories will be created/overwritten:
echo.
echo Type CTRL-C to abort installation.
echo Hitting any other key will continue installation.
echo.
pause

if "%1" == "I386" goto I386
if "%1" == "i386" goto I386
goto usage

:I386

@rem Initialize defaults: no tools, old-style debugger
set _sys=i386
set _mstools=0
set _newdbg=0

@echo Parsing arguments...
shift
:LOOP
if "%1"=="" goto EXITLOOP
if "%1"=="mstools" set _mstools=1
if "%1"=="MSTOOLS" set _mstools=1
if "%1"=="newdbg" set _newdbg=1
if "%1"=="NEWDBG" set _newdbg=1
shift
goto LOOP
:EXITLOOP

.\install\delnode /q c:\nt > nul

echo Copying NT for i386 CPU...

mkdir c:\nt
.\install\tc %_sys%\nt c:\nt
@rem Make sure files are not read-only after install
.\install\walk /f c:\nt .\install\chmode -r %%s > nul

if not errorlevel 1 goto c1
echo ERROR: Unable to xcopy all system files to c:\nt. Installation failed.
echo Likely insufficient disk space. Fix problem and rerun setup.
goto exit
:c1

copy readme.txt c:\nt

mkdir c:\nt\tmp

if %_newdbg%==1 goto i386kd

copy %_sys%\ntoskrnl.exe	c:\
goto i386done

:i386kd
echo Copying new nt kernel debugger...
copy %_sys%\debug\ntoskrnl.exe	      c:\

:i386done

if exist c:\os2ldr.os2 goto cont

.\install\chmode -rhs c:\os2ldr.

if not errorlevel 1 goto c2
echo ERROR: Using CHMODE.EXE utility. Problem unhidding OS2LDR.  Installation
echo failed. Fix problem and rerun setup.
goto exit

:c2

@rem note there is a limitation in rename that there is no path names
@rem allowed before the given filenames, so we will use mv instead

.\install\mv c:\os2ldr. c:\os2ldr.os2 >nul

:cont
copy %_sys%\os2ldr.nt c:\ >nul
copy .\install\os2ldr.dul c:\os2ldr.

if %_mstools%==0 goto done

echo Copying Win32 development files...

mkdir c:\nt\mstools
mkdir c:\nt\mstools\bin
mkdir c:\nt\mstools\h
mkdir c:\nt\mstools\lib
mkdir c:\nt\mstools\samples

copy  .\mstools\setenv.cmd	c:\nt\mstools
copy  .\mstools\sdktools.grp	c:\nt\windows
copy  .\mstools\sdktools.ini	c:\nt\windows\progman.ini
copy  .\mstools\bin\%_sys%	c:\nt\mstools\bin

if not errorlevel 1 goto c3
echo ERROR: Problem installing mstools binaries. Likely cause insufficient
echo disk space. Fix problem and rerun setup.
goto exit
:c3

.\install\tc .\mstools\h	c:\nt\mstools\h

if not errorlevel 1 goto c4
echo ERROR: Problem installing mstools header files. Likely cause insufficient
echo disk space. Fix problem and rerun setup.
goto exit
:c4

copy  .\mstools\lib\%_sys%	c:\nt\mstools\lib

if not errorlevel 1 goto c5
echo ERROR: Problem installing mstools lib files. Likely cause insufficient
echo disk space. Fix problem and rerun setup.
goto exit
:c5

.\install\tc .\mstools\samples c:\nt\mstools\samples

if not errorlevel 1 goto c6
echo ERROR: Problem installing mstools sample files. Likely cause insufficient
echo disk space. Fix problem and rerun setup.
goto exit
:c6

@rem Make sure files are not read-only after install
.\install\walk /f c:\nt\mstools .\install\chmode -r %%s > nul

@rem Temporary OS/2 hosted nt dev files
mkdir c:\nt\mstools\bin\os2
copy .\mstools\bin\os2 c:\nt\mstools\bin\os2

if not errorlevel 1 goto c7
echo ERROR: Problem installing mstools OS/2-based Win32 development files.
echo Likely cause insufficient disk space. Fix problem and rerun setup.
goto exit
:c7

:done
echo ALL NT FILES ARE INSTALLED!
echo.
echo BE SURE TO VERIFY THAT OS2LDR.NT IS CONTIGUOUS!!!
echo Running chkdsk to determine if os2ldr.nt is contiguous...
chkdsk c:\os2ldr.nt

goto exit

:usage
echo.
echo Usage: setup [system] {mstools} {newdbg}
echo system: Specifies i386 or mips. Currently, only i386 is supported.
echo mstools: Optional parameter for Win32 development files
echo newdbg: Optional specifying OS/2-based kernel debugger. Default
echo old-style kernel debugger outputs to terminal connected to COM1.
echo.
echo Example1: setup i386
echo Copies only the NT i386 system.  Does not copy the Win32 development
echo files and defaults to old-style kernel debugger.
echo.
echo Example2: setup i386 mstools
echo This copies nt files to C:, copies all i386 Win32 development files,
echo and defaults to old-style kernel debugger.
echo.

:exit
endlocal
