Skip to content

Commit bcaf7d6

Browse files
committed
(maint) Update MacOS for puppetcore work
This updates the download of puppet-agent when puppetcore packages are used. The new 'puppetcore7' and 'puppetcore8' collections when used for MacOS will now download puppetcore packages. Due to a bug in Puppet for now we're going to depend on Curl to download the package.
1 parent fd5342f commit bcaf7d6

File tree

3 files changed

+101
-14
lines changed

3 files changed

+101
-14
lines changed

manifests/osfamily/darwin.pp

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$productversion_array = split($facts['os']['macosx']['version']['major'], '[.]')
99
$productversion_major = $productversion_array[0]
1010
}
11-
11+
$destination_name = undef
1212
if $puppet_agent::absolute_source {
1313
$source = $puppet_agent::absolute_source
1414
} elsif ($puppet_agent::is_pe and (!$puppet_agent::use_alternate_sources)) {
@@ -20,12 +20,20 @@
2020
} else {
2121
$source = "puppet:///pe_packages/${pe_server_version}/${facts['platform_tag']}/${puppet_agent::package_name}-${puppet_agent::prepare::package_version}-1.osx${$productversion_major}.dmg"
2222
}
23+
} elsif $puppet_agent::collection and $puppet_agent::collection =~ /core/ {
24+
if $puppet_agent::prepare::package_version =~ /^\d+\.\d+\.\d+\.\d+\.g([a-f0-9]+)+$/ {
25+
$source = "https://artifacts-puppetcore.puppet.com/v1/download?type=native&version=${puppet_agent::prepare::package_version}&os_name=osx&os_version=${productversion_major}&os_arch=${puppet_agent::arch}&dev=true"
26+
} else {
27+
$source = "https://artifacts-puppetcore.puppet.com/v1/download?type=native&version=${puppet_agent::prepare::package_version}&os_name=osx&os_version=${productversion_major}&os_arch=${puppet_agent::arch}"
28+
}
29+
$destination_name = "${puppet_agent::package_name}-${puppet_agent::prepare::package_version}-1.osx${productversion_major}.dmg"
2330
} else {
2431
$source = "${puppet_agent::mac_source}/mac/${puppet_agent::collection}/${productversion_major}/${puppet_agent::arch}/${puppet_agent::package_name}-${puppet_agent::prepare::package_version}-1.osx${$productversion_major}.dmg"
2532
}
2633

2734
class { 'puppet_agent::prepare::package':
28-
source => $source,
35+
source => $source,
36+
destination_name => $destination_name,
2937
}
3038

3139
contain puppet_agent::prepare::package

manifests/prepare/package.pp

