Skip to content

Commit 798731f

Browse files
committed
(PA-7586) Add puppetcore support for macOS
Install puppetcore packages on macOS via SSH: ``` /opt/puppetlabs/bolt/bin/bolt task run puppet_agent::install \ collection=puppetcore8 \ version=8.13.1 \ username=forge-key \ password=${PUPPET_FORGE_TOKEN} \ --targets www.example.com ```
1 parent f164f39 commit 798731f

File tree

1 file changed

+37
-12
lines changed

1 file changed

+37
-12
lines changed

tasks/install_shell.sh

Lines changed: 37 additions & 12 deletions
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'
165+
if [[ "$collection" == "puppetcore"* ]]; then
166+
mac_source='https://artifacts-puppetcore.puppet.com/v1/download'
167+
if [ -z "$password" ]; then
168+
echo "A password parameter is required to install from ${mac_source}"
169+
exit 1
170+
fi
167171
else
168-
mac_source='http://downloads.puppet.com'
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

@@ -396,10 +404,14 @@ run_cmd() {
396404
return $rc
397405
}
398406

399-
# do_wget URL FILENAME
407+
# do_wget URL FILENAME [USERNAME] [PASSWORD]
400408
do_wget() {
401409
info "Trying wget..."
402-
run_cmd "wget -O '$2' '$1' 2>$tmp_stderr"
410+
if [[ -n "$3" && -n "$4" ]]; then
411+
run_cmd "wget -O '$2' --user '$3' --password '$4' '$1' 2>$tmp_stderr"
412+
else
413+
run_cmd "wget -O '$2' '$1' 2>$tmp_stderr"
414+
fi
403415
rc=$?
404416

405417
# check for 404
@@ -418,10 +430,14 @@ do_wget() {
418430
return 0
419431
}
420432

421-
# do_curl URL FILENAME
433+
# do_curl URL FILENAME [USERNAME] [PASSWORD]
422434
do_curl() {
423435
info "Trying curl..."
424-
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
436+
if [[ -n "$3" && -n "$4" ]]; then
437+
run_cmd "curl -1 -sL -u'$3:$4' -D $tmp_stderr '$1' > '$2'"
438+
else
439+
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
440+
fi
425441
rc=$?
426442

427443
# check for 404
@@ -544,7 +560,7 @@ do_perl_ff() {
544560
return 1
545561
}
546562

547-
# do_download URL FILENAME
563+
# do_download URL FILENAME [USERNAME] [PASSWORD]
548564
do_download() {
549565
info "Downloading $1"
550566
info " to file $2"
@@ -553,11 +569,11 @@ do_download() {
553569
# perl, in particular may be present but LWP::Simple may not be installed
554570

555571
if exists wget; then
556-
do_wget $1 $2 && return 0
572+
do_wget $1 $2 $3 $4 && return 0
557573
fi
558574

559575
if exists curl; then
560-
do_curl $1 $2 && return 0
576+
do_curl $1 $2 $3 $4 && return 0
561577
fi
562578

563579
if exists fetch; then
@@ -822,7 +838,16 @@ case $platform in
822838
if [[ $(uname -p) == "arm" ]]; then
823839
arch="arm64"
824840
fi
825-
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
841+
if [[ "$collection" =~ "puppetcore" ]]; then
842+
dots=$(echo "${version}" | grep -o '\.' | wc -l)
843+
if (( dots >= 3 )); then
844+
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&dev=true"
845+
else
846+
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}"
847+
fi
848+
else
849+
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
850+
fi
826851
;;
827852
*)
828853
critical "Sorry $platform is not supported yet!"
@@ -837,7 +862,7 @@ fi
837862
if [[ $PT__noop != true ]]; then
838863
download_filename="${tmp_dir}/${filename}"
839864

840-
do_download "$download_url" "$download_filename"
865+
do_download "$download_url" "$download_filename" "$username" "$password"
841866

842867
install_file $filetype "$download_filename"
843868

0 commit comments

Comments
 (0)