Skip to content

Commit 5db87f4

Browse files
authored
Merge pull request #784 from joshcooper/macos_puppetcore
Add puppetcore support for macOS
2 parents f164f39 + bd2787a commit 5db87f4

File tree

4 files changed

+119
-42
lines changed

4 files changed

+119
-42
lines changed

manifests/osfamily/darwin.pp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,21 @@
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 =~ /core/ {
24+
$source = 'https://artifacts-puppetcore.puppet.com/v1/download'
2325
} else {
2426
$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"
2527
}
2628

29+
$destination_name = if $puppet_agent::collection =~ /core/ {
30+
"${puppet_agent::package_name}-${puppet_agent::prepare::package_version}-1.osx${$productversion_major}.dmg"
31+
} else {
32+
undef
33+
}
34+
2735
class { 'puppet_agent::prepare::package':
28-
source => $source,
36+
source => $source,
37+
destination_name => $destination_name,
2938
}
3039

3140
contain puppet_agent::prepare::package

manifests/prepare/package.pp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@
5656
creates => $local_package_file_path,
5757
require => File[$puppet_agent::params::local_packages_dir],
5858
}
59+
} elsif $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+
$osname = 'osx'
63+
$osversion = $facts['os']['macosx']['version']['major']
64+
$osarch = $facts['os']['architecture']
65+
$fips = 'false'
66+
$dev = count(split($puppet_agent::prepare::package_version, '\.')) > 3
67+
68+
$_download_puppet = "${puppet_agent::params::local_packages_dir}/download_puppet.sh"
69+
file { $_download_puppet:
70+
ensure => file,
71+
owner => $puppet_agent::params::user,
72+
group => $puppet_agent::params::group,
73+
mode => '0700',
74+
content => Sensitive(epp('puppet_agent/download_puppet.sh.epp')),
75+
}
76+
77+
exec { 'Download Puppet Agent':
78+
command => [$_download_puppet],
79+
creates => $local_package_file_path,
80+
require => File[$puppet_agent::params::local_packages_dir],
81+
}
5982
} else {
6083
file { $local_package_file_path:
6184
ensure => file,

tasks/install_shell.sh

Lines changed: 61 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -123,50 +123,39 @@ else
123123
collection='puppet'
124124
fi
125125

126+
if [[ "$collection" == "puppetcore"* && -z "$password" ]]; then
127+
echo "A password parameter is required to install from puppetcore"
128+
exit 1
129+
fi
130+
126131
if [ -n "$PT_yum_source" ]; then
127132
yum_source=$PT_yum_source
133+
elif [[ "$collection" == "puppetcore"* ]]; then
134+
yum_source='https://yum-puppetcore.puppet.com/public'
135+
elif [ "$nightly" = true ]; then
136+
yum_source='http://nightlies.puppet.com/yum'
128137
else
129-
if [[ "$collection" == "puppetcore"* ]]; then
130-
yum_source='https://yum-puppetcore.puppet.com/public'
131-
if [ -z "$password" ]; then
132-
echo "A password parameter is required to install from ${yum_source}"
133-
exit 1
134-
fi
135-
else
136-
if [ "$nightly" = true ]; then
137-
yum_source='http://nightlies.puppet.com/yum'
138-
else
139-
yum_source='http://yum.puppet.com'
140-
fi
141-
fi
138+
yum_source='http://yum.puppet.com'
142139
fi
143140

144141
if [ -n "$PT_apt_source" ]; then
145142
apt_source=$PT_apt_source
143+
elif [[ "$collection" == "puppetcore"* ]]; then
144+
apt_source='https://apt-puppetcore.puppet.com/public'
145+
elif [ "$nightly" = true ]; then
146+
apt_source='http://nightlies.puppet.com/apt'
146147
else
147-
if [[ "$collection" == "puppetcore"* ]]; then
148-
apt_source='https://apt-puppetcore.puppet.com/public'
149-
if [ -z "$password" ]; then
150-
echo "A password parameter is required to install from ${apt_source}"
151-
exit 1
152-
fi
153-
else
154-
if [ "$nightly" = true ]; then
155-
apt_source='http://nightlies.puppet.com/apt'
156-
else
157-
apt_source='http://apt.puppet.com'
158-
fi
159-
fi
148+
apt_source='http://apt.puppet.com'
160149
fi
161150

162151
if [ -n "$PT_mac_source" ]; then
163152
mac_source=$PT_mac_source
153+
elif [[ "$collection" == "puppetcore"* ]]; then
154+
mac_source='https://artifacts-puppetcore.puppet.com/v1/download'
155+
elif [ "$nightly" = true ]; then
156+
mac_source='http://nightlies.puppet.com/downloads'
164157
else
165-
if [ "$nightly" = true ]; then
166-
mac_source='http://nightlies.puppet.com/downloads'
167-
else
168-
mac_source='http://downloads.puppet.com'
169-
fi
158+
mac_source='http://downloads.puppet.com'
170159
fi
171160

172161
if [ -n "$PT_retry" ]; then
@@ -396,10 +385,14 @@ run_cmd() {
396385
return $rc
397386
}
398387

399-
# do_wget URL FILENAME
388+
# do_wget URL FILENAME [USERNAME] [PASSWORD]
400389
do_wget() {
401390
info "Trying wget..."
402-
run_cmd "wget -O '$2' '$1' 2>$tmp_stderr"
391+
if [[ -n "$3" && -n "$4" ]]; then
392+
run_cmd "wget -O '$2' --user '$3' --password '$4' '$1' 2>$tmp_stderr"
393+
else
394+
run_cmd "wget -O '$2' '$1' 2>$tmp_stderr"
395+
fi
403396
rc=$?
404397

405398
# check for 404
@@ -409,6 +402,13 @@ do_wget() {
409402
unable_to_retrieve_package
410403
fi
411404

405+
# check for 401
406+
grep "ERROR 401" $tmp_stderr 2>&1 >/dev/null
407+
if test $? -eq 0; then
408+
critical "ERROR 401"
409+
unable_to_retrieve_package
410+
fi
411+
412412
# check for bad return status or empty output
413413
if test $rc -ne 0 || test ! -s "$2"; then
414414
capture_tmp_stderr "wget"
@@ -418,19 +418,30 @@ do_wget() {
418418
return 0
419419
}
420420

421-
# do_curl URL FILENAME
421+
# do_curl URL FILENAME [USERNAME] [PASSWORD]
422422
do_curl() {
423423
info "Trying curl..."
424-
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
424+
if [[ -n "$3" && -n "$4" ]]; then
425+
run_cmd "curl -1 -sL -u'$3:$4' -D $tmp_stderr '$1' > '$2'"
426+
else
427+
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
428+
fi
425429
rc=$?
426430

427431
# check for 404
428-
grep "404 Not Found" $tmp_stderr 2>&1 >/dev/null
432+
grep "HTTP/.* 404" $tmp_stderr 2>&1 >/dev/null
429433
if test $? -eq 0; then
430434
critical "ERROR 404"
431435
unable_to_retrieve_package
432436
fi
433437

438+
# check for 401
439+
grep "HTTP/.* 401" $tmp_stderr 2>&1 >/dev/null
440+
if test $? -eq 0; then
441+
critical "ERROR 401"
442+
unable_to_retrieve_package
443+
fi
444+
434445
# check for bad return status or empty output
435446
if test $rc -ne 0 || test ! -s "$2"; then
436447
capture_tmp_stderr "curl"
@@ -544,7 +555,7 @@ do_perl_ff() {
544555
return 1
545556
}
546557

547-
# do_download URL FILENAME
558+
# do_download URL FILENAME [USERNAME] [PASSWORD]
548559
do_download() {
549560
info "Downloading $1"
550561
info " to file $2"
@@ -553,11 +564,11 @@ do_download() {
553564
# perl, in particular may be present but LWP::Simple may not be installed
554565

555566
if exists wget; then
556-
do_wget $1 $2 && return 0
567+
do_wget $1 $2 $3 $4 && return 0
557568
fi
558569

559570
if exists curl; then
560-
do_curl $1 $2 && return 0
571+
do_curl $1 $2 $3 $4 && return 0
561572
fi
562573

563574
if exists fetch; then
@@ -822,7 +833,16 @@ case $platform in
822833
if [[ $(uname -p) == "arm" ]]; then
823834
arch="arm64"
824835
fi
825-
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
836+
if [[ "$collection" =~ "puppetcore" ]]; then
837+
dots=$(echo "${version}" | grep -o '\.' | wc -l)
838+
if (( dots >= 3 )); then
839+
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&dev=true"
840+
else
841+
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}"
842+
fi
843+
else
844+
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
845+
fi
826846
;;
827847
*)
828848
critical "Sorry $platform is not supported yet!"
@@ -837,7 +857,7 @@ fi
837857
if [[ $PT__noop != true ]]; then
838858
download_filename="${tmp_dir}/${filename}"
839859

840-
do_download "$download_url" "$download_filename"
860+
do_download "$download_url" "$download_filename" "$username" "$password"
841861

842862
install_file $filetype "$download_filename"
843863

templates/download_puppet.sh.epp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -x
3+
netrc=$(mktemp)
4+
trap 'rm -f "$netrc"' EXIT
5+
chmod 0600 "$netrc"
6+
cat <<EOF > "$netrc"
7+
machine artifacts-puppetcore.puppet.com
8+
login <%= $puppet_agent::prepare::package::download_username %>
9+
password <%= $puppet_agent::prepare::package::download_password %>
10+
EOF
11+
/opt/puppetlabs/puppet/bin/curl \
12+
--get \
13+
--fail \
14+
--location \
15+
--netrc-file "$netrc" \
16+
--retry 3 \
17+
--data-urlencode "version=<%= $puppet_agent::prepare::package_version %>" \
18+
--data-urlencode "dev=<%= $puppet_agent::prepare::package::dev %>" \
19+
--data-urlencode "os_name=<%= $puppet_agent::prepare::package::osname %>" \
20+
--data-urlencode "os_version=<%= $puppet_agent::prepare::package::osversion %>" \
21+
--data-urlencode "os_arch=<%= $puppet_agent::prepare::package::osarch %>" \
22+
--data-urlencode "fips=<%= $puppet_agent::prepare::package::fips %>" \
23+
--output "<%= $puppet_agent::prepare::package::local_package_file_path %>" \
24+
"<%= $puppet_agent::prepare::package::source %>"
25+

0 commit comments

Comments
 (0)