Land #586, download windows pre-req using host OS

This commit is contained in:
Jeffrey Martin 2023-02-04 14:50:18 -06:00
commit 6da0bda7a9
No known key found for this signature in database
GPG Key ID: 0CD9BBC2AF15F171
13 changed files with 95 additions and 44 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@
packer_cache/
packer/builds/
resources/drivers/
resources/windows_pre_downloads/
*.vfd
*.exe
*.msi

View File

@ -261,16 +261,6 @@
<CommandLine>cmd.exe /c mkdir -p C:\vagrant\scripts</CommandLine>
<Description>Create directory for vagrant files to avoid provisioner bug with packer.</Description>
<Order>26</Order>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\install_dotnet45.ps1 -AutoStart</CommandLine>
<Order>97</Order>
<Description>Install .NET 4.5.1</Description>
</SynchronousCommand>
<SynchronousCommand wcm:action="add">
<CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\install_wmf.ps1 -AutoStart</CommandLine>
<Order>98</Order>
<Description>Installing Windows Management Framework 5.0</Description>
</SynchronousCommand>
<!--WITHOUT WINDOWS UPDATES -->
<SynchronousCommand wcm:action="add">

View File

@ -18,8 +18,6 @@
"{{user `scripts_dir`}}/configs/microsoft-updates.bat",
"{{user `scripts_dir`}}/configs/win-updates.ps1",
"{{user `scripts_dir`}}/installs/openssh.ps1",
"{{user `scripts_dir`}}/installs/install_dotnet45.ps1",
"{{user `scripts_dir`}}/installs/install_wmf.ps1",
"{{user `resources_dir`}}/certs/oracle-cert.cer",
"{{user `resources_dir`}}/certs/gdig2.crt",
"{{user `resources_dir`}}/certs/comodorsadomainvalidationsecureserverca.crt",
@ -56,8 +54,6 @@
"{{user `scripts_dir`}}/configs/microsoft-updates.bat",
"{{user `scripts_dir`}}/configs/win-updates.ps1",
"{{user `scripts_dir`}}/installs/openssh.ps1",
"{{user `scripts_dir`}}/installs/install_dotnet45.ps1",
"{{user `scripts_dir`}}/installs/install_wmf.ps1",
"{{user `resources_dir`}}/certs/oracle-cert.cer",
"{{user `resources_dir`}}/certs/gdig2.crt",
"{{user `resources_dir`}}/certs/comodorsadomainvalidationsecureserverca.crt",
@ -99,8 +95,6 @@
"{{user `scripts_dir`}}/configs/microsoft-updates.bat",
"{{user `scripts_dir`}}/configs/win-updates.ps1",
"{{user `scripts_dir`}}/installs/openssh.ps1",
"{{user `scripts_dir`}}/installs/install_dotnet45.ps1",
"{{user `scripts_dir`}}/installs/install_wmf.ps1",
"{{user `resources_dir`}}/certs/oracle-cert.cer",
"{{user `resources_dir`}}/certs/gdig2.crt",
"{{user `resources_dir`}}/certs/comodorsadomainvalidationsecureserverca.crt",
@ -150,8 +144,6 @@
"{{user `scripts_dir`}}/configs/microsoft-updates.bat",
"{{user `scripts_dir`}}/configs/win-updates.ps1",
"{{user `scripts_dir`}}/installs/openssh.ps1",
"{{user `scripts_dir`}}/installs/install_dotnet45.ps1",
"{{user `scripts_dir`}}/installs/install_wmf.ps1",
"{{user `resources_dir`}}/certs/oracle-cert.cer",
"{{user `resources_dir`}}/certs/gdig2.crt",
"{{user `resources_dir`}}/certs/comodorsadomainvalidationsecureserverca.crt",
@ -184,6 +176,16 @@
}
],
"provisioners": [
{
"type": "shell-local",
"only_on": ["linux", "darwin"],
"inline": ["cd {{user `resources_dir`}} && {{user `resources_dir`}}/download-windows-files.sh"]
},
{
"type": "shell-local",
"only_on": ["windows"],
"inline": ["cd {{user `resources_dir`}} && powershell {{user `resources_dir`}}/download-windows-files.ps1"]
},
{
"type": "file",
"source": "{{user `scripts_dir`}}",
@ -200,7 +202,6 @@
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
"scripts": [
"{{user `scripts_dir`}}/configs/update_root_certs.bat",
"{{user `scripts_dir`}}/configs/disable-auto-logon.bat",
"{{user `scripts_dir`}}/configs/enable-rdp.bat"
]
},
@ -215,6 +216,25 @@
{
"type": "windows-restart"
},
{
"type": "powershell",
"scripts": [
"{{user `scripts_dir`}}/installs/install_dotnet45.ps1"
]
},
{
"type": "windows-restart"
},
{
"type": "powershell",
"scripts": [
"{{user `scripts_dir`}}/installs/install_wmf.ps1"
]
},
{
"type": "windows-restart",
"pause_before": "180s"
},
{
"type": "powershell",
"scripts": [
@ -240,7 +260,9 @@
"remote_path": "C:/Windows/Temp/script.bat",
"execute_command": "{{.Vars}} cmd /c C:/Windows/Temp/script.bat",
"scripts": [
"{{user `scripts_dir`}}/installs/install_boxstarter.bat",
"{{user `scripts_dir`}}/configs/disable-auto-logon.bat",
"{{user `scripts_dir`}}/chocolatey_installs/chocolatey-compatibility.bat",
"{{user `scripts_dir`}}/chocolatey_installs/boxstarter.bat",
"{{user `scripts_dir`}}/chocolatey_installs/7zip.bat",
"{{user `scripts_dir`}}/configs/apply_password_settings.bat",
"{{user `scripts_dir`}}/configs/create_users.bat",
@ -267,7 +289,7 @@
"{{user `scripts_dir`}}/installs/install_wordpress.bat",
"{{user `scripts_dir`}}/installs/install_openjdk6.bat",
"{{user `scripts_dir`}}/installs/setup_jmx.bat",
"{{user `scripts_dir`}}/installs/install_ruby.bat",
"{{user `scripts_dir`}}/chocolatey_installs/ruby.bat",
"{{user `scripts_dir`}}/installs/install_devkit.bat"
]
},

View File

@ -0,0 +1,23 @@
$Logfile = "C:\Windows\Temp\wmf-install.log"
function LogWrite {
Param ([string]$logstring)
$now = Get-Date -format s
Add-Content $Logfile -value "$now $logstring"
Write-Host $logstring
}
LogWrite "Downloading dotNet 4.5.2"
try {
(New-Object System.Net.WebClient).DownloadFile('https://download.microsoft.com/download/E/2/1/E21644B5-2DF2-47C2-91BD-63C560427900/NDP452-KB2901907-x86-x64-AllOS-ENU.exe', 'windows_pre_downloads/dotnet.exe')
} catch {
LogWrite $_.Exception | Format-List -force
LogWrite "Failed to download file."
}
LogWrite "Downloading Windows Management Framework 5.1"
try {
(New-Object System.Net.WebClient).DownloadFile('https://download.microsoft.com/download/6/F/5/6F5FF66C-6775-42B0-86C4-47D41F2DA187/Win7AndW2K8R2-KB3191566-x64.zip', 'windows_pre_downloads/wmf.zip')
} catch {
LogWrite $_.Exception | Format-List -force
LogWrite "Failed to download file."
}

View File

@ -0,0 +1,3 @@
#!/bin/bash -e
curl -L --output windows_pre_downloads/dotnet.exe https://download.microsoft.com/download/E/2/1/E21644B5-2DF2-47C2-91BD-63C560427900/NDP452-KB2901907-x86-x64-AllOS-ENU.exe
curl -L --output windows_pre_downloads/wmf.zip https://download.microsoft.com/download/6/F/5/6F5FF66C-6775-42B0-86C4-47D41F2DA187/Win7AndW2K8R2-KB3191566-x64.zip

View File

View File

@ -0,0 +1,4 @@
chocolatey feature enable -n=allowGlobalConfirmation
choco install chocolatey-compatibility.extension
chocolatey feature disable -n=allowGlobalConfirmation
exit

View File

@ -1 +0,0 @@
@powershell -NoProfile -ExecutionPolicy Bypass -File "%systemdrive%\vagrant\scripts\installs\install_chocolatey.ps1"

View File

@ -40,12 +40,17 @@ function Invoke-CLR4PowerShellCommand {
}
if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$isWin8 = wmic os get caption | find /i '" 8 "'
$isWin2012 = wmic os get caption | find /i '" 2012 "'
$env:chocolateyVersion = '0.10.13'
# skip wrapping for 8 or 2012?
if ($isWin8 -or $isWin2012){
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))

View File

@ -6,17 +6,9 @@ function LogWrite {
Write-Host $logstring
}
LogWrite "Downloading dotNet 4.5.1"
try {
(New-Object System.Net.WebClient).DownloadFile('http://download.microsoft.com/download/1/6/7/167F0D79-9317-48AE-AEDB-17120579F8E2/NDP451-KB2858728-x86-x64-AllOS-ENU.exe', 'C:\Windows\Temp\dotnet.exe')
} catch {
LogWrite $_.Exception | Format-List -force
LogWrite "Failed to download file."
}
LogWrite "Starting installation process..."
try {
Start-Process -FilePath "C:\Windows\Temp\dotnet.exe" -ArgumentList "/I /q /norestart" -Wait -PassThru
Start-Process -FilePath "C:\vagrant\resources\windows_pre_downloads\dotnet.exe" -ArgumentList "/I /q /norestart" -Wait -PassThru
} catch {
LogWrite $_.Exception | Format-List -force
LogWrite "Exception during install process."

View File

@ -5,19 +5,31 @@ function LogWrite {
Add-Content $Logfile -value "$now $logstring"
Write-Host $logstring
}
LogWrite "Downloading Windows Management Framework 5.0"
try {
(New-Object System.Net.WebClient).DownloadFile('https://download.microsoft.com/download/2/C/6/2C6E1B4A-EBE5-48A6-B225-2D2058A9CEFB/Win7AndW2K8R2-KB3134760-x64.msu', 'C:\Windows\Temp\wmf.msu')
} catch {
LogWrite $_.Exception | Format-List -force
LogWrite "Failed to download file."
LogWrite "Extracting Archive..."
$extractLocation = "C:\vagrant\resources\windows_pre_downloads\wmf_install"
New-Item -Path $extractLocation -ItemType Directory
$shell = New-Object -ComObject shell.application
$zip = $shell.NameSpace("C:\vagrant\resources\windows_pre_downloads\wmf.zip")
foreach ($item in $zip.items()) {
$shell.Namespace($extractLocation).CopyHere($item)
}
Set-Location -Path $extractLocation -PassThru
$installCmd = "powershell.exe -ExecutionPolicy Bypass -Command " + '"' + ${extractLocation} + "\Install-WMF5.1.ps1 -AcceptEula" + '"'
LogWrite "Starting installation process..."
try {
Start-Process -FilePath "wusa.exe" -ArgumentList "C:\Windows\Temp\wmf.msu /quiet /norestart" -Wait -PassThru
} catch {
LogWrite $_.Exception | Format-List -force
LogWrite "Exception during install process."
}
New-Item C:\vagrant\resources\windows_pre_downloads\wmf_install\install_wmf.bat -ItemType "file"
Set-Content C:\vagrant\resources\windows_pre_downloads\wmf_install\install_wmf.bat $installCmd
$Taskname = "updatepsh"
SCHTASKS /CREATE /sc ONCE /st 00:00 /TN $Taskname /RU SYSTEM /RL HIGHEST /TR "C:\vagrant\resources\windows_pre_downloads\wmf_install\install_wmf.bat"
schtasks /Run /TN $Taskname
start-sleep -s 5
schtasks /delete /tn $Taskname /f
start-sleep -s 30