Skip to content

Commit 191a2cc

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 33cd0f6 commit 191a2cc

File tree

3 files changed

+95
-15
lines changed

3 files changed

+95
-15
lines changed

manifests/osfamily/darwin.pp

+9-1
Original file line numberDiff line numberDiff line change
@@ -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-
} else {
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"
30+
} 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':
2835
source => $source,
36+
destination_name => $destination_name,
2937
}
3038

3139
contain puppet_agent::prepare::package

manifests/prepare/package.pp

+39-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
# REMIND: aix
4646
# REMIND: darwin
4747
# REMIND: suse 11 and PE
48-
if $puppet_agent::collection =~ /core/ and $facts['os']['family'] =~ /windows/ {
48+
if $puppet_agent::collection and $puppet_agent::collection =~ /core/ and $facts['os']['family'] =~ /windows/ {
4949
$download_username = getvar('puppet_agent::username', 'forge-key')
5050
$download_password = unwrap(getvar('puppet_agent::password'))
5151

@@ -65,6 +65,44 @@
6565
creates => $local_package_file_path,
6666
provider => powershell,
6767
}
68+
} elsif $puppet_agent::collection and $puppet_agent::collection =~ /core/ and $facts['os']['family'] =~ /Darwin/ {
69+
$download_username = getvar('puppet_agent::username', 'forge-key')
70+
$download_password = unwrap(getvar('puppet_agent::password'))
71+
72+
$response_file = "${local_package_file_path}.response"
73+
$netrc_file = "${facts['env_temp_variable']}/.netrc"
74+
file { $netrc_file:
75+
ensure => file,
76+
content => "machine artifacts-puppetcore.puppet.com\nlogin ${download_username}\npassword ${download_password}\n",
77+
mode => '0600',
78+
}
79+
80+
$curl_command = "curl -1 -sL --netrc-file '${netrc_file}' -w '%{http_code}' -o '${local_package_file_path}' '${source}' > '${response_file}'"
81+
exec { 'Download Puppet Agent for Darwin':
82+
command => $curl_command,
83+
creates => $local_package_file_path,
84+
path => ['/usr/bin', '/usr/sbin', '/bin', '/sbin'],
85+
}
86+
87+
exec { 'Remove .netrc file':
88+
command => "rm -f '${netrc_file}'",
89+
path => ['/usr/bin', '/bin'],
90+
onlyif => "test -f '${netrc_file}'",
91+
require => Exec['Download Puppet Agent for Darwin'],
92+
}
93+
#
94+
# TODO: This is a temporary workaround to get the HTTP response code from the curl command.
95+
# For now just outputting the response is good enough.
96+
# We need to find a way to interspect this value and fail the catalog if the response
97+
# code is not 200, and then logging the output wont be as important.
98+
#
99+
exec { 'Read HTTP Response Code':
100+
command => "cat '${response_file}'",
101+
path => ['/usr/bin', '/bin'],
102+
onlyif => "test -f '${response_file}'",
103+
logoutput => true,
104+
require => Exec['Download Puppet Agent for Darwin'],
105+
}
68106
} else {
69107
file { $local_package_file_path:
70108
ensure => file,

tasks/install_shell.sh

+47-13
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,18 @@ fi
162162
if [ -n "$PT_mac_source" ]; then
163163
mac_source=$PT_mac_source
164164
else
165-
if [ "$nightly" = true ]; then
166-
mac_source='http://nightlies.puppet.com/downloads'
167-
else
168-
mac_source='http://downloads.puppet.com'
165+
if [[ "$PT_collection" =~ core ]]; then
166+
if [ -z "$password" ]; then
167+
echo "A password parameter is required to install with puppetcore"
168+
exit 1
169+
fi
170+
mac_source='https://artifacts-puppetcore.puppet.com/v1/download'
171+
else
172+
if [ "$nightly" = true ]; then
173+
mac_source='http://nightlies.puppet.com/downloads'
174+
else
175+
mac_source='http://downloads.puppet.com'
176+
fi
169177
fi
170178
fi
171179

@@ -421,7 +429,11 @@ do_wget() {
421429
# do_curl URL FILENAME
422430
do_curl() {
423431
info "Trying curl..."
424-
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
432+
if [[ -n "$3" && -n "$4" ]]; then
433+
run_cmd "curl -1 -sL -u '$3:$4' -D $tmp_stderr '$1' > '$2'"
434+
else
435+
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
436+
fi
425437
rc=$?
426438

427439
# check for 404
@@ -431,6 +443,12 @@ do_curl() {
431443
unable_to_retrieve_package
432444
fi
433445

446+
grep "HTTP/2 401" $tmp_stderr 2>&1 >/dev/null
447+
if test $? -eq 0; then
448+
critical "ERROR 401: Unauthorized access"
449+
unable_to_retrieve_package
450+
fi
451+
434452
# check for bad return status or empty output
435453
if test $rc -ne 0 || test ! -s "$2"; then
436454
capture_tmp_stderr "curl"
@@ -557,7 +575,11 @@ do_download() {
557575
fi
558576

559577
if exists curl; then
560-
do_curl $1 $2 && return 0
578+
if [[ "$collection" =~ core ]]; then
579+
do_curl $1 $2 "$username" "$password" && return 0
580+
else
581+
do_curl $1 $2 && return 0
582+
fi
561583
fi
562584

563585
if exists fetch; then
@@ -810,19 +832,31 @@ case $platform in
810832
download_url="${apt_source}/${filename}"
811833
;;
812834
"mac_os_x")
813-
info "Mac platform! Lets get you a DMG..."
814-
filetype="dmg"
835+
arch="x86_64"
836+
if [[ $(uname -p) == "arm" ]]; then
837+
arch="arm64"
838+
fi
815839
if test "$version" = "latest"; then
816840
filename="puppet-agent-latest.dmg"
817841
else
818842
filename="puppet-agent-${version}-1.osx${platform_version}.dmg"
819843
fi
820-
821-
arch="x86_64"
822-
if [[ $(uname -p) == "arm" ]]; then
823-
arch="arm64"
844+
info "Mac platform! Lets get you a DMG...!!"
845+
if [[ "$collection" =~ core ]]; then
846+
if [ -z "$password" ]; then
847+
echo "A password parameter is required to install"
848+
exit 1
849+
fi
850+
if [[ "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.g([a-f0-9]+)$ ]]; then
851+
download_url="${mac_source}/?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&fips=false&dev=true"
852+
else
853+
download_url="${mac_source}/?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&fips=false"
854+
fi
855+
else
856+
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
824857
fi
825-
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
858+
filetype="dmg"
859+
826860
;;
827861
*)
828862
critical "Sorry $platform is not supported yet!"

0 commit comments

Comments
 (0)