@echo off
set ARG1=null
set NTLITE="%ProgramFiles%\NTLite\NTLite.exe"
set SOURCES=c:\TEMP\W10\sources
set IMAGEFILE=install.wim
set T=c:\temp

IF "%~1" NEQ "" set ARG1=%1
if /I %ARG1% == /? goto usage

rem check for the image directory ...
if NOT EXIST image (
  echo ERROR: directory [ image ] NOT FOUND!
  echo ABORT.
  exit /b
) else (
  cd image
)

echo =========================================
echo START of MAIN image creation process ... 
echo =========================================
echo.

rem start scripts
for %%S in (
  export-image.cmd
  mount-image.cmd
) do (
  echo ########## calling [ %%S ] ##########
  call %%S || ( cd .. ; exit /b )
  echo.
)

if /I %ARG1% == /R (
  echo ########## calling [ remove-apps.cmd ] ##########
  call remove-apps.cmd
  echo.
)

echo ########## calling [ finish-image.cmd ] ##########
call finish-image.cmd || ( cd .. ; exit /b )
echo.

rem go back ...
cd ..

echo checking for NTLite ...
if NOT EXIST %NTLITE% (
  echo.
  echo ERROR: program [ NTLite ] NOT FOUND!
) else (
  echo calling NTLite ...
  rem stupid windows: the "" are needed or NTlite will not be started - sigh -
  start /B "" %NTLITE% /LoadImage:%SOURCES%\%IMAGEFILE%
)

echo.
echo ======
echo READY.
echo ======
GOTO END

:USAGE
echo.
echo "usage: %0 [/R|/?]"
echo "  /R = remove apps from main image"
echo "  /? = show help                  "
echo.
:END

