Skip to content

Commit 5d6c29e

Browse files
committed
Land #51, update dotnet 4.5 to restore chocolatey
2 parents bf83967 + 51ec0ce commit 5d6c29e

7 files changed

+87
-15
lines changed

answer_files/windows/Autounattend_x64.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
<Order>26</Order>
269269
</SynchronousCommand>
270270
<SynchronousCommand wcm:action="add">
271-
<CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\install_netfx.ps1 -AutoStart</CommandLine>
271+
<CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\install_net45.ps1 -AutoStart</CommandLine>
272272
<Description>Install .NET 4.0</Description>
273273
<Order>27</Order>
274274
</SynchronousCommand>

answer_files/windows/Autounattend_x86.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
<Order>26</Order>
263263
</SynchronousCommand>
264264
<SynchronousCommand wcm:action="add">
265-
<CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\install_netfx.ps1 -AutoStart</CommandLine>
265+
<CommandLine>cmd.exe /c C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File a:\install_net45.ps1 -AutoStart</CommandLine>
266266
<Description>Install .NET 4.0</Description>
267267
<Order>27</Order>
268268
</SynchronousCommand>

scripts/installs/chocolatey.cmd

-1
This file was deleted.

scripts/installs/chocolatey.ps1

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
function Invoke-CLR4PowerShellCommand {
2+
[CmdletBinding()]
3+
param (
4+
[Parameter(Mandatory=$true)]
5+
[ScriptBlock]
6+
$ScriptBlock,
7+
8+
[Parameter(ValueFromRemainingArguments=$true)]
9+
[Alias('Args')]
10+
[object[]]
11+
$ArgumentList
12+
)
13+
14+
if ($PSVersionTable.CLRVersion.Major -eq 4) {
15+
Invoke-Command -ScriptBlock $ScriptBlock -ArgumentList $ArgumentList
16+
return
17+
}
18+
19+
$RunActivationConfigPath = $Env:TEMP | Join-Path -ChildPath ([Guid]::NewGuid())
20+
New-Item -Path $RunActivationConfigPath -ItemType Container | Out-Null
21+
@"
22+
<?xml version="1.0" encoding="utf-8" ?>
23+
<configuration>
24+
<startup useLegacyV2RuntimeActivationPolicy="true">
25+
<supportedRuntime version="v4.0"/>
26+
</startup>
27+
</configuration>
28+
"@ | Set-Content -Path $RunActivationConfigPath\powershell.exe.activation_config -Encoding UTF8
29+
30+
$EnvVarName = 'COMPLUS_ApplicationMigrationRuntimeActivationConfigPath'
31+
$EnvVarOld = [Environment]::GetEnvironmentVariable($EnvVarName)
32+
[Environment]::SetEnvironmentVariable($EnvVarName, $RunActivationConfigPath)
33+
34+
try {
35+
& powershell.exe -inputformat text -command $ScriptBlock -args $ArgumentList
36+
} finally {
37+
[Environment]::SetEnvironmentVariable($EnvVarName, $EnvVarOld)
38+
$RunActivationConfigPath | Remove-Item -Recurse
39+
}
40+
41+
}
42+
43+
$ErrorActionPreference = 'Stop'
44+
Set-StrictMode -Version Latest
45+
46+
$isWin8 = wmic os get caption | find /i '" 8 "'
47+
$isWin2012 = wmic os get caption | find /i '" 2012 "'
48+
49+
# skip wrapping for 8 or 2012?
50+
if ($isWin8 -or $isWin2012){
51+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
52+
}else{
53+
Invoke-CLR4PowerShellCommand -ScriptBlock {
54+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
55+
}
56+
}
57+
58+
# cribbed from https://gist.github.com/jstangroome/882528

scripts/installs/install_net45.ps1

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$Logfile = "C:\Windows\Temp\dotnet-install.log"
2+
function LogWrite {
3+
Param ([string]$logstring)
4+
$now = Get-Date -format s
5+
Add-Content $Logfile -value "$now $logstring"
6+
Write-Host $logstring
7+
}
8+
9+
LogWrite "Downloading dotNet 4.5.1"
10+
try {
11+
(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')
12+
} catch {
13+
LogWrite $_.Exception | Format-List -force
14+
LogWrite "Failed to download file."
15+
}
16+
17+
LogWrite "Starting installation process..."
18+
try {
19+
Start-Process -FilePath "C:\Windows\Temp\dotnet.exe" -ArgumentList "/I /q /norestart" -Wait -PassThru
20+
} catch {
21+
LogWrite $_.Exception | Format-List -force
22+
LogWrite "Exception during install process."
23+
}

scripts/installs/install_netfx.ps1

-7
This file was deleted.

windows_packer.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
"ssh_wait_timeout": "2h",
1515
"shutdown_command": "shutdown /s /t 10 /f /d p:4:1 /c \"Packer Shutdown\"",
1616
"guest_os_type": "{{user `guest_os_type`}}",
17-
"tools_upload_flavor": "windows",
1817
"disk_size": 61440,
1918
"floppy_files": [
2019
"{{user `autounattend`}}",
2120
"./scripts/configs/microsoft-updates.bat",
2221
"./scripts/configs/win-updates.ps1",
2322
"./scripts/installs/openssh.ps1",
24-
"./scripts/installs/install_netfx.ps1",
23+
"./scripts/installs/install_net45.ps1",
2524
"./resources/certs/oracle-cert.cer",
2625
"./resources/certs/gdig2.crt",
2726
"./resources/certs/comodorsadomainvalidationsecureserverca.crt",
@@ -67,7 +66,7 @@
6766
"./scripts/configs/microsoft-updates.bat",
6867
"./scripts/configs/win-updates.ps1",
6968
"./scripts/installs/openssh.ps1",
70-
"./scripts/installs/install_netfx.ps1",
69+
"./scripts/installs/install_net45.ps1",
7170
"./resources/certs/oracle-cert.cer",
7271
"./resources/certs/gdig2.crt",
7372
"./resources/certs/comodorsadomainvalidationsecureserverca.crt",
@@ -134,8 +133,8 @@
134133
},
135134
{
136135
"type":"powershell",
137-
"inline": [
138-
"$env:chocolateyVersion = '0.10.8'; [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))"
136+
"scripts": [
137+
"./scripts/installs/chocolatey.ps1"
139138
]
140139
},
141140
{

0 commit comments

Comments
 (0)