@echo off
set IMAGE=%SystemDrive%\TEMP\IMAGE
set SOURCES=%SystemDrive%\TEMP\W10\sources
set WIM=%SOURCES%\install.wim

if NOT EXIST %WIM% (
  echo.
  echo [%0] ERROR: %WIM% NOT found!
  exit /b
)

rd /S /Q %IMAGE%\Windows\Setup\scripts 1>nul 2>nul
mkdir %IMAGE%\Windows\Setup\scripts 1>nul 2>nul

echo [%0] INFO: copying scripts to %IMAGE%\Windows\Setup\scripts ...
copy /Y SetupComplete.cmd %IMAGE%\Windows\Setup\scripts
copy /Y SearchAutoconfig.cmd %IMAGE%\Windows\Setup\scripts
copy /Y ..\tools\prompt-user.exe %IMAGE%\Windows

if %ERRORLEVEL% NEQ 0 (
  echo [%0] ERROR: while copying scripts to IMAGE
  exit /b
)

echo [%0] INFO: doing cleanup on mountpoint %IMAGE% ...
dism /Image:%IMAGE% /Cleanup-Image /StartComponentCleanup /ResetBase

echo [%0] INFO: unmounting and committing changes to %WIM% ...
dism /Unmount-Wim /MountDir:%IMAGE% /Commit

