::
:: 
::  NOTE TO USER
::
::  This is a script file which builds EBCD LITE.
::  Normally, you do not need to modify this file, even if you want to customize EBCD.
::  See README\README_EN.txt file for more info.
::
::
@echo off
cls
echo.
echo Building EMERGENCY BOOT CD LITE, version 0.5
echo Start with `--include-build' option to include build files to CD.
echo       with `--alternate-build' option to use mkisofs to build the image.
echo.
echo.
echo [ 1 ]  Checking environment...
if [%TEMP%]==[] goto _no_temp
echo. >> %TEMP%\$ebcd$long$name$check$.tmp
for %%i in (%TEMP%\$ebcd$long$name$check$.tmp) do if not exist %TEMP%\$ebcd$long$name$check$.tmp goto _no_lfn
del %TEMP%\$ebcd$long$name$check$.tmp
echo [ 2 ]  Checking intergity...
for %%i in (CDROM-LITE\BOOT\ISOLINUX\ISOLINUX.SYS BIN\postfix.exe BIN\cdimage.exe) do if not exist %%i goto _fail
echo [ 3 ]  Compressing ramdisk patch...
if not exist BIN\rar-260.exe goto _rp_done
if not exist EXTRA-RD1-LITE\nul goto _try2
cd EXTRA-RD1-LITE
if exist ..\CDROM-LITE\BOOT\extra.rar del ..\CDROM-LITE\BOOT\extra.rar 
..\BIN\rar-260.exe a -r ..\CDROM-LITE\BOOT\extra.rar *.* > NUL
cd ..
:_try2
if not exist EXTRA-RD2-LITE\nul goto _rp_done
cd EXTRA-RD2-LITE
if exist ..\CDROM-LITE\BOOT\extrac.rar del ..\CDROM-LITE\BOOT\extrac.rar 
..\BIN\rar-260.exe a -r ..\CDROM-LITE\BOOT\extrac.rar *.* > NUL
cd ..
:_rp_done
echo [ 4 ]  Building ISO9660 filesystem image (EBCD-LITE-v05.ISO)...
if exist EBCD-LITE-v05.ISO del EBCD-LITE-v05.ISO
if not [%1]==[--include-build] if not [%2]==[--include-build] goto _simple_build
BIN\rar-260.exe a -r %TEMP%\$ebcd$.tmp *.* > NUL
if exist %TEMP%\$ebcd$.tmp copy %TEMP%\$ebcd$.tmp CDROM-LITE\build.rar > NUL
if exist %TEMP%\$ebcd$.tmp del %TEMP%\$ebcd$.tmp
:_simple_build
if not [%1]==[--alternate-build] if not [%2]==[--alternate-build] goto _normal_build
:_alt_build
ren CDROM-LITE\BOOT\ISOLINUX\isolinux.sys isolinux.sys
BIN\mkisofs.exe -oEBCD-LITE-v05.iso -bBOOT/ISOLINUX/isolinux.sys -VEBCD_LITE -J -no-emul-boot -boot-load-size 4 -boot-info-table CDROM-LITE/
echo.
echo.
echo [ 5 ]  Patch skipped
goto _build_done
:_normal_build
BIN\cdimage.exe CDROM-LITE EBCD-LITE-v05.iso -bCDROM-LITE\BOOT\ISOLINUX\ISOLINUX.SYS -lEBCD_LITE -e -w2 -c -j1
if not exist EBCD-LITE-v05.iso goto _alt_build
echo.
echo.
echo [ 5 ]  Patching image to force isolinux bootloader compatibility...
BIN\postfix.exe EBCD-LITE-v05.ISO
:_build_done
if not [%1]==[--include-build] if not [%2]==[--include-build] goto _skip
if exist CDROM-LITE\build.rar del CDROM-LITE\build.rar
:_skip
echo [ 6 ]  Cleaning up...
if exist CDROM-LITE\BOOT\extra.rar del CDROM-LITE\BOOT\extra.rar 
goto _exit

:_fail
echo ...FAILED!
pause
goto _exit
:_no_lfn
echo Not long filename enviroment, or TEMP folder is not accessible.
echo When running under NT 4.0, maybe you'll need to rename this (.BAT) file 
echo to .CMD file to get around this.
goto _fail
:_no_temp
echo Environment variable TEMP is not set.
goto _fail
:_exit
