77 [String ]$install_options = ' REINSTALLMODE="amus"' ,
88 [Bool ]$stop_service = $False ,
99 [Int ]$retry = 5 ,
10- [Bool ]$_noop = $False
10+ [Bool ]$_noop = $False ,
11+ [String ]$username = ' forge-key' ,
12+ [String ]$password
1113)
1214# If an error is encountered, the script will stop instead of the default of "Continue"
1315$ErrorActionPreference = " Stop"
1416
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+
1525try {
1626 if ((Get-WmiObject Win32_OperatingSystem).OSArchitecture -match ' ^32' ) {
1727 $arch = " x86"
@@ -27,9 +37,19 @@ catch [System.Management.Automation.CommandNotFoundException] {
2737 }
2838}
2939
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+
3050function Test-PuppetInstalled {
3151 $rootPath = ' HKLM:\SOFTWARE\Puppet Labs\Puppet'
32- try {
52+ try {
3353 if (Get-ItemProperty - Path $rootPath ) { RETURN $true }
3454 }
3555 catch {
@@ -98,12 +118,16 @@ if (Test-RunningServices) {
98118# Change windows_source only if the collection is a nightly build, and the source was not explicitly specified.
99119if (($collection -like ' *nightly*' ) -And -Not ($PSBoundParameters.ContainsKey (' windows_source' ))) {
100120 $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'
101123}
102124
103125if ($absolute_source ) {
104126 $msi_source = " $absolute_source "
105127}
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 {
107131 $msi_source = " $windows_source /windows/${collection} /${msi_name} "
108132}
109133
@@ -125,22 +149,27 @@ function Set-Tls12 {
125149}
126150
127151function 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} "
129153 Set-Tls12
130154
131155 $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+ }
133160 try {
134161 $webclient.DownloadFile ($msi_source , $msi_dest )
135162 }
136163 catch [System.Net.WebException ] {
164+ Write-Host " Download exception: $ ( $_.Exception.Message ) "
137165 For ($attempt_number = 1 ; $attempt_number -le $retry ; $attempt_number ++ ) {
138166 try {
139167 Write-Output " Retrying... [$attempt_number /$retry ]"
140168 $webclient.DownloadFile ($msi_source , $msi_dest )
141169 break
142170 }
143171 catch [System.Net.WebException ] {
172+ Write-Host " Download exception: $ ( $_.Exception.Message ) "
144173 if ($attempt_number -eq $retry ) {
145174 # If we can't find the msi, then we may not be configured correctly
146175 if ($_.Exception.Response.StatusCode -eq [system.net.httpstatuscode ]::NotFound) {
0 commit comments