+39
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,45 @@
5656
creates => $local_package_file_path,
5757
require => File[$puppet_agent::params::local_packages_dir],
5858
}
59+
} elsif $puppet_agent::collection and $puppet_agent::collection =~ /core/ and $facts['os']['family'] =~ /Darwin/ {
60+
$download_username = getvar('puppet_agent::username', 'forge-key')
61+
$download_password = unwrap(getvar('puppet_agent::password'))
62+
63+
$response_file = "${local_package_file_path}.response"
64+
$netrc_file = "${facts['env_temp_variable']}/.netrc"
65+
file { $netrc_file:
66+
ensure => file,
67+
content => "machine artifacts-puppetcore.puppet.com\nlogin ${download_username}\npassword ${download_password}\n",
68+
mode => '0600',
69+
show_diff => false,
70+
}
71+
72+
$curl_command = "curl -1 -sL --netrc-file '${netrc_file}' -w '%{http_code}' -o '${local_package_file_path}' '${source}' > '${response_file}'"
73+
exec { 'Download Puppet Agent for Darwin':
74+
command => $curl_command,
75+
creates => $local_package_file_path,
76+
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'],
77+
}
78+
79+
exec { 'Remove .netrc file':
80+
command => "rm -f '${netrc_file}'",
81+
path => ['/usr/bin', '/bin'],
82+
onlyif => "test -f '${netrc_file}'",
83+
require => Exec['Download Puppet Agent for Darwin'],
84+
}
85+
#
86+
# TODO: This is a temporary workaround to get the HTTP response code from the curl command.
87+
# For now just outputting the response is good enough.
88+
# We need to find a way to interspect this value and fail the catalog if the response
89+
# code is not 200, and then logging the output wont be as important.
90+
#
91+
exec { 'Read HTTP Response Code':
92+
command => "cat '${response_file}'",
93+
path => ['/usr/bin', '/bin'],
94+
onlyif => "test -f '${response_file}'",
95+
logoutput => true,
96+
require => Exec['Download Puppet Agent for Darwin'],
97+
}
5998
} else {
6099
file { $local_package_file_path:
61100
ensure => file,

tasks/install_shell.sh

+52-12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ warn () {
2626
log "WARN: ${1}"
2727
}
2828

29+
url_parameters() {
30+
if [[ "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.g([a-f0-9]+)$ ]]; then
31+
echo "&dev=true"
32+
else
33+
echo ""
34+
fi
35+
}
36+
2937
critical () {
3038
log "CRIT: ${1}"
3139
}
@@ -162,10 +170,18 @@ fi
162170
if [ -n "$PT_mac_source" ]; then
163171
mac_source=$PT_mac_source
164172
else
165-
if [ "$nightly" = true ]; then
166-
mac_source='http://nightlies.puppet.com/downloads'
167-
else
168-
mac_source='http://downloads.puppet.com'
173+
if [[ "$PT_collection" =~ core ]]; then
174+
if [ -z "$password" ]; then
175+
echo "A password parameter is required to install with puppetcore"
176+
exit 1
177+
fi
178+
mac_source='https://artifacts-puppetcore.puppet.com/v1/download'
179+
else
180+
if [ "$nightly" = true ]; then
181+
mac_source='http://nightlies.puppet.com/downloads'
182+
else
183+
mac_source='http://downloads.puppet.com'
184+
fi
169185
fi
170186
fi
171187

@@ -421,7 +437,11 @@ do_wget() {
421437
# do_curl URL FILENAME
422438
do_curl() {
423439
info "Trying curl..."
424-
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
440+
if [[ -n "$3" && -n "$4" ]]; then
441+
run_cmd "curl -1 -sL -u '$3:$4' -D $tmp_stderr '$1' > '$2'"
442+
else
443+
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
444+
fi
425445
rc=$?
426446

427447
# check for 404
@@ -431,6 +451,12 @@ do_curl() {
431451
unable_to_retrieve_package
432452
fi
433453

454+
grep "HTTP/2 401" $tmp_stderr 2>&1 >/dev/null
455+
if test $? -eq 0; then
456+
critical "ERROR 401: Unauthorized access"
457+
unable_to_retrieve_package
458+
fi
459+
434460
# check for bad return status or empty output
435461
if test $rc -ne 0 || test ! -s "$2"; then
436462
capture_tmp_stderr "curl"
@@ -557,7 +583,11 @@ do_download() {
557583
fi
558584

559585
if exists curl; then
560-
do_curl $1 $2 && return 0
586+
if [[ "$collection" =~ core ]]; then
587+
do_curl $1 $2 "$username" "$password" && return 0
588+
else
589+
do_curl $1 $2 && return 0
590+
fi
561591
fi
562592

563593
if exists fetch; then
@@ -810,19 +840,29 @@ case $platform in
810840
download_url="${apt_source}/${filename}"
811841
;;
812842
"mac_os_x")
813-
info "Mac platform! Lets get you a DMG..."
814-
filetype="dmg"
843+
arch="x86_64"
844+
if [[ $(uname -p) == "arm" ]]; then
845+
arch="arm64"
846+
fi
815847
if test "$version" = "latest"; then
816848
filename="puppet-agent-latest.dmg"
817849
else
818850
filename="puppet-agent-${version}-1.osx${platform_version}.dmg"
819851
fi
852+
info "Mac platform! Lets get you a DMG...!!"
853+
if [[ "$collection" =~ core ]]; then
854+
if [ -z "$password" ]; then
855+
echo "A password parameter is required to install"
856+
exit 1
857+
fi
820858

821-
arch="x86_64"
822-
if [[ $(uname -p) == "arm" ]]; then
823-
arch="arm64"
859+
# Call the url_parameters function to append to the download_url
860+
download_url="${mac_source}/?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&fips=false$(url_parameters)"
861+
else
862+
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
824863
fi
825-
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
864+
filetype="dmg"
865+
826866
;;
827867
*)
828868
critical "Sorry $platform is not supported yet!"

0 commit comments

Comments
 (0)