7
7
[String ]$install_options = ' REINSTALLMODE="amus"' ,
8
8
[Bool ]$stop_service = $False ,
9
9
[Int ]$retry = 5 ,
10
- [Bool ]$_noop = $False
10
+ [Bool ]$_noop = $False ,
11
+ [String ]$username = ' forge-key' ,
12
+ [String ]$password
11
13
)
12
14
# If an error is encountered, the script will stop instead of the default of "Continue"
13
15
$ErrorActionPreference = " Stop"
14
16
17
+ try {
18
+ $os_version = (Get-WmiObject Win32_OperatingSystem).Version
19
+ }
20
+ catch [System.Management.Automation.CommandNotFoundException ] {
21
+ $os_version = (Get-CimInstance - ClassName win32_OperatingSystem).Version
22
+ }
23
+ $major_os_version = ($os_version -split ' \.' )[0 ]
24
+
15
25
try {
16
26
if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -match ' ^32' ) {
17
27
$arch = " x86"
@@ -27,9 +37,19 @@ catch [System.Management.Automation.CommandNotFoundException] {
27
37
}
28
38
}
29
39
40
+ $fips = ' false'
41
+ try {
42
+ if ((Get-ItemPropertyValue - Path ' HKLM:\System\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy' - Name Enabled) -ne 0 ) {
43
+ $fips = ' true'
44
+ }
45
+ }
46
+ catch {
47
+ Write-Output " Failed to lookup FIPS mode, assuming it is disabled"
48
+ }
49
+
30
50
function Test-PuppetInstalled {
31
51
$rootPath = ' HKLM:\SOFTWARE\Puppet Labs\Puppet'
32
- try {
52
+ try {
33
53
if (Get-ItemProperty - Path $rootPath ) { RETURN $true }
34
54
}
35
55
catch {
@@ -98,12 +118,16 @@ if (Test-RunningServices) {
98
118
# Change windows_source only if the collection is a nightly build, and the source was not explicitly specified.
99
119
if (($collection -like ' *nightly*' ) -And -Not ($PSBoundParameters.ContainsKey (' windows_source' ))) {
100
120
$windows_source = ' https://nightlies.puppet.com/downloads'
121
+ } elseif (($collection -like ' *puppetcore*' ) -And -Not ($PSBoundParameters.ContainsKey (' windows_source' ))) {
122
+ $windows_source = ' https://artifacts-puppetcore.puppet.com/v1/download'
101
123
}
102
124
103
125
if ($absolute_source ) {
104
126
$msi_source = " $absolute_source "
105
127
}
106
- else {
128
+ elseif ($collection -like ' *puppetcore*' ) {
129
+ $msi_source = " ${windows_source} ?version=${version} &os_name=windows&os_version=${major_os_version} &os_arch=${arch} &fips=${fips} "
130
+ } else {
107
131
$msi_source = " $windows_source /windows/${collection} /${msi_name} "
108
132
}
109
133
@@ -125,22 +149,27 @@ function Set-Tls12 {
125
149
}
126
150
127
151
function DownloadPuppet {
128
- Write-Output " Downloading the Puppet Agent installer on $env: COMPUTERNAME ... "
152
+ Write-Output " Downloading the Puppet Agent installer on $env: COMPUTERNAME from ${msi_source} "
129
153
Set-Tls12
130
154
131
155
$webclient = New-Object system.net.webclient
132
-
156
+ if ($password ) {
157
+ $credentials = [Convert ]::ToBase64String([System.Text.Encoding ]::ASCII.GetBytes(" ${username} :${password} " ))
158
+ $webclient.Headers.Add (" Authorization" , " Basic ${credentials} " )
159
+ }
133
160
try {
134
161
$webclient.DownloadFile ($msi_source , $msi_dest )
135
162
}
136
163
catch [System.Net.WebException ] {
164
+ Write-Host " Download exception: $ ( $_.Exception.Message ) "
137
165
For ($attempt_number = 1 ; $attempt_number -le $retry ; $attempt_number ++ ) {
138
166
try {
139
167
Write-Output " Retrying... [$attempt_number /$retry ]"
140
168
$webclient.DownloadFile ($msi_source , $msi_dest )
141
169
break
142
170
}
143
171
catch [System.Net.WebException ] {
172
+ Write-Host " Download exception: $ ( $_.Exception.Message ) "
144
173
if ($attempt_number -eq $retry ) {
145
174
# If we can't find the msi, then we may not be configured correctly
146
175
if ($_.Exception.Response.StatusCode -eq [system.net.httpstatuscode ]::NotFound) {
0 commit comments