@echo off
rem *** Author: T. Wittrock, RZ Uni Kiel ***

verify other 2>nul
setlocal enableextensions
if errorlevel 1 goto NoExtensions

%~d0
cd "%~p0"

for %%i in (all enu deu nld esn fra ptg ptb ita rus plk ell csy dan nor sve fin) do (if /i "%1"=="%%i" goto Valid1)
for %%i in (w2k wxp w2k3 o2k oxp o2k3) do (
  if /i "%1"=="%%i" (
    for %%j in (enu deu nld esn fra ptg ptb ita rus plk ell csy dan nor sve fin) do (if /i "%2"=="%%j" goto Valid2)
    goto Valid1
  )
)
for %%i in (w60 o2k7) do (
  if /i "%1"=="%%i" (
    if /i "%2"=="glb" shift /2
    goto Valid1
  )
)
goto InvalidParams

:Valid1
set CREATE_DVD=1
if /i "%2"=="/outputpath" (
  if %3~==~ (goto InvalidParams) else (set OUTPUT_PATH=%~fs3)
)
for %%i in (all w2k wxp w2k3 w60 o2k oxp o2k3 o2k7) do (if /i "%1"=="%%i" goto V1CopyFilter)
rem *** Generate ISO filter ***
echo Generating ISO filter for %1...
copy /Y ..\exclude\ExcludeListISO-all.txt "%TEMP%\ExcludeListISO-%1.txt" > nul
for %%i in (enu deu nld esn fra ptg ptb ita rus plk ell csy dan nor sve fin) do (
  if /i "%1" NEQ "%%i" (
    if /i "%%i"=="enu" (
      echo *%%i\/*>> "%TEMP%\ExcludeListISO-%1.txt"
    ) else (
      echo *%%i*>> "%TEMP%\ExcludeListISO-%1.txt"
    )
  )
)
if /i "%1" NEQ "enu" echo *o2k3\/glb\/*2003SP*>> "%TEMP%\ExcludeListISO-%1.txt"
goto NoMoreParams
:V1CopyFilter
rem *** Copy ISO filter ***
echo Copying ISO filter for %1...
if exist ..\exclude\ExcludeListISO-%1.txt (
  copy /Y ..\exclude\ExcludeListISO-%1.txt "%TEMP%\ExcludeListISO-%1.txt" > nul
) else (
  copy /Y ..\exclude\ExcludeListISO-%1-x86.txt "%TEMP%\ExcludeListISO-%1.txt" > nul
)
goto NoMoreParams

:Valid2
if /i "%3"=="/outputpath" (
  if %4~==~ (goto InvalidParams) else (set OUTPUT_PATH=%~fs4)
)
rem *** Generate ISO filter ***
echo Generating ISO filter for %1 %2...
if exist ..\exclude\ExcludeListISO-%1.txt (
  copy /Y ..\exclude\ExcludeListISO-%1.txt "%TEMP%\ExcludeListISO-%1-%2.txt" > nul
) else (
  copy /Y ..\exclude\ExcludeListISO-%1-x86.txt "%TEMP%\ExcludeListISO-%1-%2.txt" > nul
)
for %%i in (enu deu nld esn fra ptg ptb ita rus plk ell csy dan nor sve fin) do (
  if /i "%2" NEQ "%%i" (
    if /i "%%i"=="enu" (
      echo *%%i\/*>> "%TEMP%\ExcludeListISO-%1-%2.txt"
    ) else (
      echo *%%i*>> "%TEMP%\ExcludeListISO-%1-%2.txt"
    )
  )
)
if /i "%1"=="o2k3" (
  if /i "%2" NEQ "enu" echo *glb\/*2003SP*>> "%TEMP%\ExcludeListISO-%1-%2.txt"
)
goto NoMoreParams

:NoMoreParams
if not exist ..\bin\mkisofs.exe goto NoMkIsoFs
if %OUTPUT_PATH%~==~ set OUTPUT_PATH=..\iso

if "%CREATE_DVD%"=="1" goto DVD

rem *** Create CD ISO image ***
title Creating ISO image for %1 %2...
echo Creating ISO image for %1 %2...
if exist %OUTPUT_PATH%\wsusoffline-%1-%2.iso del %OUTPUT_PATH%\wsusoffline-%1-%2.iso
..\bin\mkisofs.exe -iso-level 4 -joliet -joliet-long -rational-rock -exclude-list "%TEMP%\ExcludeListISO-%1-%2.txt" -output %OUTPUT_PATH%\wsusoffline-%1-%2.iso -volid ctou_%1_%2 ..\client
if errorlevel 1 goto MkIsoError
del "%TEMP%\ExcludeListISO-%1-%2.txt"
goto EoF

:DVD
rem *** Create DVD ISO image ***
title Creating ISO image for %1...
echo Creating ISO image for %1...
if exist %OUTPUT_PATH%\wsusoffline-%1.iso del %OUTPUT_PATH%\wsusoffline-%1.iso
..\bin\mkisofs.exe -iso-level 4 -joliet -joliet-long -rational-rock -exclude-list "%TEMP%\ExcludeListISO-%1.txt" -output %OUTPUT_PATH%\wsusoffline-%1.iso -volid ctou_%1 ..\client
if errorlevel 1 goto MkIsoError
del "%TEMP%\ExcludeListISO-%1.txt"
goto EoF

:NoExtensions
echo.
echo ERROR: No command extensions available.
echo.
goto Error

:InvalidParams
echo.
echo ERROR: Invalid parameter: %1 %2 %3 %4
echo Usage1: %~n0 {w2k ^| wxp ^| w2k3 ^| w60 ^| o2k ^| oxp ^| o2k3 ^| o2k7} {enu ^| deu ^| nld ^| esn ^| fra ^| ptg ^| ptb ^| ita ^| rus ^| plk ^| ell ^| csy ^| dan ^| nor ^| sve ^| fin} [/outputpath ^<OutputPath^>]
echo Usage2: %~n0 {all ^| w2k ^| wxp ^| w2k3 ^| w60 ^| o2k ^| oxp ^| o2k3 ^| o2k7 ^| enu ^| deu ^| nld ^| esn ^| fra ^| ptg ^| ptb ^| ita ^| rus ^| plk ^| ell ^| csy ^| dan ^| nor ^| sve ^| fin} [/outputpath ^<OutputPath^>]
echo.
goto Error

:NoMkIsoFs
echo.
echo ERROR: Utility ..\bin\mkisofs.exe not found.
echo.
goto Error

:MkIsoError
echo.
echo ERROR: Creation of ISO image failed.
echo.
goto Error

:Error
endlocal
pause
verify other 2>nul
exit

:EoF
title %ComSpec%
endlocal
