diff --git a/scripts/Copy WizardKit.cmd b/scripts/Copy WizardKit.cmd index 1740382d..d63588c6 100644 --- a/scripts/Copy WizardKit.cmd +++ b/scripts/Copy WizardKit.cmd @@ -14,12 +14,12 @@ call :SetTitle Tools Copier rem Set variables using settings\main.py file set "SETTINGS=%bin%\Scripts\settings\main.py" for %%v in (ARCHIVE_PASSWORD KIT_NAME_FULL) do ( - set "var=%%v" - for /f "tokens=* usebackq" %%f in (`findstr "!var!=" "%SETTINGS%"`) do ( - set "_v=%%f" - set "_v=!_v:*'=!" - set "%%v=!_v:~0,-1!" - ) + set "var=%%v" + for /f "tokens=* usebackq" %%f in (`findstr "!var!=" "%SETTINGS%"`) do ( + set "_v=%%f" + set "_v=!_v:*'=!" + set "%%v=!_v:~0,-1!" + ) ) rem Set ARCH to 32 as a gross assumption and check for x86_64 status set ARCH=32 @@ -28,9 +28,9 @@ set "SEVEN_ZIP=%bin%\7-Zip\7za.exe" set "CON=%bin%\ConEmu\ConEmu.exe" set "FASTCOPY=%bin%\FastCopy\FastCopy.exe" if %ARCH% equ 64 ( - set "SEVEN_ZIP=%bin%\7-Zip\7za64.exe" - set "CON=%bin%\ConEmu\ConEmu64.exe" - set "FASTCOPY=%bin%\FastCopy\FastCopy64.exe" + set "SEVEN_ZIP=%bin%\7-Zip\7za64.exe" + set "CON=%bin%\ConEmu\ConEmu64.exe" + set "FASTCOPY=%bin%\FastCopy\FastCopy64.exe" ) set "fastcopy_args=/cmd=diff /no_ui /auto_close" rem Set %client_dir% @@ -42,14 +42,14 @@ set "dest=%client_dir%\Tools" :RelaunchInConEmu if not defined IN_CONEMU ( - if not defined L_NCMD ( - set "con_args=-new_console:n" - rem If in DEBUG state then force ConEmu to stay open - if defined DEBUG (set "con_args=!con_args! -new_console:c") - set IN_CONEMU=True - start "" "%CON%" -run ""%~0" %*" !con_args! || goto ErrorUnknown - exit /b 0 - ) + if not defined L_NCMD ( + set "con_args=-new_console:n" + rem If in DEBUG state then force ConEmu to stay open + if defined DEBUG (set "con_args=!con_args! -new_console:c") + set IN_CONEMU=True + start "" "%CON%" -run ""%~0" %*" !con_args! || goto ErrorUnknown + exit /b 0 + ) ) :CopyBin echo Copying .bin... @@ -102,7 +102,7 @@ goto Exit rem Loops through all arguments to check for accepted flags set DEBUG= for %%f in (%*) do ( - if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG") + if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG") ) @exit /b 0 diff --git a/scripts/Launch.cmd b/scripts/Launch.cmd index faea56f8..1afddb2b 100644 --- a/scripts/Launch.cmd +++ b/scripts/Launch.cmd @@ -21,12 +21,12 @@ call :DeQuote L_TYPE rem Set variables using settings\main.py file set "SETTINGS=%bin%\Scripts\settings\main.py" for %%v in (ARCHIVE_PASSWORD KIT_NAME_FULL OFFICE_SERVER_IP QUICKBOOKS_SERVER_IP) do ( - set "var=%%v" - for /f "tokens=* usebackq" %%f in (`findstr "!var!=" "%SETTINGS%"`) do ( - set "_v=%%f" - set "_v=!_v:*'=!" - set "%%v=!_v:~0,-1!" - ) + set "var=%%v" + for /f "tokens=* usebackq" %%f in (`findstr "!var!=" "%SETTINGS%"`) do ( + set "_v=%%f" + set "_v=!_v:*'=!" + set "%%v=!_v:~0,-1!" + ) ) rem Set ARCH to 32 as a gross assumption and check for x86_64 status set ARCH=32 @@ -37,21 +37,21 @@ set "FASTCOPY=%bin%\FastCopy\FastCopy.exe" set "POWERSHELL=%systemroot%\system32\WindowsPowerShell\v1.0\powershell.exe" set "PYTHON=%bin%\Python\x32\python.exe" if %ARCH% equ 64 ( - set "SEVEN_ZIP=%bin%\7-Zip\7za64.exe" - set "CON=%bin%\ConEmu\ConEmu64.exe" - set "FASTCOPY=%bin%\FastCopy\FastCopy64.exe" - set "PYTHON=%bin%\Python\x64\python.exe" + set "SEVEN_ZIP=%bin%\7-Zip\7za64.exe" + set "CON=%bin%\ConEmu\ConEmu64.exe" + set "FASTCOPY=%bin%\FastCopy\FastCopy64.exe" + set "PYTHON=%bin%\Python\x64\python.exe" ) :UpdateTitle rem Sets title using KIT_NAME_FULL from settings\main.py (unless %window_title% already set) if defined window_title ( - title %window_title% + title %window_title% ) else ( - set "window_title=%*" - if not defined window_title set "window_title=Launcher" - set "window_title=%KIT_NAME_FULL%: %window_title%" - title %window_title% + set "window_title=%*" + if not defined window_title set "window_title=Launcher" + set "window_title=%KIT_NAME_FULL%: %window_title%" + title %window_title% ) :CheckUsage @@ -66,28 +66,28 @@ if /i not "%L__CLI%" == "True" (set "L__CLI=") :RelaunchInConEmu set RELOAD_IN_CONEMU=True -if defined ConEmuBuild set "RELOAD_IN_CONEMU=" -if defined L_NCMD set "RELOAD_IN_CONEMU=" -if "%L_TYPE%" == "Executable" set "RELOAD_IN_CONEMU=" -if "%L_TYPE%" == "PSScript" set "RELOAD_IN_CONEMU=" -if "%L_TYPE%" == "PyScript" set "RELOAD_IN_CONEMU=" +if defined ConEmuBuild set "RELOAD_IN_CONEMU=" +if defined L_NCMD set "RELOAD_IN_CONEMU=" +if "%L_TYPE%" == "Executable" set "RELOAD_IN_CONEMU=" +if "%L_TYPE%" == "PSScript" set "RELOAD_IN_CONEMU=" +if "%L_TYPE%" == "PyScript" set "RELOAD_IN_CONEMU=" if defined RELOAD_IN_CONEMU ( - set "con_args=-new_console:n" - rem If in DEBUG state then force ConEmu to stay open - if defined DEBUG (set "con_args=!con_args! -new_console:c") - start "" "%CON%" -run ""%~0" %*" !con_args! || goto ErrorUnknown - exit /b 0 + set "con_args=-new_console:n" + rem If in DEBUG state then force ConEmu to stay open + if defined DEBUG (set "con_args=!con_args! -new_console:c") + start "" "%CON%" -run ""%~0" %*" !con_args! || goto ErrorUnknown + exit /b 0 ) :CheckLaunchType rem Jump to the selected launch type or show usage -if /i "%L_TYPE%" == "Executable" (goto LaunchExecutable) -if /i "%L_TYPE%" == "Folder" (goto LaunchFolder) -if /i "%L_TYPE%" == "Office" (goto LaunchOffice) -if /i "%L_TYPE%" == "PSScript" (goto LaunchPSScript) -if /i "%L_TYPE%" == "PyScript" (goto LaunchPyScript) -if /i "%L_TYPE%" == "QuickBooks" (goto LaunchQuickBooksSetup) +if /i "%L_TYPE%" == "Executable" (goto LaunchExecutable) +if /i "%L_TYPE%" == "Folder" (goto LaunchFolder) +if /i "%L_TYPE%" == "Office" (goto LaunchOffice) +if /i "%L_TYPE%" == "PSScript" (goto LaunchPSScript) +if /i "%L_TYPE%" == "PyScript" (goto LaunchPyScript) +if /i "%L_TYPE%" == "QuickBooks" (goto LaunchQuickBooksSetup) goto Usage :LaunchExecutable @@ -97,7 +97,7 @@ call :ExtractOrFindPath || goto ErrorProgramNotFound rem Check for 64-bit prog (if running on 64-bit system) set "prog=%_path%\%L_ITEM%" if %ARCH% equ 64 ( - if exist "%_path%\%L_ITEM:.=64.%" set "prog=%_path%\%L_ITEM:.=64.%" + if exist "%_path%\%L_ITEM:.=64.%" set "prog=%_path%\%L_ITEM:.=64.%" ) if not exist "%prog%" goto ErrorProgramNotFound @@ -105,9 +105,9 @@ rem Run popd && pushd "%_path%" if defined L__CLI goto LaunchExecutableCLI if defined L_ELEV ( - goto LaunchExecutableElev + goto LaunchExecutableElev ) else ( - goto LaunchExecutableUser + goto LaunchExecutableUser ) :LaunchExecutableCLI @@ -153,9 +153,9 @@ set "_odt=False" if %L_PATH% equ 2016 (set "_odt=True") if %L_PATH% equ 2019 (set "_odt=True") if "%_odt%" == "True" ( - goto LaunchOfficeODT + goto LaunchOfficeODT ) else ( - goto LaunchOfficeSetup + goto LaunchOfficeSetup ) :LaunchOfficeODT @@ -202,14 +202,14 @@ start "" /wait "%FASTCOPY%" %fastcopy_args% "%source%" /to="%dest%\" rem Run if exist "%dest%\%product_name%\setup.exe" ( - start "" "%dest%\%product_name%\setup.exe" || goto ErrorUnknown + start "" "%dest%\%product_name%\setup.exe" || goto ErrorUnknown ) else if "%product_name:~-3,3%" == "exe" ( - start "" "%dest%\%product_name%" || goto ErrorUnknown + start "" "%dest%\%product_name%" || goto ErrorUnknown ) else if "%product_name:~-3,3%" == "msi" ( - start "" "%dest%\%product_name%" || goto ErrorUnknown + start "" "%dest%\%product_name%" || goto ErrorUnknown ) else ( - rem Office source not supported by this script - goto ErrorOfficeUnsupported + rem Office source not supported by this script + goto ErrorOfficeUnsupported ) goto Exit @@ -225,9 +225,9 @@ if not exist "%script%" goto ErrorScriptNotFound rem Run popd && pushd "%_path%" if defined L_ELEV ( - goto LaunchPSScriptElev + goto LaunchPSScriptElev ) else ( - goto LaunchPSScriptUser + goto LaunchPSScriptUser ) :LaunchPSScriptElev @@ -238,10 +238,10 @@ rem Create VB script mkdir "%bin%\tmp" 2>nul echo Set UAC = CreateObject^("Shell.Application"^) > "%bin%\tmp\Elevate.vbs" if defined L_NCMD ( - rem use Powershell's window instead of %CON% - echo UAC.ShellExecute "%POWERSHELL%", "%ps_args% -File "%script%"", "", "runas", 3 >> "%bin%\tmp\Elevate.vbs" + rem use Powershell's window instead of %CON% + echo UAC.ShellExecute "%POWERSHELL%", "%ps_args% -File "%script%"", "", "runas", 3 >> "%bin%\tmp\Elevate.vbs" ) else ( - echo UAC.ShellExecute "%CON%", "-run %POWERSHELL% %ps_args% -File "%script%" -new_console:n", "", "runas", 1 >> "%bin%\tmp\Elevate.vbs" + echo UAC.ShellExecute "%CON%", "-run %POWERSHELL% %ps_args% -File "%script%" -new_console:n", "", "runas", 1 >> "%bin%\tmp\Elevate.vbs" ) rem Run @@ -251,9 +251,9 @@ goto Exit :LaunchPSScriptUser rem Run if defined L_NCMD ( - start "" "%POWERSHELL%" %ps_args% -File "%script%" || goto ErrorUnknown + start "" "%POWERSHELL%" %ps_args% -File "%script%" || goto ErrorUnknown ) else ( - start "" "%CON%" -run "%POWERSHELL%" %ps_args% -File "%script%" -new_console:n || goto ErrorUnknown + start "" "%CON%" -run "%POWERSHELL%" %ps_args% -File "%script%" -new_console:n || goto ErrorUnknown ) goto Exit @@ -268,9 +268,9 @@ if not exist "%script%" goto ErrorScriptNotFound rem Run if defined L_ELEV ( - goto LaunchPyScriptElev + goto LaunchPyScriptElev ) else ( - goto LaunchPyScriptUser + goto LaunchPyScriptUser ) :LaunchPyScriptElev @@ -281,9 +281,9 @@ rem Create VB script mkdir "%bin%\tmp" 2>nul echo Set UAC = CreateObject^("Shell.Application"^) > "%bin%\tmp\Elevate.vbs" if defined L_NCMD ( - echo UAC.ShellExecute "%PYTHON%", """%script%"" %L_ARGS%", "", "runas", 3 >> "%bin%\tmp\Elevate.vbs" + echo UAC.ShellExecute "%PYTHON%", """%script%"" %L_ARGS%", "", "runas", 3 >> "%bin%\tmp\Elevate.vbs" ) else ( - echo UAC.ShellExecute "%CON%", "-run ""%PYTHON%"" ""%script%"" %L_ARGS% -new_console:n", "", "runas", 1 >> "%bin%\tmp\Elevate.vbs" + echo UAC.ShellExecute "%CON%", "-run ""%PYTHON%"" ""%script%"" %L_ARGS% -new_console:n", "", "runas", 1 >> "%bin%\tmp\Elevate.vbs" ) rem Run @@ -292,9 +292,9 @@ goto Exit :LaunchPyScriptUser if defined L_NCMD ( - start "" "%PYTHON%" "%script%" %L_ARGS% || goto ErrorUnknown + start "" "%PYTHON%" "%script%" %L_ARGS% || goto ErrorUnknown ) else ( - start "" "%CON%" -run "%PYTHON%" "%script%" %L_ARGS% -new_console:n || goto ErrorUnknown + start "" "%CON%" -run "%PYTHON%" "%script%" %L_ARGS% -new_console:n || goto ErrorUnknown ) goto Exit @@ -317,12 +317,12 @@ start "" /wait "%FASTCOPY%" %fastcopy_args% "%source%" /to="%dest%\" rem Run if exist "%dest%\%product_name%\Setup.exe" ( - pushd "%dest%\%product_name%" - start "" "%dest%\%product_name%\Setup.exe" || goto ErrorUnknown - popd + pushd "%dest%\%product_name%" + start "" "%dest%\%product_name%\Setup.exe" || goto ErrorUnknown + popd ) else ( - rem QuickBooks source not supported by this script - goto ErrorQuickBooksUnsupported + rem QuickBooks source not supported by this script + goto ErrorQuickBooksUnsupported ) goto Exit @@ -331,16 +331,16 @@ echo. echo.Usage (via defined variables): echo. L_TYPE L_PATH L_ITEM L_ARGS echo. Executable Working Dir Program Args [L_7ZIP] [L_ELEV] [L__CLI] -echo. Folder Folder '.' [L_7ZIP] -echo. Office Year Product [L_7ZIP] -echo. PSScript Scripts Script [L_7ZIP] [L_ELEV] [L_NCMD] -echo. PyScript Scripts Script Args [L_7ZIP] [L_ELEV] [L_NCMD] -echo. QuickBooks Year Product [L_7ZIP] +echo. Folder Folder '.' [L_7ZIP] +echo. Office Year Product [L_7ZIP] +echo. PSScript Scripts Script [L_7ZIP] [L_ELEV] [L_NCMD] +echo. PyScript Scripts Script Args [L_7ZIP] [L_ELEV] [L_NCMD] +echo. QuickBooks Year Product [L_7ZIP] echo. -echo.L_7ZIP: Extra arguments for 7-Zip (in the :ExtractCBin label) -echo.L_ELEV: Elevate to run as Admin -echo.L_NCMD: Do not run script inside ConEmu (i.e. use the native window) -echo.L__CLI: Run executable in ConEmu +echo.L_7ZIP: Extra arguments for 7-Zip (in the :ExtractCBin label) +echo.L_ELEV: Elevate to run as Admin +echo.L_NCMD: Do not run script inside ConEmu (i.e. use the native window) +echo.L__CLI: Run executable in ConEmu echo. goto Abort @@ -392,15 +392,15 @@ set "%1=%_tmp%" :ExtractOrFindPath rem Test L_PATH in the following order: -rem 1: %cbin%\L_PATH.7z (which will be extracted to %bin%\L_PATH) -rem 2: %bin%\L_PATH -rem 3. %L_PATH% (i.e. treat L_PATH as an absolute path) +rem 1: %cbin%\L_PATH.7z (which will be extracted to %bin%\L_PATH) +rem 2: %bin%\L_PATH +rem 3. %L_PATH% (i.e. treat L_PATH as an absolute path) rem NOTE: This function should be called as 'call :ExtractOrFindPath || goto ErrorProgramNotFound' to catch invalid paths. set _path= if exist "%cbin%\%L_PATH%.7z" ( - call :ExtractCBin + call :ExtractCBin ) else if exist "%cbin%\%L_PATH%\%L_ITEM:~0,-4%.7z" ( - call :ExtractCBin + call :ExtractCBin ) if exist "%bin%\%L_PATH%" (set "_path=%bin%\%L_PATH%") if not defined _path (set "_path=%L_PATH%") @@ -476,9 +476,9 @@ goto Abort :Abort rem Handle color theme for both the native console and ConEmu if defined ConEmuBuild ( - color c4 + color c4 ) else ( - color 4e + color 4e ) echo Aborted. echo. diff --git a/scripts/Launcher_Template.cmd b/scripts/Launcher_Template.cmd index 01d1758d..9bb03a97 100644 --- a/scripts/Launcher_Template.cmd +++ b/scripts/Launcher_Template.cmd @@ -46,7 +46,7 @@ goto Exit rem Loops through all arguments to check for accepted flags set DEBUG= for %%f in (%*) do ( - if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG") + if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG") ) @exit /b 0 @@ -70,9 +70,9 @@ popd rem Sets title using KIT_NAME_FULL from settings\main.py set "SETTINGS=%bin%\Scripts\settings\main.py" for /f "tokens=* usebackq" %%f in (`findstr KIT_NAME_FULL "%SETTINGS%"`) do ( - set "_v=%%f" - set "_v=!_v:*'=!" - set "KIT_NAME_FULL=!_v:~0,-1!" + set "_v=%%f" + set "_v=!_v:*'=!" + set "KIT_NAME_FULL=!_v:~0,-1!" ) set "window_title=%*" if not defined window_title set "window_title=Launcher" diff --git a/scripts/build_kit.ps1 b/scripts/build_kit.ps1 index 76e69966..a8316913 100644 --- a/scripts/build_kit.ps1 +++ b/scripts/build_kit.ps1 @@ -3,7 +3,7 @@ ## Init ## #Requires -Version 3.0 if (Test-Path Env:\DEBUG) { - Set-PSDebug -Trace 1 + Set-PSDebug -Trace 1 } $Host.UI.RawUI.WindowTitle = "Wizard Kit: Build Tool" $WD = $(Split-Path $MyInvocation.MyCommand.Path) @@ -21,47 +21,47 @@ $Host.UI.RawUI.ForegroundColor = "white" ## Functions ## function Abort { - Write-Host -ForegroundColor "Red" "`nAborted." - WKPause "Press Enter to exit..." - exit + Write-Host -ForegroundColor "Red" "`nAborted." + WKPause "Press Enter to exit..." + exit } function DownloadFile ($Path, $Name, $Url) { - $OutFile = "{0}\{1}" -f $Path, $Name + $OutFile = "{0}\{1}" -f $Path, $Name - Write-Host ("Downloading: $Name") - New-Item -Type Directory $Path 2>&1 | Out-Null - try { - Invoke-WebRequest -Uri $Url -OutFile $OutFile - } - catch { - Write-Host (" ERROR: Failed to download file." ) -ForegroundColor "Red" - $global:DownloadErrors += 1 - } + Write-Host ("Downloading: $Name") + New-Item -Type Directory $Path 2>&1 | Out-Null + try { + Invoke-WebRequest -Uri $Url -OutFile $OutFile + } + catch { + Write-Host (" ERROR: Failed to download file." ) -ForegroundColor "Red" + $global:DownloadErrors += 1 + } } function FindDynamicUrl ($SourcePage, $RegEx) { - # Get source page - Invoke-Webrequest -Uri $SourcePage -OutFile "tmp_page" + # Get source page + Invoke-Webrequest -Uri $SourcePage -OutFile "tmp_page" - # Search for real url - $Url = Get-Content "tmp_page" | Where-Object {$_ -imatch $RegEx} - $Url = $Url -ireplace '.*(a |)href="([^"]+)".*', '$2' - $Url = $Url -ireplace ".*(a |)href='([^']+)'.*", '$2' + # Search for real url + $Url = Get-Content "tmp_page" | Where-Object {$_ -imatch $RegEx} + $Url = $Url -ireplace '.*(a |)href="([^"]+)".*', '$2' + $Url = $Url -ireplace ".*(a |)href='([^']+)'.*", '$2' - # Remove tmp_page - Remove-Item "tmp_page" + # Remove tmp_page + Remove-Item "tmp_page" - $Url | Select-Object -First 1 + $Url | Select-Object -First 1 } function WKPause ($Message = "Press Enter to continue... ") { - Write-Host $Message -NoNewLine - Read-Host + Write-Host $Message -NoNewLine + Read-Host } ## Safety Check ## if ($PSVersionTable.PSVersion.Major -eq 6 -and $PSVersionTable.OS -imatch "Windows 6.1") { - Write-Host "`nThis script doesn't support PowerShell 6.0 on Windows 7." + Write-Host "`nThis script doesn't support PowerShell 6.0 on Windows 7." Write-Host "Press Enter to exit... " -NoNewLine - Abort + Abort } ## PowerShell equivalent of Python's "if __name__ == '__main__'" @@ -71,160 +71,160 @@ if ($PSVersionTable.PSVersion.Major -eq 6 -and $PSVersionTable.OS -imatch "Windo # Asked by: https://stackoverflow.com/users/65164/mark-mascolino # Answer by: https://stackoverflow.com/users/696808/bacon-bits if ($MyInvocation.InvocationName -ne ".") { - Clear-Host - Write-Host "Wizard Kit: Build Tool`n`n`n`n`n" - - ## Download ## - $DownloadErrors = 0 - $Path = $Temp + Clear-Host + Write-Host "Wizard Kit: Build Tool`n`n`n`n`n" - # 7-Zip - DownloadFile -Path $Path -Name "7z-installer.msi" -Url "https://www.7-zip.org/a/7z1900.msi" - DownloadFile -Path $Path -Name "7z-extra.7z" -Url "https://www.7-zip.org/a/7z1900-extra.7z" + ## Download ## + $DownloadErrors = 0 + $Path = $Temp - # ConEmu - $Url = "https://github.com/Maximus5/ConEmu/releases/download/v19.03.10/ConEmuPack.190310.7z" - DownloadFile -Path $Path -Name "ConEmuPack.7z" -Url $Url + # 7-Zip + DownloadFile -Path $Path -Name "7z-installer.msi" -Url "https://www.7-zip.org/a/7z1900.msi" + DownloadFile -Path $Path -Name "7z-extra.7z" -Url "https://www.7-zip.org/a/7z1900-extra.7z" - # Notepad++ - $Url = "https://notepad-plus-plus.org/repository/7.x/7.6.4/npp.7.6.4.bin.minimalist.7z" - DownloadFile -Path $Path -Name "npp.7z" -Url $Url + # ConEmu + $Url = "https://github.com/Maximus5/ConEmu/releases/download/v19.03.10/ConEmuPack.190310.7z" + DownloadFile -Path $Path -Name "ConEmuPack.7z" -Url $Url - # Python - $Url = "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-win32.zip" - DownloadFile -Path $Path -Name "python32.zip" -Url $Url - $Url = "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-amd64.zip" - DownloadFile -Path $Path -Name "python64.zip" -Url $Url + # Notepad++ + $Url = "https://notepad-plus-plus.org/repository/7.x/7.6.4/npp.7.6.4.bin.minimalist.7z" + DownloadFile -Path $Path -Name "npp.7z" -Url $Url - # Python: psutil - $DownloadPage = "https://pypi.org/project/psutil/" - $RegEx = "href=.*-cp37-cp37m-win32.whl" - $Url = FindDynamicUrl $DownloadPage $RegEx - DownloadFile -Path $Path -Name "psutil32.whl" -Url $Url - $RegEx = "href=.*-cp37-cp37m-win_amd64.whl" - $Url = FindDynamicUrl $DownloadPage $RegEx - DownloadFile -Path $Path -Name "psutil64.whl" -Url $Url + # Python + $Url = "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-win32.zip" + DownloadFile -Path $Path -Name "python32.zip" -Url $Url + $Url = "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-amd64.zip" + DownloadFile -Path $Path -Name "python64.zip" -Url $Url - # Python: requests & dependancies - $RegEx = "href=.*.py3-none-any.whl" - foreach ($Module in @("chardet", "certifi", "idna", "urllib3", "requests")) { - $DownloadPage = "https://pypi.org/project/$Module/" - $Name = "$Module.whl" - $Url = FindDynamicUrl -SourcePage $DownloadPage -RegEx $RegEx - DownloadFile -Path $Path -Name $Name -Url $Url - } + # Python: psutil + $DownloadPage = "https://pypi.org/project/psutil/" + $RegEx = "href=.*-cp37-cp37m-win32.whl" + $Url = FindDynamicUrl $DownloadPage $RegEx + DownloadFile -Path $Path -Name "psutil32.whl" -Url $Url + $RegEx = "href=.*-cp37-cp37m-win_amd64.whl" + $Url = FindDynamicUrl $DownloadPage $RegEx + DownloadFile -Path $Path -Name "psutil64.whl" -Url $Url - # Visual C++ Runtimes - $Url = "https://aka.ms/vs/15/release/vc_redist.x86.exe" - DownloadFile -Path $Path -Name "vcredist_x86.exe" -Url $Url - $Url = "https://aka.ms/vs/15/release/vc_redist.x64.exe" - DownloadFile -Path $Path -Name "vcredist_x64.exe" -Url $Url - - ## Bail ## - # If errors were encountered during downloads - if ($DownloadErrors -gt 0) { - Abort - } + # Python: requests & dependancies + $RegEx = "href=.*.py3-none-any.whl" + foreach ($Module in @("chardet", "certifi", "idna", "urllib3", "requests")) { + $DownloadPage = "https://pypi.org/project/$Module/" + $Name = "$Module.whl" + $Url = FindDynamicUrl -SourcePage $DownloadPage -RegEx $RegEx + DownloadFile -Path $Path -Name $Name -Url $Url + } - ## Install ## - # Visual C++ Runtimes - $ArgumentList = @("/install", "/passive", "/norestart") - Start-Process -FilePath "$Temp\vcredist_x86.exe" -ArgumentList $ArgumentList -Wait - Start-Process -FilePath "$Temp\vcredist_x64.exe" -ArgumentList $ArgumentList -Wait - Remove-Item "$Temp\vcredist*.exe" - - ## Extract ## - # 7-Zip - Write-Host "Extracting: 7-Zip" - try { - $ArgumentList = @("/a", "$Temp\7z-installer.msi", "TARGETDIR=$Temp\7zi", "/qn") - Start-Process -FilePath "$System32\msiexec.exe" -ArgumentList $ArgumentList -Wait - $SevenZip = "$Temp\7zi\Files\7-Zip\7z.exe" - $ArgumentList = @( - "x", "$Temp\7z-extra.7z", "-o$Bin\7-Zip", - "-aoa", "-bso0", "-bse0", "-bsp0", - "-x!x64\*.dll", "-x!Far", "-x!*.dll") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Start-Sleep 1 - Move-Item "$Bin\7-Zip\x64\7za.exe" "$Bin\7-Zip\7za64.exe" - Remove-Item "$Bin\7-Zip\x64" -Recurse - Remove-Item "$Temp\7z*" -Recurse - $SevenZip = "$Bin\7-Zip\7za.exe" - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } + # Visual C++ Runtimes + $Url = "https://aka.ms/vs/15/release/vc_redist.x86.exe" + DownloadFile -Path $Path -Name "vcredist_x86.exe" -Url $Url + $Url = "https://aka.ms/vs/15/release/vc_redist.x64.exe" + DownloadFile -Path $Path -Name "vcredist_x64.exe" -Url $Url - # Notepad++ - Write-Host "Extracting: Notepad++" - try { - $ArgumentList = @( - "x", "$Temp\npp.7z", "-o$Bin\NotepadPlusPlus", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Remove-Item "$Temp\npp.7z" - Move-Item "$Bin\NotepadPlusPlus\notepad++.exe" "$Bin\NotepadPlusPlus\notepadplusplus.exe" - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } + ## Bail ## + # If errors were encountered during downloads + if ($DownloadErrors -gt 0) { + Abort + } - # ConEmu - Write-Host "Extracting: ConEmu" - try { - $ArgumentList = @( - "x", "$Temp\ConEmuPack.7z", "-o$Bin\ConEmu", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Remove-Item "$Temp\ConEmuPack.7z" - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } + ## Install ## + # Visual C++ Runtimes + $ArgumentList = @("/install", "/passive", "/norestart") + Start-Process -FilePath "$Temp\vcredist_x86.exe" -ArgumentList $ArgumentList -Wait + Start-Process -FilePath "$Temp\vcredist_x64.exe" -ArgumentList $ArgumentList -Wait + Remove-Item "$Temp\vcredist*.exe" - # Python - foreach ($Arch in @("32", "64")) { - Write-Host "Extracting: Python (x$Arch)" - $Files = @( - "python$Arch.zip", - "certifi.whl", - "chardet.whl", - "idna.whl", - "psutil$Arch.whl", - "requests.whl", - "urllib3.whl" - ) - try { - foreach ($File in $Files) { - $ArgumentList = @( - "x", "$Temp\$File", "-o$Bin\Python\x$Arch", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - } - try { - Copy-Item -Path "$System32\vcruntime140.dll" -Destination "$Bin\Python\x64\vcruntime140.dll" -Force - Copy-Item -Path "$SysWOW64\vcruntime140.dll" -Destination "$Bin\Python\x32\vcruntime140.dll" -Force - } - catch { - Write-Host (" ERROR: Failed to copy Visual C++ Runtime DLLs." ) -ForegroundColor "Red" - } - Remove-Item "$Temp\python*.zip" - Remove-Item "$Temp\*.whl" - - ## Configure ## - Write-Host "Configuring kit" - WKPause "Press Enter to open settings..." - $Cmd = "$Bin\NotepadPlusPlus\notepadplusplus.exe" - Start-Process -FilePath $Cmd -ArgumentList @("$Bin\Scripts\settings\main.py") -Wait + ## Extract ## + # 7-Zip + Write-Host "Extracting: 7-Zip" + try { + $ArgumentList = @("/a", "$Temp\7z-installer.msi", "TARGETDIR=$Temp\7zi", "/qn") + Start-Process -FilePath "$System32\msiexec.exe" -ArgumentList $ArgumentList -Wait + $SevenZip = "$Temp\7zi\Files\7-Zip\7z.exe" + $ArgumentList = @( + "x", "$Temp\7z-extra.7z", "-o$Bin\7-Zip", + "-aoa", "-bso0", "-bse0", "-bsp0", + "-x!x64\*.dll", "-x!Far", "-x!*.dll") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait Start-Sleep 1 + Move-Item "$Bin\7-Zip\x64\7za.exe" "$Bin\7-Zip\7za64.exe" + Remove-Item "$Bin\7-Zip\x64" -Recurse + Remove-Item "$Temp\7z*" -Recurse + $SevenZip = "$Bin\7-Zip\7za.exe" + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } - ## Done ## - Pop-Location - $ArgumentList = @("-run", "$Bin\Python\x32\python.exe", "$Bin\Scripts\update_kit.py", "-new_console:n") - Start-Process -FilePath "$Bin\ConEmu\ConEmu.exe" -ArgumentList $ArgumentList -verb RunAs + # Notepad++ + Write-Host "Extracting: Notepad++" + try { + $ArgumentList = @( + "x", "$Temp\npp.7z", "-o$Bin\NotepadPlusPlus", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Remove-Item "$Temp\npp.7z" + Move-Item "$Bin\NotepadPlusPlus\notepad++.exe" "$Bin\NotepadPlusPlus\notepadplusplus.exe" + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # ConEmu + Write-Host "Extracting: ConEmu" + try { + $ArgumentList = @( + "x", "$Temp\ConEmuPack.7z", "-o$Bin\ConEmu", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Remove-Item "$Temp\ConEmuPack.7z" + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # Python + foreach ($Arch in @("32", "64")) { + Write-Host "Extracting: Python (x$Arch)" + $Files = @( + "python$Arch.zip", + "certifi.whl", + "chardet.whl", + "idna.whl", + "psutil$Arch.whl", + "requests.whl", + "urllib3.whl" + ) + try { + foreach ($File in $Files) { + $ArgumentList = @( + "x", "$Temp\$File", "-o$Bin\Python\x$Arch", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + } + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + } + try { + Copy-Item -Path "$System32\vcruntime140.dll" -Destination "$Bin\Python\x64\vcruntime140.dll" -Force + Copy-Item -Path "$SysWOW64\vcruntime140.dll" -Destination "$Bin\Python\x32\vcruntime140.dll" -Force + } + catch { + Write-Host (" ERROR: Failed to copy Visual C++ Runtime DLLs." ) -ForegroundColor "Red" + } + Remove-Item "$Temp\python*.zip" + Remove-Item "$Temp\*.whl" + + ## Configure ## + Write-Host "Configuring kit" + WKPause "Press Enter to open settings..." + $Cmd = "$Bin\NotepadPlusPlus\notepadplusplus.exe" + Start-Process -FilePath $Cmd -ArgumentList @("$Bin\Scripts\settings\main.py") -Wait + Start-Sleep 1 + + ## Done ## + Pop-Location + $ArgumentList = @("-run", "$Bin\Python\x32\python.exe", "$Bin\Scripts\update_kit.py", "-new_console:n") + Start-Process -FilePath "$Bin\ConEmu\ConEmu.exe" -ArgumentList $ArgumentList -verb RunAs } diff --git a/scripts/build_pe.ps1 b/scripts/build_pe.ps1 index e783e39e..2b205093 100644 --- a/scripts/build_pe.ps1 +++ b/scripts/build_pe.ps1 @@ -4,7 +4,7 @@ #Requires -Version 3.0 #Requires -RunAsAdministrator if (Test-Path Env:\DEBUG) { - Set-PSDebug -Trace 1 + Set-PSDebug -Trace 1 } $Host.UI.RawUI.WindowTitle = "Wizard Kit: Windows PE Build Tool" $WD = $(Split-Path $MyInvocation.MyCommand.Path) @@ -24,73 +24,73 @@ $DISM = "{0}\DISM.exe" -f $Env:DISMRoot ## Functions ## function Ask-User ($text = "Kotaero") { - $text += " [Y/N]" - while ($true) { - $answer = read-host $text - if ($answer -imatch "^(y|yes)$") { - $answer = $true - break - } elseif ($answer -imatch "^(n|no|nope)$") { - $answer = $false - break - } + $text += " [Y/N]" + while ($true) { + $answer = read-host $text + if ($answer -imatch "^(y|yes)$") { + $answer = $true + break + } elseif ($answer -imatch "^(n|no|nope)$") { + $answer = $false + break } - $answer + } + $answer } function Abort { - Write-Host -ForegroundColor "Red" "`nAborted." - WKPause "Press Enter to exit... " - exit + Write-Host -ForegroundColor "Red" "`nAborted." + WKPause "Press Enter to exit... " + exit } function MakeClean { - $Folders = @( - "$Build\Mount", - "$Build\PEFiles") - $Clean = $false + $Folders = @( + "$Build\Mount", + "$Build\PEFiles") + $Clean = $false + foreach ($f in $Folders) { + if (Test-Path $f) { + Write-Host -ForegroundColor "Yellow" ("Found: {0}" -f $f) + $Clean = $true + } + } + if (($Clean) -and (Ask-User "Delete the above folder(s)?")) { foreach ($f in $Folders) { - if (Test-Path $f) { - Write-Host -ForegroundColor "Yellow" ("Found: {0}" -f $f) - $Clean = $true - } - } - if (($Clean) -and (Ask-User "Delete the above folder(s)?")) { - foreach ($f in $Folders) { - if (Test-Path $f) { - Remove-Item -Path $f -Recurse -Force - } - } + if (Test-Path $f) { + Remove-Item -Path $f -Recurse -Force + } } + } } function DownloadFile ($Path, $Name, $Url) { - $OutFile = "{0}\{1}" -f $Path, $Name + $OutFile = "{0}\{1}" -f $Path, $Name - Write-Host ("Downloading: $Name") - New-Item -Type Directory $Path 2>&1 | Out-Null - try { - Invoke-WebRequest -Uri $Url -OutFile $OutFile - } - catch { - Write-Host (" ERROR: Failed to download file." ) -ForegroundColor "Red" - $global:DownloadErrors += 1 - } + Write-Host ("Downloading: $Name") + New-Item -Type Directory $Path 2>&1 | Out-Null + try { + Invoke-WebRequest -Uri $Url -OutFile $OutFile + } + catch { + Write-Host (" ERROR: Failed to download file." ) -ForegroundColor "Red" + $global:DownloadErrors += 1 + } } function FindDynamicUrl ($SourcePage, $RegEx) { - # Get source page - Invoke-Webrequest -Uri $SourcePage -OutFile "tmp_page" + # Get source page + Invoke-Webrequest -Uri $SourcePage -OutFile "tmp_page" - # Search for real url - $Url = Get-Content "tmp_page" | Where-Object {$_ -imatch $RegEx} - $Url = $Url -ireplace '.*(a |)href="([^"]+)".*', '$2' - $Url = $Url -ireplace ".*(a |)href='([^']+)'.*", '$2' + # Search for real url + $Url = Get-Content "tmp_page" | Where-Object {$_ -imatch $RegEx} + $Url = $Url -ireplace '.*(a |)href="([^"]+)".*', '$2' + $Url = $Url -ireplace ".*(a |)href='([^']+)'.*", '$2' - # Remove tmp_page - Remove-Item "tmp_page" + # Remove tmp_page + Remove-Item "tmp_page" - $Url | Select-Object -First 1 + $Url | Select-Object -First 1 } function WKPause ($Message = "Press Enter to continue... ") { - Write-Host $Message -NoNewLine - Read-Host + Write-Host $Message -NoNewLine + Read-Host } ## PowerShell equivalent of Python's "if __name__ == '__main__'" @@ -100,558 +100,558 @@ function WKPause ($Message = "Press Enter to continue... ") { # Asked by: https://stackoverflow.com/users/65164/mark-mascolino # Answer by: https://stackoverflow.com/users/696808/bacon-bits if ($MyInvocation.InvocationName -ne ".") { - Clear-Host - Write-Host "Wizard Kit: Windows PE Build Tool`n`n`n`n`n" - - ## Prep ## + Clear-Host + Write-Host "Wizard Kit: Windows PE Build Tool`n`n`n`n`n" + + ## Prep ## + try { + Import-Module -Name $Env:DISMRoot -ErrorAction "stop" + } + catch { + Write-Host -ForegroundColor "Red" "ERROR: Failed to load DISM CmdLet" + Abort + } + Push-Location "$WD" + MakeClean + New-Item -Type Directory $Build 2>&1 | Out-Null + New-Item -Type Directory $LogDir 2>&1 | Out-Null + + ## main.py ## + if (!(Test-Path "$Build\main.py") -or (Ask-User "Replace existing main.py?")) { + Copy-Item -Path "$Bin\Scripts\settings\main.py" -Destination "$Build\main.py" -Force + } + WKPause "Press Enter to open settings..." + Start-Process "$HostSystem32\notepad.exe" -ArgumentList @("$Build\main.py") -Wait + $KitNameFull = (Get-Content "$Build\main.py" | Where-Object {$_ -match 'FULL'}) -replace ".*'(.*)'$", '$1' + $KitNameShort = (Get-Content "$Build\main.py" | Where-Object {$_ -match 'SHORT'}) -replace ".*'(.*)'$", '$1' + + if (Ask-User "Update Tools?") { + $DownloadErrors = 0 + + ## Download Tools ## + $ToolSources = @( + # 7-Zip + @("7z-installer.msi", "https://www.7-zip.org/a/7z1900.msi"), + @("7z-extra.7z", "https://www.7-zip.org/a/7z1900-extra.7z"), + # Blue Screen View + @("bluescreenview32.zip", "http://www.nirsoft.net/utils/bluescreenview.zip"), + @("bluescreenview64.zip", "http://www.nirsoft.net/utils/bluescreenview-x64.zip"), + # ConEmu + @("ConEmuPack.7z", "https://github.com/Maximus5/ConEmu/releases/download/v19.03.10/ConEmuPack.190310.7z"), + # Fast Copy + @("fastcopy.zip", "http://ftp.vector.co.jp/71/31/2323/FastCopy363_installer.exe"), + # HWiNFO + @("hwinfo.zip", "http://files2.majorgeeks.com/377527622c5325acc1cb937fb149d0de922320c0/systeminfo/hwi_602.zip"), + # Killer Network Drivers + @( + "killerinf.zip", + ("https://www.killernetworking.com"+(FindDynamicUrl "https://www.killernetworking.com/killersupport/category/other-downloads" "Download Killer-Ethernet").replace('&', '&')) + ), + # Notepad++ + @("npp_x86.7z", "https://notepad-plus-plus.org/repository/7.x/7.6.4/npp.7.6.4.bin.minimalist.7z"), + @("npp_amd64.7z", "https://notepad-plus-plus.org/repository/7.x/7.6.4/npp.7.6.4.bin.minimalist.x64.7z"), + # NT Password Editor + @("ntpwed.zip", "http://cdslow.org.ru/files/ntpwedit/ntpwed07.zip"), + # Prime95 + @("prime95_32.zip", "http://www.mersenne.org/ftp_root/gimps/p95v294b7.win32.zip"), + @("prime95_64.zip", "http://www.mersenne.org/ftp_root/gimps/p95v294b8.win64.zip"), + # ProduKey + @("produkey32.zip", "http://www.nirsoft.net/utils/produkey.zip"), + @("produkey64.zip", "http://www.nirsoft.net/utils/produkey-x64.zip"), + # Python + @("python32.zip", "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-win32.zip"), + @("python64.zip", "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-amd64.zip"), + # Python: psutil + @( + "psutil64.whl", + (FindDynamicUrl "https://pypi.org/project/psutil/" "href=.*-cp37-cp37m-win_amd64.whl") + ), + @( + "psutil32.whl", + (FindDynamicUrl "https://pypi.org/project/psutil/" "href=.*-cp37-cp37m-win32.whl") + ), + # Q-Dir + @("qdir32.zip", "https://www.softwareok.com/Download/Q-Dir_Portable.zip"), + @("qdir64.zip", "https://www.softwareok.com/Download/Q-Dir_Portable_x64.zip"), + # TestDisk / PhotoRec + @("testdisk32.zip", "https://www.cgsecurity.org/testdisk-7.1-WIP.win.zip"), + @("testdisk64.zip", "https://www.cgsecurity.org/testdisk-7.1-WIP.win64.zip"), + # VirtIO drivers + @("virtio-win.iso", "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso"), + # Visual C++ Runtimes + @("vcredist_x86.exe", "https://aka.ms/vs/15/release/vc_redist.x86.exe"), + @("vcredist_x64.exe", "https://aka.ms/vs/15/release/vc_redist.x64.exe"), + # wimlib-imagex + @("wimlib32.zip", "https://wimlib.net/downloads/wimlib-1.13.0-windows-i686-bin.zip"), + @("wimlib64.zip", "https://wimlib.net/downloads/wimlib-1.13.0-windows-x86_64-bin.zip") + ) + foreach ($Tool in $ToolSources) { + DownloadFile -Path $Temp -Name $Tool[0] -Url $Tool[1] + } + + ## Bail ## + # If errors were encountered during downloads + if ($DownloadErrors -gt 0) { + Abort + } + + ## Install ## + # Visual C++ Runtimes + Write-Host "Installing: Visual C++ Runtimes" + $ArgumentList = @("/install", "/passive", "/norestart") + Start-Process -FilePath "$Temp\vcredist_x86.exe" -ArgumentList $ArgumentList -Wait + Start-Process -FilePath "$Temp\vcredist_x64.exe" -ArgumentList $ArgumentList -Wait + + ## Extract ## + # 7-Zip + Write-Host "Extracting: 7-Zip" try { - Import-Module -Name $Env:DISMRoot -ErrorAction "stop" + $ArgumentList = @("/a", "$Temp\7z-installer.msi", "TARGETDIR=$Temp\7zi", "/qn") + Start-Process -FilePath "$HostSystem32\msiexec.exe" -ArgumentList $ArgumentList -Wait + $SevenZip = "$Temp\7zi\Files\7-Zip\7z.exe" + $ArgumentList = @( + "e", "$Temp\7z-extra.7z", "-o$Build\bin\amd64\7-Zip", + "-aoa", "-bso0", "-bse0", "-bsp0", + "x64\7za.exe", "*.txt") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "e", "$Temp\7z-extra.7z", "-o$Build\bin\x86\7-Zip", + "-aoa", "-bso0", "-bse0", "-bsp0", + "7za.exe", "*.txt") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait } catch { - Write-Host -ForegroundColor "Red" "ERROR: Failed to load DISM CmdLet" - Abort + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" } - Push-Location "$WD" - MakeClean - New-Item -Type Directory $Build 2>&1 | Out-Null - New-Item -Type Directory $LogDir 2>&1 | Out-Null - - ## main.py ## - if (!(Test-Path "$Build\main.py") -or (Ask-User "Replace existing main.py?")) { - Copy-Item -Path "$Bin\Scripts\settings\main.py" -Destination "$Build\main.py" -Force + + # Blue Screen View + Write-Host "Extracting: BlueScreenView" + try { + $ArgumentList = @( + "x", "$Temp\bluescreenview64.zip", "-o$Build\bin\amd64\BlueScreenView", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "x", "$Temp\bluescreenview32.zip", "-o$Build\bin\x86\BlueScreenView", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait } - WKPause "Press Enter to open settings..." - Start-Process "$HostSystem32\notepad.exe" -ArgumentList @("$Build\main.py") -Wait - $KitNameFull = (Get-Content "$Build\main.py" | Where-Object {$_ -match 'FULL'}) -replace ".*'(.*)'$", '$1' - $KitNameShort = (Get-Content "$Build\main.py" | Where-Object {$_ -match 'SHORT'}) -replace ".*'(.*)'$", '$1' - - if (Ask-User "Update Tools?") { - $DownloadErrors = 0 - - ## Download Tools ## - $ToolSources = @( - # 7-Zip - @("7z-installer.msi", "https://www.7-zip.org/a/7z1900.msi"), - @("7z-extra.7z", "https://www.7-zip.org/a/7z1900-extra.7z"), - # Blue Screen View - @("bluescreenview32.zip", "http://www.nirsoft.net/utils/bluescreenview.zip"), - @("bluescreenview64.zip", "http://www.nirsoft.net/utils/bluescreenview-x64.zip"), - # ConEmu - @("ConEmuPack.7z", "https://github.com/Maximus5/ConEmu/releases/download/v19.03.10/ConEmuPack.190310.7z"), - # Fast Copy - @("fastcopy.zip", "http://ftp.vector.co.jp/71/31/2323/FastCopy363_installer.exe"), - # HWiNFO - @("hwinfo.zip", "http://files2.majorgeeks.com/377527622c5325acc1cb937fb149d0de922320c0/systeminfo/hwi_602.zip"), - # Killer Network Drivers - @( - "killerinf.zip", - ("https://www.killernetworking.com"+(FindDynamicUrl "https://www.killernetworking.com/killersupport/category/other-downloads" "Download Killer-Ethernet").replace('&', '&')) - ), - # Notepad++ - @("npp_x86.7z", "https://notepad-plus-plus.org/repository/7.x/7.6.4/npp.7.6.4.bin.minimalist.7z"), - @("npp_amd64.7z", "https://notepad-plus-plus.org/repository/7.x/7.6.4/npp.7.6.4.bin.minimalist.x64.7z"), - # NT Password Editor - @("ntpwed.zip", "http://cdslow.org.ru/files/ntpwedit/ntpwed07.zip"), - # Prime95 - @("prime95_32.zip", "http://www.mersenne.org/ftp_root/gimps/p95v294b7.win32.zip"), - @("prime95_64.zip", "http://www.mersenne.org/ftp_root/gimps/p95v294b8.win64.zip"), - # ProduKey - @("produkey32.zip", "http://www.nirsoft.net/utils/produkey.zip"), - @("produkey64.zip", "http://www.nirsoft.net/utils/produkey-x64.zip"), - # Python - @("python32.zip", "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-win32.zip"), - @("python64.zip", "https://www.python.org/ftp/python/3.7.2/python-3.7.2.post1-embed-amd64.zip"), - # Python: psutil - @( - "psutil64.whl", - (FindDynamicUrl "https://pypi.org/project/psutil/" "href=.*-cp37-cp37m-win_amd64.whl") - ), - @( - "psutil32.whl", - (FindDynamicUrl "https://pypi.org/project/psutil/" "href=.*-cp37-cp37m-win32.whl") - ), - # Q-Dir - @("qdir32.zip", "https://www.softwareok.com/Download/Q-Dir_Portable.zip"), - @("qdir64.zip", "https://www.softwareok.com/Download/Q-Dir_Portable_x64.zip"), - # TestDisk / PhotoRec - @("testdisk32.zip", "https://www.cgsecurity.org/testdisk-7.1-WIP.win.zip"), - @("testdisk64.zip", "https://www.cgsecurity.org/testdisk-7.1-WIP.win64.zip"), - # VirtIO drivers - @("virtio-win.iso", "https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/latest-virtio/virtio-win.iso"), - # Visual C++ Runtimes - @("vcredist_x86.exe", "https://aka.ms/vs/15/release/vc_redist.x86.exe"), - @("vcredist_x64.exe", "https://aka.ms/vs/15/release/vc_redist.x64.exe"), - # wimlib-imagex - @("wimlib32.zip", "https://wimlib.net/downloads/wimlib-1.13.0-windows-i686-bin.zip"), - @("wimlib64.zip", "https://wimlib.net/downloads/wimlib-1.13.0-windows-x86_64-bin.zip") - ) - foreach ($Tool in $ToolSources) { - DownloadFile -Path $Temp -Name $Tool[0] -Url $Tool[1] - } - - ## Bail ## - # If errors were encountered during downloads - if ($DownloadErrors -gt 0) { - Abort - } - - ## Install ## - # Visual C++ Runtimes - Write-Host "Installing: Visual C++ Runtimes" - $ArgumentList = @("/install", "/passive", "/norestart") - Start-Process -FilePath "$Temp\vcredist_x86.exe" -ArgumentList $ArgumentList -Wait - Start-Process -FilePath "$Temp\vcredist_x64.exe" -ArgumentList $ArgumentList -Wait - - ## Extract ## - # 7-Zip - Write-Host "Extracting: 7-Zip" - try { - $ArgumentList = @("/a", "$Temp\7z-installer.msi", "TARGETDIR=$Temp\7zi", "/qn") - Start-Process -FilePath "$HostSystem32\msiexec.exe" -ArgumentList $ArgumentList -Wait - $SevenZip = "$Temp\7zi\Files\7-Zip\7z.exe" - $ArgumentList = @( - "e", "$Temp\7z-extra.7z", "-o$Build\bin\amd64\7-Zip", - "-aoa", "-bso0", "-bse0", "-bsp0", - "x64\7za.exe", "*.txt") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "e", "$Temp\7z-extra.7z", "-o$Build\bin\x86\7-Zip", - "-aoa", "-bso0", "-bse0", "-bsp0", - "7za.exe", "*.txt") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # Blue Screen View - Write-Host "Extracting: BlueScreenView" - try { - $ArgumentList = @( - "x", "$Temp\bluescreenview64.zip", "-o$Build\bin\amd64\BlueScreenView", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "x", "$Temp\bluescreenview32.zip", "-o$Build\bin\x86\BlueScreenView", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # ConEmu - Write-Host "Extracting: ConEmu" - try { - $ArgumentList = @( - "x", "$Temp\ConEmuPack.7z", "-o$Build\bin\amd64\ConEmu", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Remove-Item "$Build\bin\amd64\ConEmu\ConEmu.exe" - Remove-Item "$Build\bin\amd64\ConEmu\ConEmu.map" - Move-Item "$Build\bin\amd64\ConEmu\ConEmu64.exe" "$Build\bin\amd64\ConEmu\ConEmu.exe" -Force - Move-Item "$Build\bin\amd64\ConEmu\ConEmu64.map" "$Build\bin\amd64\ConEmu\ConEmu.map" -Force - $ArgumentList = @( - "x", "$Temp\ConEmuPack.7z", "-o$Build\bin\x86\ConEmu", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Remove-Item "$Build\bin\x86\ConEmu\ConEmu64.exe" - Remove-Item "$Build\bin\x86\ConEmu\ConEmu64.map" - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # Fast Copy - Write-Host "Extracting: FastCopy" - try { - # Extract Installer - $ArgumentList = @( - "e", "$Temp\fastcopy.zip", "-o$Temp", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - - # Extract 64-bit - $ArgumentList = @( - "/NOSUBDIR", "/DIR=$Build\bin\amd64\FastCopy", - "/EXTRACT64") - Start-Process -FilePath "$TEMP\FastCopy354_installer.exe" -ArgumentList $ArgumentList -NoNewWindow -Wait - Remove-Item "$Build\bin\amd64\FastCopy\setup.exe" -Force - - # Extract 32-bit - $ArgumentList = @( - "/NOSUBDIR", "/DIR=$Build\bin\x86\FastCopy", - "/EXTRACT32") - Start-Process -FilePath "$TEMP\FastCopy354_installer.exe" -ArgumentList $ArgumentList -NoNewWindow -Wait - Remove-Item "$Build\bin\x86\FastCopy\setup.exe" -Force - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - - # Killer Network Driver - Write-Host "Extracting: Killer Network Driver" - try { - $ArgumentList = @( - "e", "$Temp\killerinf.zip", "-o$Build\Drivers\amd64\Killer", - "-aoa", "-bso0", "-bse0", "-bsp0", - "Production\Windows10-x64\Eth\*") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "e", "$Temp\killerinf.zip", "-o$Build\Drivers\x86\Killer", - "-aoa", "-bso0", "-bse0", "-bsp0", - "Production\Windows10-x86\Eth\*") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # HWiNFO - Write-Host "Extracting: HWiNFO" - try { - $ArgumentList = @( - "e", "$Temp\hwinfo.zip", "-o$Build\bin\amd64\HWiNFO", - "-aoa", "-bso0", "-bse0", "-bsp0", "HWiNFO64.exe") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "e", "$Temp\hwinfo.zip", "-o$Build\bin\x86\HWiNFO", - "-aoa", "-bso0", "-bse0", "-bsp0", "HWiNFO32.exe") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Move-Item "$Build\bin\amd64\HWiNFO\HWiNFO64.exe" "$Build\bin\amd64\HWiNFO\HWiNFO.exe" -Force - Move-Item "$Build\bin\x86\HWiNFO\HWiNFO32.exe" "$Build\bin\x86\HWiNFO\HWiNFO.exe" -Force - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # Notepad++ - Write-Host "Extracting: Notepad++" - try { - $ArgumentList = @( - "x", "$Temp\npp_amd64.7z", "-o$Build\bin\amd64\NotepadPlusPlus", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "x", "$Temp\npp_x86.7z", "-o$Build\bin\x86\NotepadPlusPlus", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Move-Item "$Build\bin\amd64\NotepadPlusPlus\notepad++.exe" "$Build\bin\amd64\NotepadPlusPlus\notepadplusplus.exe" -Force - Move-Item "$Build\bin\x86\NotepadPlusPlus\notepad++.exe" "$Build\bin\x86\NotepadPlusPlus\notepadplusplus.exe" -Force - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # NT Password Editor - Write-Host "Extracting: NT Password Editor" - try { - $ArgumentList = @( - "e", "$Temp\ntpwed.zip", ('-o"{0}\bin\amd64\NT Password Editor"' -f $Build), - "-aoa", "-bso0", "-bse0", "-bsp0", - "ntpwedit64.exe", "*.txt") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Move-Item "$Build\bin\amd64\NT Password Editor\ntpwedit64.exe" "$Build\bin\amd64\NT Password Editor\ntpwedit.exe" -Force - $ArgumentList = @( - "e", "$Temp\ntpwed.zip", ('-o"{0}\bin\x86\NT Password Editor"' -f $Build), - "-aoa", "-bso0", "-bse0", "-bsp0", - "ntpwedit.exe", "*.txt") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # PhotoRec / TestDisk - Write-Host "Extracting: PhotoRec / TestDisk" - try { - $ArgumentList = @( - "x", "$Temp\testdisk64.zip", "-o$Build\bin\amd64\TestDisk", - "-aoa", "-bso0", "-bse0", "-bsp0") - # Remove destination since Move-Item -Force can't handle this recursive merge - Remove-Item "$Build\bin\amd64\TestDisk" -Recurse -Force 2>&1 | Out-Null - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Move-Item "$Build\bin\amd64\TestDisk\testdisk-7.1-WIP\*" "$Build\bin\amd64\TestDisk" -Force - Remove-Item "$Build\bin\amd64\TestDisk\testdisk-7.1-WIP" -Recurse -Force - $ArgumentList = @( - "x", "$Temp\testdisk32.zip", "-o$Build\bin\x86\TestDisk", - "-aoa", "-bso0", "-bse0", "-bsp0") - # Remove destination since Move-Item -Force can't handle this recursive merge - Remove-Item "$Build\bin\x86\TestDisk" -Recurse -Force 2>&1 | Out-Null - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Move-Item "$Build\bin\x86\TestDisk\testdisk-7.1-WIP\*" "$Build\bin\x86\TestDisk" -Force - Remove-Item "$Build\bin\x86\TestDisk\testdisk-7.1-WIP" -Recurse -Force - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # Prime95 - Write-Host "Extracting: Prime95" - try { - $ArgumentList = @( - "x", "$Temp\prime95_64.zip", "-o$Build\bin\amd64\Prime95", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "x", "$Temp\prime95_32.zip", "-o$Build\bin\x86\Prime95", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # ProduKey - try { - $ArgumentList = @( - "x", "$Temp\produkey64.zip", "-o$Build\bin\amd64\ProduKey", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "x", "$Temp\produkey32.zip", "-o$Build\bin\x86\ProduKey", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # Python (x64) - Write-Host "Extracting: Python (x64)" - try { - $ArgumentList = @( - "x", "$Temp\python64.zip", "-o$Build\bin\amd64\python", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "x", "$Temp\psutil64.whl", "-o$Build\bin\amd64\python", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - try { - Copy-Item -Path "$HostSystem32\vcruntime140.dll" -Destination "$Build\bin\amd64\python\vcruntime140.dll" -Force - } - catch { - Write-Host (" ERROR: Failed to copy Visual C++ Runtime DLL." ) -ForegroundColor "Red" - } - - # Python (x32) - Write-Host "Extracting: Python (x32)" - try { - $ArgumentList = @( - "x", "$Temp\python32.zip", "-o$Build\bin\x86\python", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "x", "$Temp\psutil32.whl", "-o$Build\bin\x86\python", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - try { - Copy-Item -Path "$HostSysWOW64\vcruntime140.dll" -Destination "$Build\bin\x86\python\vcruntime140.dll" -Force - } - catch { - Write-Host (" ERROR: Failed to copy Visual C++ Runtime DLL." ) -ForegroundColor "Red" - } - - # Q-Dir - Write-Host "Extracting: Q-Dir" - try { - $ArgumentList = @( - "x", "$Temp\qdir64.zip", "-o$Build\bin\amd64", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - Move-Item "$Build\bin\amd64\Q-Dir\Q-Dir_x64.exe" "$Build\bin\amd64\Q-Dir\Q-Dir.exe" -Force - $ArgumentList = @( - "x", "$Temp\qdir32.zip", "-o$Build\bin\x86", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # VirtIO Drivers - Write-Host "Extracting: VirtIO Drivers" - try { - $ArgumentList = @( - "e", "$Temp\virtio-win.iso", "-o$Build\Drivers\amd64\VirtIO", - "-aoa", "-bso0", "-bse0", "-bsp0", - "*\w10\amd64\*") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "e", "$Temp\virtio-win.iso", "-o$Build\Drivers\x86\VirtIO", - "-aoa", "-bso0", "-bse0", "-bsp0", - "*\w10\x86\*") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - # wimlib-imagex - try { - $ArgumentList = @( - "x", "$Temp\wimlib64.zip", "-o$Build\bin\amd64\wimlib", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @( - "x", "$Temp\wimlib32.zip", "-o$Build\bin\x86\wimlib", - "-aoa", "-bso0", "-bse0", "-bsp0") - Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait - } - catch { - Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" - } - - ## Cleanup ## - if (Ask-User "Delete temp files?") { - Remove-Item "$Temp" -Recurse - } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" } - - ## Build ## - foreach ($Arch in @("amd64", "x86")) { - $Drivers = "$Build\Drivers\$Arch" - $Mount = "$Build\Mount" - $PEFiles = "$Build\PEFiles\$Arch" - - # Copy WinPE files - Write-Host "Copying files..." - $Cmd = ("{0}\copype.cmd" -f $Env:WinPERoot) - Start-Process -FilePath $Cmd -ArgumentList @($Arch, $PEFiles) -NoNewWindow -Wait - - # Remove unwanted items - foreach ($SubDir in @("media", "media\Boot", "media\EFI\Microsoft\Boot")) { - foreach ($Item in Get-ChildItem "$PEFiles\$SubDir") { - if ($Item.Name -inotmatch "^(boot|efi|en-us|sources|fonts|resources|bcd|memtest)") { - Remove-Item -Path $Item.FullName -Recurse -Force - } - } - } - - # Mount image - Write-Host "Mounting image..." - New-Item -Path $Mount -ItemType "directory" -Force | Out-Null - Mount-WindowsImage -Path $Mount -ImagePath "$PEFiles\media\sources\boot.wim" -Index 1 -LogPath "$LogDir\DISM.log" - - # Add drivers - Add-WindowsDriver -Path $Mount -Driver $Drivers -Recurse -LogPath "$LogDir\DISM.log" - - # Add packages - Write-Host "Adding packages:" - $WinPEPackages = @( - "WinPE-EnhancedStorage", - "WinPE-FMAPI", - "WinPE-WMI", - "WinPE-SecureStartup" - ) - foreach ($Package in $WinPEPackages) { - $PackagePath = ("{0}\{1}\WinPE_OCs\{2}.cab" -f $Env:WinPERoot, $Arch, $Package) - Write-Host " $Package..." - Add-WindowsPackage –PackagePath $PackagePath –Path $Mount -LogPath "$LogDir\DISM.log" - $LangPackagePath = ("{0}\{1}\WinPE_OCs\en-us\{2}_en-us.cab" -f $Env:WinPERoot, $Arch, $Package) - if (Test-Path $LangPackagePath) { - Add-WindowsPackage –PackagePath $LangPackagePath –Path $Mount -LogPath "$LogDir\DISM.log" - } - } - - # Set RamDisk size - $ArgumentList = @( - ('/Image:"{0}"' -f $Mount), - "/Set-ScratchSpace:512", - ('/LogPath:"{0}\DISM.log"' -f $LogDir) - ) - Start-Process -FilePath $DISM -ArgumentList $ArgumentList -NoNewWindow -Wait - - # Add tools - Write-Host "Copying tools..." - Copy-Item -Path "$Build\bin\$Arch" -Destination "$Mount\.bin" -Recurse -Force - Copy-Item -Path "$Root\.pe_items\_include\*" -Destination "$Mount\.bin" -Recurse -Force - if ($Arch -eq "amd64") { - $DestIni = "$Mount\.bin\HWiNFO\HWiNFO64.INI" - } else { - $DestIni = "$Mount\.bin\HWiNFO\HWiNFO32.INI" - } - Move-Item -Path "$Mount\.bin\HWiNFO\HWiNFO.INI" -Destination $DestIni -Force - Copy-Item -Path "$Root\Images\WinPE.jpg" -Destination "$Mount\.bin\ConEmu\ConEmu.jpg" -Recurse -Force - Copy-Item -Path "$Bin\Scripts" -Destination "$Mount\.bin\Scripts" -Recurse -Force - Copy-Item -Path "$Build\main.py" -Destination "$Mount\.bin\Scripts\settings\main.py" -Force - - # Add System32 items - $HostSystem32 = "{0}\System32" -f $Env:SystemRoot - Copy-Item -Path "$Root\.pe_items\System32\*" -Destination "$Mount\Windows\System32" -Recurse -Force - $ArgumentList = @("/f", "$Mount\Windows\System32\winpe.jpg", "/a") - Start-Process -FilePath "$HostSystem32\takeown.exe" -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @("$Mount\Windows\System32\winpe.jpg", "/grant", "Administrators:F") - Start-Process -FilePath "$HostSystem32\icacls.exe" -ArgumentList $ArgumentList -NoNewWindow -Wait - Copy-Item -Path "$Root\Images\WinPE.jpg" -Destination "$Mount\Windows\System32\winpe.jpg" -Recurse -Force - - # Load registry hives - Write-Host "Updating Registry..." - $Reg = "$HostSystem32\reg.exe" - $ArgumentList = @("load", "HKLM\WinPE-SW", "$Mount\Windows\System32\config\SOFTWARE") - Start-Process -FilePath $Reg -ArgumentList $ArgumentList -NoNewWindow -Wait - $ArgumentList = @("load", "HKLM\WinPE-SYS", "$Mount\Windows\System32\config\SYSTEM") - Start-Process -FilePath $Reg -ArgumentList $ArgumentList -NoNewWindow -Wait - - # Add tools to path - ## .NET code to properly handle REG_EXPAND_SZ values - ## Credit: https://www.sepago.com/blog/2013/08/22/reading-and-writing-regexpandsz-data-with-powershell - ## By: Marius Gawenda - $Hive = [Microsoft.Win32.Registry]::LocalMachine - $RegPath = "WinPE-SYS\ControlSet001\Control\Session Manager\Environment" - $RegKey = $Hive.OpenSubKey($RegPath) - $CurValue = $RegKey.GetValue( - "Path", $false, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) - $NewValue = "$CurValue;%SystemDrive%\.bin\7-Zip;%SystemDrive%\.bin\python;%SystemDrive%\.bin\wimlib" - Set-ItemProperty -Path "HKLM:\$RegPath" -Name "Path" -Value $NewValue -Force | Out-Null - $Hive.close() - $RegKey.close() - - # Replace Notepad - $RegPath = "HKLM:\WinPE-SW\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" - $NewValue = 'cmd /c "%SystemDrive%\.bin\NotepadPlusPlus\npp.cmd"' - New-Item -Path $RegPath -Force | Out-Null - New-ItemProperty -Path $RegPath -Name "Debugger" -Value $NewValue -Force | Out-Null - - # Run garbage collection to release potential stale handles - ## Credit: https://jrich523.wordpress.com/2012/03/06/powershell-loading-and-unloading-registry-hives/ - Start-Sleep -Seconds 2 - [gc]::collect() - # Unload registry hives - Start-Sleep -Seconds 2 - Start-Process -FilePath $Reg -ArgumentList @("unload", "HKLM\WinPE-SW") -NoNewWindow -Wait - Start-Process -FilePath $Reg -ArgumentList @("unload", "HKLM\WinPE-SYS") -NoNewWindow -Wait - - # Unmount image - Write-Host "Dismounting image..." - Dismount-WindowsImage -Path $Mount -Save -LogPath "$LogDir\DISM.log" - - # Create ISO - New-Item -Type Directory "$Root\OUT_PE" 2>&1 | Out-Null - $ArgumentList = @("/iso", $PEFiles, "$Root\OUT_PE\$KitNameShort-WinPE-$Date-$Arch.iso") - $Cmd = "{0}\MakeWinPEMedia.cmd" -f $Env:WinPERoot - Start-Process -FilePath $Cmd -ArgumentList $ArgumentList -NoNewWindow -Wait + # ConEmu + Write-Host "Extracting: ConEmu" + try { + $ArgumentList = @( + "x", "$Temp\ConEmuPack.7z", "-o$Build\bin\amd64\ConEmu", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Remove-Item "$Build\bin\amd64\ConEmu\ConEmu.exe" + Remove-Item "$Build\bin\amd64\ConEmu\ConEmu.map" + Move-Item "$Build\bin\amd64\ConEmu\ConEmu64.exe" "$Build\bin\amd64\ConEmu\ConEmu.exe" -Force + Move-Item "$Build\bin\amd64\ConEmu\ConEmu64.map" "$Build\bin\amd64\ConEmu\ConEmu.map" -Force + $ArgumentList = @( + "x", "$Temp\ConEmuPack.7z", "-o$Build\bin\x86\ConEmu", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Remove-Item "$Build\bin\x86\ConEmu\ConEmu64.exe" + Remove-Item "$Build\bin\x86\ConEmu\ConEmu64.map" } - + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # Fast Copy + Write-Host "Extracting: FastCopy" + try { + # Extract Installer + $ArgumentList = @( + "e", "$Temp\fastcopy.zip", "-o$Temp", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + + # Extract 64-bit + $ArgumentList = @( + "/NOSUBDIR", "/DIR=$Build\bin\amd64\FastCopy", + "/EXTRACT64") + Start-Process -FilePath "$TEMP\FastCopy354_installer.exe" -ArgumentList $ArgumentList -NoNewWindow -Wait + Remove-Item "$Build\bin\amd64\FastCopy\setup.exe" -Force + + # Extract 32-bit + $ArgumentList = @( + "/NOSUBDIR", "/DIR=$Build\bin\x86\FastCopy", + "/EXTRACT32") + Start-Process -FilePath "$TEMP\FastCopy354_installer.exe" -ArgumentList $ArgumentList -NoNewWindow -Wait + Remove-Item "$Build\bin\x86\FastCopy\setup.exe" -Force + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + + # Killer Network Driver + Write-Host "Extracting: Killer Network Driver" + try { + $ArgumentList = @( + "e", "$Temp\killerinf.zip", "-o$Build\Drivers\amd64\Killer", + "-aoa", "-bso0", "-bse0", "-bsp0", + "Production\Windows10-x64\Eth\*") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "e", "$Temp\killerinf.zip", "-o$Build\Drivers\x86\Killer", + "-aoa", "-bso0", "-bse0", "-bsp0", + "Production\Windows10-x86\Eth\*") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # HWiNFO + Write-Host "Extracting: HWiNFO" + try { + $ArgumentList = @( + "e", "$Temp\hwinfo.zip", "-o$Build\bin\amd64\HWiNFO", + "-aoa", "-bso0", "-bse0", "-bsp0", "HWiNFO64.exe") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "e", "$Temp\hwinfo.zip", "-o$Build\bin\x86\HWiNFO", + "-aoa", "-bso0", "-bse0", "-bsp0", "HWiNFO32.exe") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Move-Item "$Build\bin\amd64\HWiNFO\HWiNFO64.exe" "$Build\bin\amd64\HWiNFO\HWiNFO.exe" -Force + Move-Item "$Build\bin\x86\HWiNFO\HWiNFO32.exe" "$Build\bin\x86\HWiNFO\HWiNFO.exe" -Force + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # Notepad++ + Write-Host "Extracting: Notepad++" + try { + $ArgumentList = @( + "x", "$Temp\npp_amd64.7z", "-o$Build\bin\amd64\NotepadPlusPlus", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "x", "$Temp\npp_x86.7z", "-o$Build\bin\x86\NotepadPlusPlus", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Move-Item "$Build\bin\amd64\NotepadPlusPlus\notepad++.exe" "$Build\bin\amd64\NotepadPlusPlus\notepadplusplus.exe" -Force + Move-Item "$Build\bin\x86\NotepadPlusPlus\notepad++.exe" "$Build\bin\x86\NotepadPlusPlus\notepadplusplus.exe" -Force + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # NT Password Editor + Write-Host "Extracting: NT Password Editor" + try { + $ArgumentList = @( + "e", "$Temp\ntpwed.zip", ('-o"{0}\bin\amd64\NT Password Editor"' -f $Build), + "-aoa", "-bso0", "-bse0", "-bsp0", + "ntpwedit64.exe", "*.txt") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Move-Item "$Build\bin\amd64\NT Password Editor\ntpwedit64.exe" "$Build\bin\amd64\NT Password Editor\ntpwedit.exe" -Force + $ArgumentList = @( + "e", "$Temp\ntpwed.zip", ('-o"{0}\bin\x86\NT Password Editor"' -f $Build), + "-aoa", "-bso0", "-bse0", "-bsp0", + "ntpwedit.exe", "*.txt") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # PhotoRec / TestDisk + Write-Host "Extracting: PhotoRec / TestDisk" + try { + $ArgumentList = @( + "x", "$Temp\testdisk64.zip", "-o$Build\bin\amd64\TestDisk", + "-aoa", "-bso0", "-bse0", "-bsp0") + # Remove destination since Move-Item -Force can't handle this recursive merge + Remove-Item "$Build\bin\amd64\TestDisk" -Recurse -Force 2>&1 | Out-Null + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Move-Item "$Build\bin\amd64\TestDisk\testdisk-7.1-WIP\*" "$Build\bin\amd64\TestDisk" -Force + Remove-Item "$Build\bin\amd64\TestDisk\testdisk-7.1-WIP" -Recurse -Force + $ArgumentList = @( + "x", "$Temp\testdisk32.zip", "-o$Build\bin\x86\TestDisk", + "-aoa", "-bso0", "-bse0", "-bsp0") + # Remove destination since Move-Item -Force can't handle this recursive merge + Remove-Item "$Build\bin\x86\TestDisk" -Recurse -Force 2>&1 | Out-Null + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Move-Item "$Build\bin\x86\TestDisk\testdisk-7.1-WIP\*" "$Build\bin\x86\TestDisk" -Force + Remove-Item "$Build\bin\x86\TestDisk\testdisk-7.1-WIP" -Recurse -Force + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # Prime95 + Write-Host "Extracting: Prime95" + try { + $ArgumentList = @( + "x", "$Temp\prime95_64.zip", "-o$Build\bin\amd64\Prime95", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "x", "$Temp\prime95_32.zip", "-o$Build\bin\x86\Prime95", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # ProduKey + try { + $ArgumentList = @( + "x", "$Temp\produkey64.zip", "-o$Build\bin\amd64\ProduKey", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "x", "$Temp\produkey32.zip", "-o$Build\bin\x86\ProduKey", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # Python (x64) + Write-Host "Extracting: Python (x64)" + try { + $ArgumentList = @( + "x", "$Temp\python64.zip", "-o$Build\bin\amd64\python", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "x", "$Temp\psutil64.whl", "-o$Build\bin\amd64\python", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + try { + Copy-Item -Path "$HostSystem32\vcruntime140.dll" -Destination "$Build\bin\amd64\python\vcruntime140.dll" -Force + } + catch { + Write-Host (" ERROR: Failed to copy Visual C++ Runtime DLL." ) -ForegroundColor "Red" + } + + # Python (x32) + Write-Host "Extracting: Python (x32)" + try { + $ArgumentList = @( + "x", "$Temp\python32.zip", "-o$Build\bin\x86\python", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "x", "$Temp\psutil32.whl", "-o$Build\bin\x86\python", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + try { + Copy-Item -Path "$HostSysWOW64\vcruntime140.dll" -Destination "$Build\bin\x86\python\vcruntime140.dll" -Force + } + catch { + Write-Host (" ERROR: Failed to copy Visual C++ Runtime DLL." ) -ForegroundColor "Red" + } + + # Q-Dir + Write-Host "Extracting: Q-Dir" + try { + $ArgumentList = @( + "x", "$Temp\qdir64.zip", "-o$Build\bin\amd64", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + Move-Item "$Build\bin\amd64\Q-Dir\Q-Dir_x64.exe" "$Build\bin\amd64\Q-Dir\Q-Dir.exe" -Force + $ArgumentList = @( + "x", "$Temp\qdir32.zip", "-o$Build\bin\x86", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # VirtIO Drivers + Write-Host "Extracting: VirtIO Drivers" + try { + $ArgumentList = @( + "e", "$Temp\virtio-win.iso", "-o$Build\Drivers\amd64\VirtIO", + "-aoa", "-bso0", "-bse0", "-bsp0", + "*\w10\amd64\*") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "e", "$Temp\virtio-win.iso", "-o$Build\Drivers\x86\VirtIO", + "-aoa", "-bso0", "-bse0", "-bsp0", + "*\w10\x86\*") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + + # wimlib-imagex + try { + $ArgumentList = @( + "x", "$Temp\wimlib64.zip", "-o$Build\bin\amd64\wimlib", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @( + "x", "$Temp\wimlib32.zip", "-o$Build\bin\x86\wimlib", + "-aoa", "-bso0", "-bse0", "-bsp0") + Start-Process -FilePath $SevenZip -ArgumentList $ArgumentList -NoNewWindow -Wait + } + catch { + Write-Host (" ERROR: Failed to extract files." ) -ForegroundColor "Red" + } + ## Cleanup ## - Remove-Item -Path "$Build\Mount" -Recurse -Force - Remove-Item -Path "$Build\PEFiles" -Recurse -Force + if (Ask-User "Delete temp files?") { + Remove-Item "$Temp" -Recurse + } + } - ## Done ## - Pop-Location - Write-Host "`nDone." - WKPause "Press Enter to exit... " + ## Build ## + foreach ($Arch in @("amd64", "x86")) { + $Drivers = "$Build\Drivers\$Arch" + $Mount = "$Build\Mount" + $PEFiles = "$Build\PEFiles\$Arch" + + # Copy WinPE files + Write-Host "Copying files..." + $Cmd = ("{0}\copype.cmd" -f $Env:WinPERoot) + Start-Process -FilePath $Cmd -ArgumentList @($Arch, $PEFiles) -NoNewWindow -Wait + + # Remove unwanted items + foreach ($SubDir in @("media", "media\Boot", "media\EFI\Microsoft\Boot")) { + foreach ($Item in Get-ChildItem "$PEFiles\$SubDir") { + if ($Item.Name -inotmatch "^(boot|efi|en-us|sources|fonts|resources|bcd|memtest)") { + Remove-Item -Path $Item.FullName -Recurse -Force + } + } + } + + # Mount image + Write-Host "Mounting image..." + New-Item -Path $Mount -ItemType "directory" -Force | Out-Null + Mount-WindowsImage -Path $Mount -ImagePath "$PEFiles\media\sources\boot.wim" -Index 1 -LogPath "$LogDir\DISM.log" + + # Add drivers + Add-WindowsDriver -Path $Mount -Driver $Drivers -Recurse -LogPath "$LogDir\DISM.log" + + # Add packages + Write-Host "Adding packages:" + $WinPEPackages = @( + "WinPE-EnhancedStorage", + "WinPE-FMAPI", + "WinPE-WMI", + "WinPE-SecureStartup" + ) + foreach ($Package in $WinPEPackages) { + $PackagePath = ("{0}\{1}\WinPE_OCs\{2}.cab" -f $Env:WinPERoot, $Arch, $Package) + Write-Host " $Package..." + Add-WindowsPackage –PackagePath $PackagePath –Path $Mount -LogPath "$LogDir\DISM.log" + $LangPackagePath = ("{0}\{1}\WinPE_OCs\en-us\{2}_en-us.cab" -f $Env:WinPERoot, $Arch, $Package) + if (Test-Path $LangPackagePath) { + Add-WindowsPackage –PackagePath $LangPackagePath –Path $Mount -LogPath "$LogDir\DISM.log" + } + } + + # Set RamDisk size + $ArgumentList = @( + ('/Image:"{0}"' -f $Mount), + "/Set-ScratchSpace:512", + ('/LogPath:"{0}\DISM.log"' -f $LogDir) + ) + Start-Process -FilePath $DISM -ArgumentList $ArgumentList -NoNewWindow -Wait + + # Add tools + Write-Host "Copying tools..." + Copy-Item -Path "$Build\bin\$Arch" -Destination "$Mount\.bin" -Recurse -Force + Copy-Item -Path "$Root\.pe_items\_include\*" -Destination "$Mount\.bin" -Recurse -Force + if ($Arch -eq "amd64") { + $DestIni = "$Mount\.bin\HWiNFO\HWiNFO64.INI" + } else { + $DestIni = "$Mount\.bin\HWiNFO\HWiNFO32.INI" + } + Move-Item -Path "$Mount\.bin\HWiNFO\HWiNFO.INI" -Destination $DestIni -Force + Copy-Item -Path "$Root\Images\WinPE.jpg" -Destination "$Mount\.bin\ConEmu\ConEmu.jpg" -Recurse -Force + Copy-Item -Path "$Bin\Scripts" -Destination "$Mount\.bin\Scripts" -Recurse -Force + Copy-Item -Path "$Build\main.py" -Destination "$Mount\.bin\Scripts\settings\main.py" -Force + + # Add System32 items + $HostSystem32 = "{0}\System32" -f $Env:SystemRoot + Copy-Item -Path "$Root\.pe_items\System32\*" -Destination "$Mount\Windows\System32" -Recurse -Force + $ArgumentList = @("/f", "$Mount\Windows\System32\winpe.jpg", "/a") + Start-Process -FilePath "$HostSystem32\takeown.exe" -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @("$Mount\Windows\System32\winpe.jpg", "/grant", "Administrators:F") + Start-Process -FilePath "$HostSystem32\icacls.exe" -ArgumentList $ArgumentList -NoNewWindow -Wait + Copy-Item -Path "$Root\Images\WinPE.jpg" -Destination "$Mount\Windows\System32\winpe.jpg" -Recurse -Force + + # Load registry hives + Write-Host "Updating Registry..." + $Reg = "$HostSystem32\reg.exe" + $ArgumentList = @("load", "HKLM\WinPE-SW", "$Mount\Windows\System32\config\SOFTWARE") + Start-Process -FilePath $Reg -ArgumentList $ArgumentList -NoNewWindow -Wait + $ArgumentList = @("load", "HKLM\WinPE-SYS", "$Mount\Windows\System32\config\SYSTEM") + Start-Process -FilePath $Reg -ArgumentList $ArgumentList -NoNewWindow -Wait + + # Add tools to path + ## .NET code to properly handle REG_EXPAND_SZ values + ## Credit: https://www.sepago.com/blog/2013/08/22/reading-and-writing-regexpandsz-data-with-powershell + ## By: Marius Gawenda + $Hive = [Microsoft.Win32.Registry]::LocalMachine + $RegPath = "WinPE-SYS\ControlSet001\Control\Session Manager\Environment" + $RegKey = $Hive.OpenSubKey($RegPath) + $CurValue = $RegKey.GetValue( + "Path", $false, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) + $NewValue = "$CurValue;%SystemDrive%\.bin\7-Zip;%SystemDrive%\.bin\python;%SystemDrive%\.bin\wimlib" + Set-ItemProperty -Path "HKLM:\$RegPath" -Name "Path" -Value $NewValue -Force | Out-Null + $Hive.close() + $RegKey.close() + + # Replace Notepad + $RegPath = "HKLM:\WinPE-SW\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" + $NewValue = 'cmd /c "%SystemDrive%\.bin\NotepadPlusPlus\npp.cmd"' + New-Item -Path $RegPath -Force | Out-Null + New-ItemProperty -Path $RegPath -Name "Debugger" -Value $NewValue -Force | Out-Null + + # Run garbage collection to release potential stale handles + ## Credit: https://jrich523.wordpress.com/2012/03/06/powershell-loading-and-unloading-registry-hives/ + Start-Sleep -Seconds 2 + [gc]::collect() + + # Unload registry hives + Start-Sleep -Seconds 2 + Start-Process -FilePath $Reg -ArgumentList @("unload", "HKLM\WinPE-SW") -NoNewWindow -Wait + Start-Process -FilePath $Reg -ArgumentList @("unload", "HKLM\WinPE-SYS") -NoNewWindow -Wait + + # Unmount image + Write-Host "Dismounting image..." + Dismount-WindowsImage -Path $Mount -Save -LogPath "$LogDir\DISM.log" + + # Create ISO + New-Item -Type Directory "$Root\OUT_PE" 2>&1 | Out-Null + $ArgumentList = @("/iso", $PEFiles, "$Root\OUT_PE\$KitNameShort-WinPE-$Date-$Arch.iso") + $Cmd = "{0}\MakeWinPEMedia.cmd" -f $Env:WinPERoot + Start-Process -FilePath $Cmd -ArgumentList $ArgumentList -NoNewWindow -Wait + } + + ## Cleanup ## + Remove-Item -Path "$Build\Mount" -Recurse -Force + Remove-Item -Path "$Build\PEFiles" -Recurse -Force + + ## Done ## + Pop-Location + Write-Host "`nDone." + WKPause "Press Enter to exit... " } diff --git a/scripts/init_client_dir.cmd b/scripts/init_client_dir.cmd index 302b27d1..6c99fbdf 100644 --- a/scripts/init_client_dir.cmd +++ b/scripts/init_client_dir.cmd @@ -10,12 +10,12 @@ if not defined bin (goto Abort) :: Credit to SS64.com Code taken from http://ss64.com/nt/syntax-getdate.html :: Use WMIC to retrieve date and time in ISO 8601 format. for /f "skip=1 tokens=1-6" %%G in ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') do ( - if "%%~L"=="" goto s_done - set _yyyy=%%L - set _mm=00%%J - set _dd=00%%G - set _hour=00%%H - set _minute=00%%I + if "%%~L"=="" goto s_done + set _yyyy=%%L + set _mm=00%%J + set _dd=00%%G + set _hour=00%%H + set _minute=00%%I ) :s_done :: Pad digits with leading zeros @@ -28,9 +28,9 @@ set iso_date=%_yyyy%-%_mm%-%_dd% :SetVars set "SETTINGS=%bin%\Scripts\settings\main.py" for /f "tokens=* usebackq" %%f in (`findstr KIT_NAME_SHORT "%SETTINGS%"`) do ( - set "_v=%%f" - set "_v=!_v:*'=!" - set "KIT_NAME_SHORT=!_v:~0,-1!" + set "_v=%%f" + set "_v=!_v:*'=!" + set "KIT_NAME_SHORT=!_v:~0,-1!" ) set "client_dir=%systemdrive%\%KIT_NAME_SHORT%" set "log_dir=%client_dir%\Logs\%iso_date%" @@ -43,20 +43,20 @@ set _quarantine= set _quickbooks= set _transfer= for %%f in (%*) do ( - if /i "%%f" == "/DEBUG" (@echo on) - if /i "%%f" == "/Backups" set _backups=True - if /i "%%f" == "/Logs" set _logs=True - if /i "%%f" == "/Office" set _office=True - if /i "%%f" == "/Quarantine" set _quarantine=True - if /i "%%f" == "/QuickBooks" set _quickbooks=True - if /i "%%f" == "/Transfer" set _transfer=True + if /i "%%f" == "/DEBUG" (@echo on) + if /i "%%f" == "/Backups" set _backups=True + if /i "%%f" == "/Logs" set _logs=True + if /i "%%f" == "/Office" set _office=True + if /i "%%f" == "/Quarantine" set _quarantine=True + if /i "%%f" == "/QuickBooks" set _quickbooks=True + if /i "%%f" == "/Transfer" set _transfer=True ) :CreateDirs if defined _backups mkdir "%client_dir%\Backups">nul 2>&1 if defined _logs ( - mkdir "%log_dir%\%KIT_NAME_FULL%">nul 2>&1 - mkdir "%log_dir%\Tools">nul 2>&1) + mkdir "%log_dir%\%KIT_NAME_FULL%">nul 2>&1 + mkdir "%log_dir%\Tools">nul 2>&1) if defined _office mkdir "%client_dir%\Office">nul 2>&1 if defined _quarantine mkdir "%client_dir%\Quarantine">nul 2>&1 if defined _quickbooks mkdir "%client_dir%\QuickBooks">nul 2>&1 diff --git a/scripts/wk/hw/diags.py b/scripts/wk/hw/diags.py index ce6c9c51..40b84e2e 100644 --- a/scripts/wk/hw/diags.py +++ b/scripts/wk/hw/diags.py @@ -619,7 +619,7 @@ def check_self_test_results(test_obj, aborted=False): # known progress instead of just "was aborted buy host" test_details = test_obj.dev.get_smart_self_test_details() test_result = test_details.get('status', {}).get('string', 'Unknown') - test_obj.report.append(f' {test_result}') + test_obj.report.append(f' {test_result.capitalize()}') if aborted and not (test_obj.passed or test_obj.failed): test_obj.report.append(std.color_string(' Aborted', 'YELLOW')) test_obj.set_status('Aborted') @@ -895,6 +895,8 @@ def disk_self_test(state, test_objects): test_obj.failed = True result = 'TimedOut' except hw_obj.SMARTNotSupportedError: + # Pass test since it doesn't apply + test_obj.passed = True result = 'N/A' # Set status diff --git a/scripts/wk/hw/obj.py b/scripts/wk/hw/obj.py index 205d857a..1facbc15 100644 --- a/scripts/wk/hw/obj.py +++ b/scripts/wk/hw/obj.py @@ -163,6 +163,11 @@ class Disk(BaseObj): self.get_details() self.enable_smart() self.update_smart_details() + if self.details['bus'] == 'USB' and not self.attributes: + # Try using SAT + LOG.warning('Using SAT for smartctl for %s', self.path) + self.enable_smart(use_sat=True) + self.update_smart_details(use_sat=True) if not self.is_4k_aligned(): self.add_note('One or more partitions are not 4K aligned', 'YELLOW') @@ -218,11 +223,12 @@ class Disk(BaseObj): test.set_status('Denied') test.disabled = True - def enable_smart(self): + def enable_smart(self, use_sat=False): """Try enabling SMART for this disk.""" cmd = [ 'sudo', 'smartctl', + f'--device={"sat,auto" if use_sat else "auto"}', '--tolerance=permissive', '--smart=on', self.path, @@ -500,12 +506,23 @@ class Disk(BaseObj): # Done return result - def update_smart_details(self): + def update_smart_details(self, use_sat=False): """Update SMART details via smartctl.""" self.attributes = {} + + # Check if SAT is needed + if not use_sat: + # use_sat not set, check previous run (if possible) + for arg in self.smartctl.get('smartctl', {}).get('argv', []): + if arg == '--device=sat,auto': + use_sat = True + break + + # Get SMART data cmd = [ 'sudo', 'smartctl', + f'--device={"sat,auto" if use_sat else "auto"}', '--tolerance=verypermissive', '--all', '--json', diff --git a/scripts/wk/kit/ufd.py b/scripts/wk/kit/ufd.py index f432a3f3..dcbd572b 100644 --- a/scripts/wk/kit/ufd.py +++ b/scripts/wk/kit/ufd.py @@ -15,6 +15,7 @@ from wk import io, log, std from wk.cfg.main import KIT_NAME_FULL, KIT_NAME_SHORT from wk.cfg.ufd import BOOT_ENTRIES, BOOT_FILES, ITEMS, ITEMS_HIDDEN, SOURCES from wk.exe import run_program +from wk.hw.obj import Disk from wk.os import linux @@ -391,6 +392,8 @@ def show_selections(args, sources, ufd_dev, ufd_sources): def update_boot_entries(): """Update boot files for UFD usage""" configs = [] + ufd = Disk('/mnt/UFD') + uuid = ufd.details.get('uuid') # Find config files for c_path, c_ext in BOOT_FILES.items(): @@ -399,12 +402,12 @@ def update_boot_entries(): if item.name.lower().endswith(c_ext.lower()): configs.append(item.path) - # Update Linux labels + # Use UUID instead of label cmd = [ 'sed', '--in-place', '--regexp-extended', - f's/{ISO_LABEL}/{UFD_LABEL}/', + f's#archisolabel={ISO_LABEL}#archisodevice=/dev/disk/by-uuid/{uuid}#', *configs, ] run_program(cmd) diff --git a/setup/build_linux b/setup/build_linux index 50f84190..17547a33 100755 --- a/setup/build_linux +++ b/setup/build_linux @@ -20,430 +20,493 @@ SKEL_DIR="$LIVE_DIR/airootfs/etc/skel" TEMP_DIR="$BUILD_DIR/temp" MIRRORLIST_SOURCE='https://www.archlinux.org/mirrorlist/?country=US&protocol=http&protocol=https&ip_version=4&use_mirror_status=on' if which nano >/dev/null 2>&1; then - EDITOR=nano + EDITOR=nano elif which vim >/dev/null 2>&1; then - EDITOR=vim + EDITOR=vim else - EDITOR=vi + EDITOR=vi fi if [ ! -z ${SUDO_USER+x} ]; then - REAL_USER="$SUDO_USER" + REAL_USER="$SUDO_USER" fi function ask() { - while :; do - read -p "$1 [Y/N] " -r answer - if echo "$answer" | egrep -iq '^(y|yes|sure)$'; then - return 0 - elif echo "$answer" | egrep -iq '^(n|no|nope)$'; then - return 1 - fi - done + while :; do + read -p "$1 [Y/N] " -r answer + if echo "$answer" | egrep -iq '^(y|yes|sure)$'; then + return 0 + elif echo "$answer" | egrep -iq '^(n|no|nope)$'; then + return 1 + fi + done } - + function cleanup() { - for d in "$TEMP_DIR" "$LIVE_DIR"; do - if [[ -d "$d" ]]; then - if ask "Remove: ${d}?"; then - rm -Rf "$d" - fi - fi - done - mkdir -p "$BUILD_DIR" 2>/dev/null - mkdir -p "$LOG_DIR" 2>/dev/null - mkdir -p "$OUT_DIR" 2>/dev/null - mkdir -p "$TEMP_DIR" 2>/dev/null + for d in "$TEMP_DIR" "$LIVE_DIR"; do + if [[ -d "$d" ]]; then + if ask "Remove: ${d}?"; then + rm -Rf "$d" + fi + fi + done + mkdir -p "$BUILD_DIR" 2>/dev/null + mkdir -p "$LOG_DIR" 2>/dev/null + mkdir -p "$OUT_DIR" 2>/dev/null + mkdir -p "$TEMP_DIR" 2>/dev/null } function fix_kit_permissions() { - # GitHub zip archives don't preserve the correct permissions - for d in docs images scripts setup; do - find "$ROOT_DIR/$d" -type d -exec chmod 755 "{}" \; - done + # GitHub zip archives don't preserve the correct permissions + for d in docs images scripts setup; do + find "$ROOT_DIR/$d" -type d -exec chmod 755 "{}" \; + done } function load_settings() { - # Check if settings already loaded - ## Code based on StackOverflow Q&A - ## Question: https://stackoverflow.com/q/3601515 - ## Asked by: https://stackoverflow.com/users/260127/prosseek - ## Edited by: https://stackoverflow.com/users/3924118/nbro - ## Answer: https://stackoverflow.com/a/13864829 - ## Answer by: https://stackoverflow.com/users/1633643/lionel - ## Answer edit: https://stackoverflow.com/users/-1/community - _main_path="$BUILD_DIR/main.py" - if [ ! -z ${KIT_NAME_FULL+x} ]; then - # KIT_NAME_FULL is set - return 0 # Skip loading settings from main.py + # Check if settings already loaded + ## Code based on StackOverflow Q&A + ## Question: https://stackoverflow.com/q/3601515 + ## Asked by: https://stackoverflow.com/users/260127/prosseek + ## Edited by: https://stackoverflow.com/users/3924118/nbro + ## Answer: https://stackoverflow.com/a/13864829 + ## Answer by: https://stackoverflow.com/users/1633643/lionel + ## Answer edit: https://stackoverflow.com/users/-1/community + _main_path="$BUILD_DIR/main.py" + if [ ! -z ${KIT_NAME_FULL+x} ]; then + # KIT_NAME_FULL is set + return 0 # Skip loading settings from main.py + fi + + if [[ "${1:-}" == "--edit" ]]; then + # Copy settings + if [[ ! -e "$BUILD_DIR/main.py" ]] || ask "Overwrite main.py?"; then + cp -bv "$ROOT_DIR/scripts/wk/cfg/main.py" "$BUILD_DIR/main.py" + dos2unix "$BUILD_DIR/main.py" fi - if [[ "${1:-}" == "--edit" ]]; then - # Copy settings - if [[ ! -e "$BUILD_DIR/main.py" ]] || ask "Overwrite main.py?"; then - cp -bv "$ROOT_DIR/scripts/wk/cfg/main.py" "$BUILD_DIR/main.py" - dos2unix "$BUILD_DIR/main.py" - fi + # Edit settings + read -p "Press Enter to open settings... " -r + "$EDITOR" "$BUILD_DIR/main.py" + else + # Load settings from $LIVE_DIR + _main_path="$LIVE_DIR/airootfs/usr/local/bin/wk/cfg/main.py" + fi - # Edit settings - read -p "Press Enter to open settings... " -r - "$EDITOR" "$BUILD_DIR/main.py" - else - # Load settings from $LIVE_DIR - _main_path="$LIVE_DIR/airootfs/usr/local/bin/wk/cfg/main.py" + # Load settings + while read line; do + if echo "$line" | egrep -q "^\w+='"; then + line="$(echo "$line" | sed -r 's/[\r\n]+//')" + eval "$line" fi - - # Load settings - while read line; do - if echo "$line" | egrep -q "^\w+='"; then - line="$(echo "$line" | sed -r 's/[\r\n]+//')" - eval "$line" - fi - done < "$_main_path" + done < "$_main_path" } function copy_live_env() { - echo "Copying Archlinux files..." - rsync -aI /usr/share/archiso/configs/releng/ "$LIVE_DIR/" + echo "Copying Archlinux files..." + rsync -aI /usr/share/archiso/configs/releng/ "$LIVE_DIR/" - # Remove items - rm "$LIVE_DIR/airootfs/etc/systemd/scripts/choose-mirror" - rmdir "$LIVE_DIR/airootfs/etc/systemd/scripts" --ignore-fail-on-non-empty - rm "$LIVE_DIR/airootfs/etc/systemd/system/choose-mirror.service" - rm "$LIVE_DIR/airootfs/etc/systemd/system/etc-pacman.d-gnupg.mount" - rm "$LIVE_DIR/airootfs/etc/systemd/system/pacman-init.service" - rm "$LIVE_DIR/airootfs/etc/udev/rules.d/81-dhcpcd.rules" - rmdir "$LIVE_DIR/airootfs/etc/udev/rules.d" --ignore-fail-on-non-empty - rmdir "$LIVE_DIR/airootfs/etc/udev" --ignore-fail-on-non-empty - rm "$LIVE_DIR/isolinux"/*.cfg - rm "$LIVE_DIR/syslinux"/*.cfg "$LIVE_DIR/syslinux"/*.png - - # Add items - rsync -aI "$ROOT_DIR/setup/linux/include/" "$LIVE_DIR/" - if [[ "${1:-}" != "--minimal" ]]; then - rsync -aI "$ROOT_DIR/setup/linux/include_x/" "$LIVE_DIR/" - fi - mkdir -p "$LIVE_DIR/airootfs/usr/local/bin" - rsync -aI "$ROOT_DIR/scripts/" "$LIVE_DIR/airootfs/usr/local/bin/" - cp -a "$BUILD_DIR/main.py" "$LIVE_DIR/airootfs/usr/local/bin/wk/cfg/" + # Remove items + rm "$LIVE_DIR/airootfs/etc/systemd/scripts/choose-mirror" + rmdir "$LIVE_DIR/airootfs/etc/systemd/scripts" --ignore-fail-on-non-empty + rm "$LIVE_DIR/airootfs/etc/systemd/system/choose-mirror.service" + rm "$LIVE_DIR/airootfs/etc/systemd/system/etc-pacman.d-gnupg.mount" + rm "$LIVE_DIR/airootfs/etc/systemd/system/pacman-init.service" + rm "$LIVE_DIR/airootfs/etc/udev/rules.d/81-dhcpcd.rules" + rmdir "$LIVE_DIR/airootfs/etc/udev/rules.d" --ignore-fail-on-non-empty + rmdir "$LIVE_DIR/airootfs/etc/udev" --ignore-fail-on-non-empty + rm "$LIVE_DIR/isolinux"/*.cfg + rm "$LIVE_DIR/syslinux"/*.cfg "$LIVE_DIR/syslinux"/*.png + + # Add items + rsync -aI "$ROOT_DIR/setup/linux/include/" "$LIVE_DIR/" + if [[ "${1:-}" != "--minimal" ]]; then + rsync -aI "$ROOT_DIR/setup/linux/include_x/" "$LIVE_DIR/" + fi + mkdir -p "$LIVE_DIR/airootfs/usr/local/bin" + rsync -aI "$ROOT_DIR/scripts/" "$LIVE_DIR/airootfs/usr/local/bin/" + cp -a "$BUILD_DIR/main.py" "$LIVE_DIR/airootfs/usr/local/bin/wk/cfg/" } function run_elevated() { - prog="$1" - shift - if which sudo >/dev/null 2>&1; then - if ! sudo "$prog" $*; then - echo "ERROR: Failed to run '$prog'" - if ask "Retry?"; then - sudo "$prog" $* - fi - fi - else - echo -n "Root " - if ! su -c "export REAL_USER=$USER && '$prog' $*"; then - echo "ERROR: Failed to run '$prog'" - if ask "Retry?"; then - su -c "export REAL_USER=$USER && '$prog' $*" - fi - fi + prog="$1" + shift + if which sudo >/dev/null 2>&1; then + if ! sudo "$prog" $*; then + echo "ERROR: Failed to run '$prog'" + if ask "Retry?"; then + sudo "$prog" $* + fi fi + else + echo -n "Root " + if ! su -c "export REAL_USER=$USER && '$prog' $*"; then + echo "ERROR: Failed to run '$prog'" + if ask "Retry?"; then + su -c "export REAL_USER=$USER && '$prog' $*" + fi + fi + fi } function update_live_env() { - hostname="$(echo "${KIT_NAME_SHORT}-linux" | tr "[:upper:]" "[:lower:]")" - username="tech" - label="${KIT_NAME_SHORT}_LINUX" + hostname="$(echo "${KIT_NAME_SHORT}-linux" | tr "[:upper:]" "[:lower:]")" + username="tech" + label="${KIT_NAME_SHORT}_LINUX" - # Boot config (legacy) - mkdir -p "$LIVE_DIR/arch" - cp "$ROOT_DIR/images/Pxelinux.png" "$LIVE_DIR/arch/pxelinux.png" - cp "$ROOT_DIR/images/Syslinux.png" "$LIVE_DIR/arch/syslinux.png" - sed -i -r "s/_+/$KIT_NAME_FULL/" "$LIVE_DIR/syslinux/wk_head.cfg" - mkdir -p "$TEMP_DIR" 2>/dev/null - curl -Lo "$TEMP_DIR/wimboot.zip" "http://git.ipxe.org/releases/wimboot/wimboot-latest.zip" - 7z e "$TEMP_DIR/wimboot.zip" -o"$LIVE_DIR/arch/boot" 'wimboot*/LICENSE.txt' 'wimboot*/README.txt' 'wimboot*/wimboot' + # Boot config (legacy) + mkdir -p "$LIVE_DIR/arch" + cp "$ROOT_DIR/images/Pxelinux.png" "$LIVE_DIR/arch/pxelinux.png" + cp "$ROOT_DIR/images/Syslinux.png" "$LIVE_DIR/arch/syslinux.png" + sed -i -r "s/_+/$KIT_NAME_FULL/" "$LIVE_DIR/syslinux/wk_head.cfg" + mkdir -p "$TEMP_DIR" 2>/dev/null + curl -Lo "$TEMP_DIR/wimboot.zip" "http://git.ipxe.org/releases/wimboot/wimboot-latest.zip" + 7z e -aoa "$TEMP_DIR/wimboot.zip" -o"$LIVE_DIR/arch/boot" 'wimboot*/LICENSE.txt' 'wimboot*/README.txt' 'wimboot*/wimboot' - # Boot config (UEFI) - mkdir -p "$LIVE_DIR/EFI/boot" - cp "/usr/share/refind/refind_x64.efi" "$LIVE_DIR/EFI/boot/bootx64.efi" - cp "$ROOT_DIR/images/rEFInd.png" "$LIVE_DIR/EFI/boot/rEFInd.png" - rsync -aI "/usr/share/refind/drivers_x64/" "$LIVE_DIR/EFI/boot/drivers_x64/" - rsync -aI "/usr/share/refind/icons/" "$LIVE_DIR/EFI/boot/icons/" --exclude "/usr/share/refind/icons/svg" - sed -i "s/%ARCHISO_LABEL%/${label}/" "$LIVE_DIR/EFI/boot/refind.conf" + # Boot config (UEFI) + mkdir -p "$LIVE_DIR/EFI/boot" + cp "/usr/share/refind/refind_x64.efi" "$LIVE_DIR/EFI/boot/bootx64.efi" + cp "$ROOT_DIR/images/rEFInd.png" "$LIVE_DIR/EFI/boot/rEFInd.png" + rsync -aI "/usr/share/refind/drivers_x64/" "$LIVE_DIR/EFI/boot/drivers_x64/" + rsync -aI "/usr/share/refind/icons/" "$LIVE_DIR/EFI/boot/icons/" --exclude "/usr/share/refind/icons/svg" + sed -i "s/%ARCHISO_LABEL%/${label}/" "$LIVE_DIR/EFI/boot/refind.conf" - # Customize_airootfs.sh - sed -i -r 's/set -e -u/set -o errexit\nset -o errtrace\nset -o nounset\nset -o pipefail/' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + # Customize_airootfs.sh + sed -i -r 's/set -e -u/set -o errexit\nset -o errtrace\nset -o nounset\nset -o pipefail/' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - # Memtest86 - mkdir -p "$LIVE_DIR/EFI/memtest86/Benchmark" - mkdir -p "$TEMP_DIR/memtest86" - curl -Lo "$TEMP_DIR/memtest86/memtest86-usb.zip" "https://www.memtest86.com/downloads/memtest86-usb.zip" - 7z e "$TEMP_DIR/memtest86/memtest86-usb.zip" -o"$TEMP_DIR/memtest86" "memtest86-usb.img" - 7z e "$TEMP_DIR/memtest86/memtest86-usb.img" -o"$TEMP_DIR/memtest86" "MemTest86.img" - 7z x "$TEMP_DIR/memtest86/MemTest86.img" -o"$TEMP_DIR/memtest86" - rm "$TEMP_DIR/memtest86/EFI/BOOT/BOOTIA32.efi" - mv "$TEMP_DIR/memtest86/EFI/BOOT/BOOTX64.efi" "$LIVE_DIR/EFI/memtest86/memtestx64.efi" - mv "$TEMP_DIR/memtest86/EFI/BOOT"/* "$LIVE_DIR/EFI/memtest86"/ - mv "$TEMP_DIR/memtest86/help"/* "$LIVE_DIR/EFI/memtest86"/ - mv "$TEMP_DIR/memtest86/license.rtf" "$LIVE_DIR/EFI/memtest86"/ + # Memtest86 + mkdir -p "$LIVE_DIR/EFI/memtest86/Benchmark" + mkdir -p "$TEMP_DIR/memtest86" + curl -Lo "$TEMP_DIR/memtest86/memtest86-usb.zip" "https://www.memtest86.com/downloads/memtest86-usb.zip" + 7z e -aoa "$TEMP_DIR/memtest86/memtest86-usb.zip" -o"$TEMP_DIR/memtest86" "memtest86-usb.img" + 7z e -aoa "$TEMP_DIR/memtest86/memtest86-usb.img" -o"$TEMP_DIR/memtest86" "MemTest86.img" + 7z x -aoa "$TEMP_DIR/memtest86/MemTest86.img" -o"$TEMP_DIR/memtest86" + rm "$TEMP_DIR/memtest86/EFI/BOOT/BOOTIA32.efi" + mv "$TEMP_DIR/memtest86/EFI/BOOT/BOOTX64.efi" "$LIVE_DIR/EFI/memtest86/memtestx64.efi" + mv "$TEMP_DIR/memtest86/EFI/BOOT"/* "$LIVE_DIR/EFI/memtest86"/ + mv "$TEMP_DIR/memtest86/help"/* "$LIVE_DIR/EFI/memtest86"/ + mv "$TEMP_DIR/memtest86/license.rtf" "$LIVE_DIR/EFI/memtest86"/ - # build.sh - if ! grep -iq 'wizardkit additions' "$LIVE_DIR/build.sh"; then - sed -i -r 's/^(run_once make_iso)$/# wizardkit additions\n\1/' "$LIVE_DIR/build.sh" - sed -i '/# wizardkit additions/r .linux_items/build_additions.txt' "$LIVE_DIR/build.sh" - fi + # build.sh + if ! grep -iq 'wizardkit additions' "$LIVE_DIR/build.sh"; then + sed -i -r 's/^(run_once make_iso)$/# wizardkit additions\n\1/' "$LIVE_DIR/build.sh" + sed -i '/# wizardkit additions/r .linux_items/build_additions.txt' "$LIVE_DIR/build.sh" + fi - # Hostname - echo "$hostname" > "$LIVE_DIR/airootfs/etc/hostname" - echo "127.0.1.1 $hostname.localdomain $hostname" >> "$LIVE_DIR/airootfs/etc/hosts" - - # Live packages - while read -r p; do - sed -i "/$p/d" "$LIVE_DIR/packages.x86_64" - done < "$ROOT_DIR/setup/linux/packages/live_remove" - cat "$ROOT_DIR/setup/linux/packages/live_add" >> "$LIVE_DIR/packages.x86_64" - if [[ "${1:-}" == "--minimal" ]]; then - cat "$ROOT_DIR/setup/linux/packages/live_add_min" >> "$LIVE_DIR/packages.x86_64" - else - cat "$ROOT_DIR/setup/linux/packages/live_add_x" >> "$LIVE_DIR/packages.x86_64" - fi - echo "[custom]" >> "$LIVE_DIR/pacman.conf" - echo "SigLevel = Optional TrustAll" >> "$LIVE_DIR/pacman.conf" - echo "Server = file://$REPO_DIR" >> "$LIVE_DIR/pacman.conf" - echo "" >> "$LIVE_DIR/pacman.conf" + # Hostname + echo "$hostname" > "$LIVE_DIR/airootfs/etc/hostname" + echo "127.0.1.1 $hostname.localdomain $hostname" >> "$LIVE_DIR/airootfs/etc/hosts" - # Mirrors - sed -i -r 's/^(.*mirrorlist.*)$/#NOPE#\1/' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo "curl -o '/etc/pacman.d/mirrorlist' '$MIRRORLIST_SOURCE'" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo "sed -i 's/#Server/Server/g' /etc/pacman.d/mirrorlist" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - - # MOTD - sed -i -r "s/_+/$KIT_NAME_FULL Linux Environment/" "$LIVE_DIR/airootfs/etc/motd" + # Live packages + while read -r p; do + sed -i "/$p/d" "$LIVE_DIR/packages.x86_64" + done < "$ROOT_DIR/setup/linux/packages/live_remove" + cat "$ROOT_DIR/setup/linux/packages/live_add" >> "$LIVE_DIR/packages.x86_64" + if [[ "${1:-}" == "--minimal" ]]; then + cat "$ROOT_DIR/setup/linux/packages/live_add_min" >> "$LIVE_DIR/packages.x86_64" + else + cat "$ROOT_DIR/setup/linux/packages/live_add_x" >> "$LIVE_DIR/packages.x86_64" + fi + echo "[custom]" >> "$LIVE_DIR/pacman.conf" + echo "SigLevel = Optional TrustAll" >> "$LIVE_DIR/pacman.conf" + echo "Server = file://$REPO_DIR" >> "$LIVE_DIR/pacman.conf" + echo "" >> "$LIVE_DIR/pacman.conf" - # Oh My ZSH - git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git "$SKEL_DIR/.oh-my-zsh" - rm -Rf "$SKEL_DIR/.oh-my-zsh/.git" - curl -o "$SKEL_DIR/.oh-my-zsh/themes/lean.zsh-theme" https://raw.githubusercontent.com/miekg/lean/master/prompt_lean_setup - - if [[ "${1:-}" != "--minimal" ]]; then - # Openbox theme - git clone --depth=1 https://github.com/addy-dclxvi/Openbox-Theme-Collections.git "$TEMP_DIR/ob-themes" - mkdir -p "$LIVE_DIR/airootfs/usr/share/themes" - cp -a "$TEMP_DIR/ob-themes/Triste-Orange" "$LIVE_DIR/airootfs/usr/share/themes/" - fi + # Mirrors + sed -i -r 's/^(.*mirrorlist.*)$/#NOPE#\1/' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo "curl -o '/etc/pacman.d/mirrorlist' '$MIRRORLIST_SOURCE'" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo "sed -i 's/#Server/Server/g' /etc/pacman.d/mirrorlist" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - # Services - sed -i -r 's/^(.*pacman-init.*)$/#NOPE#\1/' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - sed -i -r 's/^(.*choose-mirror.*)$/#NOPE#\1/' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + # MOTD + sed -i -r "s/_+/$KIT_NAME_FULL Linux Environment/" "$LIVE_DIR/airootfs/etc/motd" - # Shutdown stall fix - echo "sed -i -r 's/^.*(DefaultTimeoutStartSec)=.*$/\1=15s/' /etc/systemd/system.conf" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo "sed -i -r 's/^.*(DefaultTimeoutStopSec)=.*$/\1=15s/' /etc/systemd/system.conf" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - - # SSH - mkdir -p "$SKEL_DIR/.ssh" - ssh-keygen -b 4096 -C "$username@$hostname" -N "" -f "$SKEL_DIR/.ssh/id_rsa" - echo 'rm /root/.ssh/id*' >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo 'rm /root/.zlogin' >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - sed -i -r '/.*PermitRootLogin.*/d' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo "sed -i -r '/.*PermitRootLogin.*/d' /etc/ssh/sshd_config" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - cp "$ROOT_DIR/setup/linux/authorized_keys" "$SKEL_DIR/.ssh/authorized_keys" - - # Root user - echo "echo 'root:$ROOT_PASSWORD' | chpasswd" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + # Oh My ZSH + git clone --depth=1 https://github.com/robbyrussell/oh-my-zsh.git "$SKEL_DIR/.oh-my-zsh" + rm -Rf "$SKEL_DIR/.oh-my-zsh/.git" + curl -o "$SKEL_DIR/.oh-my-zsh/themes/lean.zsh-theme" https://raw.githubusercontent.com/miekg/lean/master/prompt_lean_setup - # Sudo - echo "echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + if [[ "${1:-}" != "--minimal" ]]; then + # Openbox theme + git clone --depth=1 https://github.com/addy-dclxvi/Openbox-Theme-Collections.git "$TEMP_DIR/ob-themes" + mkdir -p "$LIVE_DIR/airootfs/usr/share/themes" + cp -a "$TEMP_DIR/ob-themes/Triste-Orange" "$LIVE_DIR/airootfs/usr/share/themes/" + fi - # Tech user - echo "groupadd -r autologin" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo "useradd -m -s /bin/zsh -G autologin,power,storage,wheel -U $username" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo "echo '$username:$TECH_PASSWORD' | chpasswd" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + # Services + sed -i -r 's/^(.*pacman-init.*)$/#NOPE#\1/' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + sed -i -r 's/^(.*choose-mirror.*)$/#NOPE#\1/' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - # Tech user autologin - mkdir -p "$LIVE_DIR/airootfs/etc/systemd/system/getty@tty1.service.d" - echo "[Service]" > "$LIVE_DIR/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf" - echo "ExecStart=" >> "$LIVE_DIR/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf" - echo "ExecStart=-/sbin/agetty --autologin $username --noclear %I 38400 linux" >> "$LIVE_DIR/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf" + # Shutdown stall fix + echo "sed -i -r 's/^.*(DefaultTimeoutStartSec)=.*$/\1=15s/' /etc/systemd/system.conf" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo "sed -i -r 's/^.*(DefaultTimeoutStopSec)=.*$/\1=15s/' /etc/systemd/system.conf" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - # Timezone - echo "ln -sf '/usr/share/zoneinfo/$LINUX_TIME_ZONE' '/etc/localtime'" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo 'sed -i "s/#FallbackNTP/NTP/" /etc/systemd/timesyncd.conf' >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + # SSH + mkdir -p "$SKEL_DIR/.ssh" + ssh-keygen -b 4096 -C "$username@$hostname" -N "" -f "$SKEL_DIR/.ssh/id_rsa" + echo 'rm /root/.ssh/id*' >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo 'rm /root/.zlogin' >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + sed -i -r '/.*PermitRootLogin.*/d' "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo "sed -i -r '/.*PermitRootLogin.*/d' /etc/ssh/sshd_config" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + cp "$ROOT_DIR/setup/linux/authorized_keys" "$SKEL_DIR/.ssh/authorized_keys" - # udevil fix - echo "mkdir /media" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + # Root user + echo "echo 'root:$ROOT_PASSWORD' | chpasswd" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - if [[ "${1:-}" != "--minimal" ]]; then - # VNC password - echo "mkdir '/home/$username/.vnc'" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - echo "echo '$TECH_PASSWORD' | vncpasswd -f > '/home/$username/.vnc/passwd'" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + # Sudo + echo "echo '%wheel ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - # Wallpaper - mkdir -p "$LIVE_DIR/airootfs/usr/share/wallpaper" - cp "$ROOT_DIR/images/Linux.png" "$LIVE_DIR/airootfs/usr/share/wallpaper/burned.in" - fi + # Tech user + echo "groupadd -r autologin" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo "useradd -m -s /bin/zsh -G autologin,power,storage,wheel -U $username" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo "echo '$username:$TECH_PASSWORD' | chpasswd" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" - # WiFi - cp "$ROOT_DIR/setup/linux/known_networks" "$LIVE_DIR/airootfs/root/known_networks" - echo "add-known-networks --user=$username" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + # Tech user autologin + mkdir -p "$LIVE_DIR/airootfs/etc/systemd/system/getty@tty1.service.d" + echo "[Service]" > "$LIVE_DIR/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf" + echo "ExecStart=" >> "$LIVE_DIR/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf" + echo "ExecStart=-/sbin/agetty --autologin $username --noclear %I 38400 linux" >> "$LIVE_DIR/airootfs/etc/systemd/system/getty@tty1.service.d/autologin.conf" + + # Timezone + echo "ln -sf '/usr/share/zoneinfo/$LINUX_TIME_ZONE' '/etc/localtime'" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo 'sed -i "s/#FallbackNTP/NTP/" /etc/systemd/timesyncd.conf' >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + + # udevil fix + echo "mkdir /media" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + + if [[ "${1:-}" != "--minimal" ]]; then + # VNC password + echo "mkdir '/home/$username/.vnc'" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + echo "echo '$TECH_PASSWORD' | vncpasswd -f > '/home/$username/.vnc/passwd'" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" + + # Wallpaper + mkdir -p "$LIVE_DIR/airootfs/usr/share/wallpaper" + cp "$ROOT_DIR/images/Linux.png" "$LIVE_DIR/airootfs/usr/share/wallpaper/burned.in" + fi + + # WiFi + cp "$ROOT_DIR/setup/linux/known_networks" "$LIVE_DIR/airootfs/root/known_networks" + echo "add-known-networks --user=$username" >> "$LIVE_DIR/airootfs/root/customize_airootfs.sh" } function update_repo() { - if [[ "$EUID" -eq 0 ]]; then - echo "This section not meant to be run as root." - echo "Aborted." - exit 1 - fi - echo "Updating custom repo..." + if [[ "$EUID" -eq 0 ]]; then + echo "This section not meant to be run as root." + echo "Aborted." + exit 1 + fi + echo "Updating custom repo..." - # Archive current files - if [[ -d "$REPO_DIR" ]]; then - mkdir -p "$BUILD_DIR/Archive" 2>/dev/null - archive="$BUILD_DIR/Archive/$(date "+%F_%H%M%S")" - mv -bv "$REPO_DIR" "$archive" - fi - sleep 1s + # Archive current files + if [[ -d "$REPO_DIR" ]]; then + mkdir -p "$BUILD_DIR/Archive" 2>/dev/null + archive="$BUILD_DIR/Archive/$(date "+%F_%H%M%S")" + mv -bv "$REPO_DIR" "$archive" + fi + sleep 1s - # Build custom repo packages - mkdir -p "$REPO_DIR" 2>/dev/null - mkdir -p "$TEMP_DIR" 2>/dev/null - pushd "$TEMP_DIR" >/dev/null - while read -r p; do - echo "Building: $p" - curl -LsfO https://aur.archlinux.org/cgit/aur.git/snapshot/$p.tar.gz - tar xf $p.tar.gz - pushd $p >/dev/null - makepkg -d - popd >/dev/null - mv -n $p/*xz "$REPO_DIR"/ - done < "$ROOT_DIR/setup/linux/packages/aur" + # Build custom repo packages + mkdir -p "$REPO_DIR" 2>/dev/null + mkdir -p "$TEMP_DIR" 2>/dev/null + pushd "$TEMP_DIR" >/dev/null + while read -r p; do + echo "Building: $p" + curl -LsfO https://aur.archlinux.org/cgit/aur.git/snapshot/$p.tar.gz + tar xf $p.tar.gz + pushd $p >/dev/null + makepkg -d popd >/dev/null + mv -n $p/*xz "$REPO_DIR"/ + done < "$ROOT_DIR/setup/linux/packages/aur" + popd >/dev/null - # Build custom repo database - pushd "$REPO_DIR" >/dev/null - repo-add custom.db.tar.gz *xz - popd >/dev/null + # Build custom repo database + pushd "$REPO_DIR" >/dev/null + repo-add custom.db.tar.gz *xz + popd >/dev/null } function install_deps() { - echo "Installing dependencies..." - packages= - while read -r line; do - packages="$packages $line" - done < "$ROOT_DIR/setup/linux/packages/dependencies" - run_elevated pacman -Syu --needed --noconfirm $packages + echo "Installing dependencies..." + packages= + while read -r line; do + packages="$packages $line" + done < "$ROOT_DIR/setup/linux/packages/dependencies" + run_elevated pacman -Syu --needed --noconfirm $packages +} + +function build_all() { + if [[ "$EUID" -ne 0 ]]; then + echo "This section is meant to be run as root." + echo "Aborted." + exit 1 + fi + + # Prep for build + cleanup + fix_kit_permissions + install_deps + load_settings --edit + update_repo + + # Build (full) + copy_live_env + update_live_env + # Rerun script as root to start Archiso build process + run_elevated "$(realpath "$0")" --build-iso + # Cleanup + mv -nv "$LIVE_DIR" "${LIVE_DIR}.full" + perl-rename -v "s/(${KIT_NAME_SHORT}-Linux)-(${DATE}.*)/\1-Full-\2/" "$OUT_DIR"/* + + # Build (minimal) + copy_live_env --minimal + update_live_env --minimal + # Rerun script as root to start Archiso build process + run_elevated "$(realpath "$0")" --build-iso + # Cleanup + mv -nv "$LIVE_DIR" "${LIVE_DIR}.minimal" + perl-rename -v "s/(${KIT_NAME_SHORT}-Linux)-(${DATE}.*)/\1-Minimal-\2/" "$OUT_DIR"/* } function build_iso() { - if [[ "$EUID" -ne 0 ]]; then - echo "This section is meant to be run as root." - echo "Aborted." - exit 1 - fi - - # Set permissions - echo "Setting permissions..." - chown root:root "$LIVE_DIR" -R - chmod 700 "$LIVE_DIR/airootfs/etc/skel/.ssh" - chmod 600 "$LIVE_DIR/airootfs/etc/skel/.ssh/id_rsa" + if [[ "$EUID" -ne 0 ]]; then + echo "This section is meant to be run as root." + echo "Aborted." + exit 1 + fi - # Removing cached (and possibly outdated) custom repo packages - for package in $(cat "$ROOT_DIR/setup/linux/packages/aur"); do - for p in /var/cache/pacman/pkg/*${package}*; do - if [[ -f "${p}" ]]; then - rm "${p}" - fi - done + # Set permissions + echo "Setting permissions..." + chown root:root "$LIVE_DIR" -R + chmod 700 "$LIVE_DIR/airootfs/etc/skel/.ssh" + chmod 600 "$LIVE_DIR/airootfs/etc/skel/.ssh/id_rsa" + + # Removing cached (and possibly outdated) custom repo packages + for package in $(cat "$ROOT_DIR/setup/linux/packages/aur"); do + for p in /var/cache/pacman/pkg/*${package}*; do + if [[ -f "${p}" ]]; then + rm "${p}" + fi done - - # Build ISO - prefix="${KIT_NAME_SHORT}-Linux" - label="${KIT_NAME_SHORT}_LINUX" - "$LIVE_DIR/build.sh" -N "$prefix" -V "$DATE" -L "$label" -w "$TEMP_DIR/Linux" -o "$OUT_DIR" -v | tee -a "$LOG_DIR/$DATETIME.log" + done - # Cleanup - echo "Removing temp files..." - rm "$TEMP_DIR/Linux" -Rf | tee -a "$LOG_DIR/$DATETIME.log" + # Build ISO + prefix="${KIT_NAME_SHORT}-Linux" + label="${KIT_NAME_SHORT}_LINUX" + "$LIVE_DIR/build.sh" -N "$prefix" -V "$DATE" -L "$label" -w "$TEMP_DIR/Linux" -o "$OUT_DIR" -v | tee -a "$LOG_DIR/$DATETIME.log" - echo "Reverting permissions..." - chown $REAL_USER:$REAL_USER "$LIVE_DIR" -R - chown $REAL_USER:$REAL_USER "$OUT_DIR" -R + # Cleanup + echo "Removing temp files..." + rm "$TEMP_DIR/Linux" -Rf | tee -a "$LOG_DIR/$DATETIME.log" + + echo "Reverting permissions..." + chown $REAL_USER:$REAL_USER "$LIVE_DIR" -R + chown $REAL_USER:$REAL_USER "$OUT_DIR" -R } function build_full() { - if [[ "$EUID" -eq 0 ]]; then - echo "This section not meant to be run as root." - echo "Aborted." - exit 1 - fi - - # Prep for build - cleanup - fix_kit_permissions - install_deps - load_settings --edit - update_repo - copy_live_env - update_live_env - # Rerun script as root to start Archiso build process - run_elevated "$(realpath "$0")" --build-iso + if [[ "$EUID" -eq 0 ]]; then + echo "This section not meant to be run as root." + echo "Aborted." + exit 1 + fi + + # Prep for build + cleanup + fix_kit_permissions + install_deps + load_settings --edit + update_repo + copy_live_env + update_live_env + # Rerun script as root to start Archiso build process + run_elevated "$(realpath "$0")" --build-iso + # Cleanup + perl-rename -v "s/(${KIT_NAME_SHORT}-Linux)-(${DATE}.*)/\1-Full-\2/" "$OUT_DIR"/* +} + +function build_minimal() { + if [[ "$EUID" -eq 0 ]]; then + echo "This section not meant to be run as root." + echo "Aborted." + exit 1 + fi + + # Prep for build + cleanup + fix_kit_permissions + install_deps + load_settings --edit + update_repo + copy_live_env --minimal + update_live_env --minimal + # Rerun script as root to start Archiso build process + run_elevated "$(realpath "$0")" --build-iso + # Cleanup + perl-rename -v "s/(${KIT_NAME_SHORT}-Linux)-(${DATE}.*)/\1-Minimal-\2/" "$OUT_DIR"/* } # Check input case ${1:-} in - -b|--build-full) - build_full - echo Done - ;; + -a|--build-all) + build_all + echo Done + ;; - -f|--fix-perms) - fix_kit_permissions - echo Done - ;; + -b|--build-full) + build_full + echo Done + ;; - -i|--install-deps) - install_deps - echo Done - ;; + -f|--fix-perms) + fix_kit_permissions + echo Done + ;; - -m|--prep-minimal-env) - load_settings --edit - copy_live_env --minimal - update_live_env --minimal - echo Done - ;; + -i|--install-deps) + install_deps + echo Done + ;; - -o|--build-iso) - load_settings - build_iso - echo Done - ;; - - -p|--prep-live-env) - load_settings --edit - copy_live_env - update_live_env - echo Done - ;; + -m|--prep-minimal-env) + load_settings --edit + copy_live_env --minimal + update_live_env --minimal + echo Done + ;; - -u|--update-repo) - update_repo - echo Done - ;; + -o|--build-iso) + load_settings + build_iso + echo Done + ;; - *) - echo "Usage: $(basename "$0") [OPTIONS]" - echo "" - echo "Options:" - echo " -b --build-full Perform all tasks and build iso" - echo " -h --help Show usage" - echo "" - echo "Advanced options:" - echo " -f --fix-perms Fix folder permissions" - echo " -i --install-deps Install build dependencies" - echo " -m --prep-minimal-env Prep live & airootfs folders (minimal packages)" - echo " -o --build-iso Build ISO (using current setup)" - echo " -p --prep-live-env Prep live & airootfs folders" - echo " -u --update-repo Update custom pacman repo" - ;; + -p|--prep-live-env) + load_settings --edit + copy_live_env + update_live_env + echo Done + ;; + + -u|--update-repo) + update_repo + echo Done + ;; + + *) + echo "Usage: $(basename "$0") [OPTIONS]" + echo "" + echo "Options:" + echo " -a --build-all Perform all tasks to build all isos" + echo " -b --build-full Perform all tasks to build the full iso" + echo " -m --build-minimal Perform all tasks to build the minimal iso" + echo " -h --help Show usage" + echo "" + echo "Advanced options:" + echo " -f --fix-perms Fix folder permissions" + echo " -i --install-deps Install build dependencies" + echo " -n --prep-minimal-env Prep live & airootfs folders (minimal packages)" + echo " -o --build-iso Build ISO (using current setup)" + echo " -p --prep-live-env Prep live & airootfs folders" + echo " -u --update-repo Update custom pacman repo" + ;; esac diff --git a/setup/build_pe.cmd b/setup/build_pe.cmd index 92e28e45..60de9829 100644 --- a/setup/build_pe.cmd +++ b/setup/build_pe.cmd @@ -36,9 +36,9 @@ rem Edited by: https://stackoverflow.com/users/330315/a-horse-with-no-name rem Answer by: https://stackoverflow.com/users/3198799/and31415 fsutil dirty query %systemdrive% >nul if %errorlevel% neq 0 ( - call :RequestElevation - rem reset errorlevel to 1 to abort the current non-elevated script - color 00 + call :RequestElevation + rem reset errorlevel to 1 to abort the current non-elevated script + color 00 ) @exit /b %errorlevel% @@ -46,7 +46,7 @@ if %errorlevel% neq 0 ( rem Loops through all arguments to check for accepted flags set DEBUG= for %%f in (%*) do ( - if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG") + if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG") ) @exit /b 0 @@ -59,12 +59,12 @@ rem Check registry for WADK set "r_path=HKLM\Software\Wow6432Node\Microsoft\Windows Kits\Installed Roots" reg query "%r_path%" /v %r_vname% >nul 2>&1 && set "found=True" if not defined found ( - rem 32-bit systems? - set "r_path=HKLM\Software\Microsoft\Windows Kits\Installed Roots" - reg query "!r_path!" /v %r_vname% >nul 2>&1 && set "found=True" + rem 32-bit systems? + set "r_path=HKLM\Software\Microsoft\Windows Kits\Installed Roots" + reg query "!r_path!" /v %r_vname% >nul 2>&1 && set "found=True" ) for /f "skip=2 tokens=2*" %%i in ('reg query "%r_path%" /v %r_vname%') do ( - set adk_root=%%j\Assessment and Deployment Kit + set adk_root=%%j\Assessment and Deployment Kit ) rem Set errorlevel if necessary if not defined adk_root color 00 diff --git a/setup/build_windows.cmd b/setup/build_windows.cmd index 58272a45..292ad6c3 100644 --- a/setup/build_windows.cmd +++ b/setup/build_windows.cmd @@ -35,7 +35,7 @@ goto Exit rem Loops through all arguments to check for accepted flags set DEBUG= for %%f in (%*) do ( - if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG") + if /i "%%f" == "/DEBUG" (@echo on & set "DEBUG=/DEBUG") ) @exit /b 0