@echo off
set SOURCES=%SystemDrive%\TEMP\W10\sources
set BOOT=%SystemDrive%\TEMP\BOOT
set SCRIPT_SETTINGS=..\scripts\settings.cmd
set COMPANY_SETTINGS=..\company\settings.cmd
set LANG=en-US
set localadmin=localadmin
set localadmin_name=Local Administrator
set localadmin_password=

rem ===================
rem CONFIGFILE CHECK
rem ===================

echo searching for SCRIPT settings ...
if NOT EXIST %SCRIPT_SETTINGS% (
  echo INFO: config file %SCRIPT_SETTINGS% NOT FOUND
) else (
  echo OK. Loading SCRIPT settings ...
  call %SCRIPT_SETTINGS%
)
echo.

echo searching for COMPANY settings ...
if NOT EXIST %COMPANY_SETTINGS% (
  echo INFO: config file %COMPANY_SETTINGS% NOT FOUND
) else (
  echo OK. Loading COMPANY settings ...
  call %COMPANY_SETTINGS%
)
echo.

rem ======
rem MAIN
rem ======

if NOT EXIST %BOOT%\winsetup.exe (
  echo renaming Windows setup.exe to boot image ...
  move /Y %BOOT%\setup.exe %BOOT%\winsetup.exe
  echo.
)

echo setting language in boot image ...
dism /image:%BOOT% /Set-InputLocale:%LANG% || exit /b 1
dism /image:%BOOT% /Set-SysLocale:%LANG% || exit /b 1
echo.

echo replacing setup.exe with our installer utility ...
copy /Y installer.exe %BOOT%\setup.exe
echo.

rem prepare unattended xml files ...
for %%A in (

  BIOS
  UEFI
  
) do (
  
  echo copying config file for unattended install [ %%A ]...
  copy /Y autounattend_%%A_template.xml %BOOT%\autounattend_%%A.xml

  rem prepare BIOS version ...
  ..\tools\searchreplace %BOOT%\autounattend_%%A.xml ___MYUSER___ "%localadmin%"
  ..\tools\searchreplace %BOOT%\autounattend_%%A.xml ___MYNAME___ "%localadmin_name%"
  ..\tools\searchreplace %BOOT%\autounattend_%%A.xml ___MYPASS___ "%localadmin_password%" /S
  ..\tools\searchreplace %BOOT%\autounattend_%%A.xml ___MYLANG___ "%LANG%"
  echo.

)

if EXIST ..\company\snapshot64.exe (
  echo copying LICENSED snapshot64.exe to boot image ...
  copy /Y ..\company\snapshot64.exe %BOOT% 
) else (
  echo copying STANDARD snapshot64.exe to boot image ...
  copy /Y ..\software\snapshot64.exe %BOOT%
)

echo copy netuse helper script to boot image ...
copy /Y netuse.cmd %BOOT%

echo unmounting and committing changes to %SOURCES%\boot.wim ...
dism /Unmount-Wim /MountDir:%BOOT% /Commit  || exit /b 1

