::
:: 
::  NOTE TO USER
::
::  This is a script file which builds EBCD PRO.
::  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 PRO, 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-PRO\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-PRO\nul goto _try2
cd EXTRA-RD1-PRO
if exist ..\CDROM-PRO\BOOT\extra.rar del ..\CDROM-PRO\BOOT\extra.rar 
..\BIN\rar-260.exe a -r ..\CDROM-PRO\BOOT\extra.rar *.* > NUL
cd ..
:_try2
if not exist EXTRA-RD2-PRO\nul goto _rp_done
cd EXTRA-RD2-PRO
if exist ..\CDROM-PRO\BOOT\extrac.rar del ..\CDROM-PRO\BOOT\extrac.rar 
..\BIN\rar-260.exe a -r ..\CDROM-PRO\BOOT\extrac.rar *.* > NUL
cd ..
:_rp_done
echo [ 4 ]  Building ISO9660 filesystem image (EBCD-PRO-v05.ISO)...
if exist EBCD-PRO-v05.ISO del EBCD-PRO-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-PRO\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-PRO\BOOT\ISOLINUX\isolinux.sys isolinux.sys
BIN\mkisofs.exe -oEBCD-PRO-v05.iso -bBOOT/ISOLINUX/isolinux.sys -VEBCD_PRO -J -no-emul-boot -boot-load-size 4 -boot-info-table CDROM-PRO/
echo.
echo.
echo [ 5 ]  Patch skipped
goto _build_done
:_normal_build
BIN\cdimage.exe CDROM-PRO EBCD-PRO-v05.iso -bCDROM-PRO\BOOT\ISOLINUX\ISOLINUX.SYS -lEBCD_PRO -e -w2 -c -j1
if not exist EBCD-PRO-v05.iso goto _alt_build
echo.
echo.
echo [ 5 ]  Patching image to force isolinux bootloader compatibility...
BIN\postfix.exe EBCD-PRO-v05.ISO
:_build_done
if not [%1]==[--include-build] if not [%2]==[--include-build] goto _skip
if exist CDROM-PRO\build.rar del CDROM-PRO\build.rar
:_skip
echo [ 6 ]  Cleaning up...
if exist CDROM-PRO\BOOT\extra.rar del CDROM-PRO\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
