Skip to content

Add puppetcore support for macOS #784

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 61 additions & 41 deletions tasks/install_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,50 +123,39 @@ else
collection='puppet'
fi

if [[ "$collection" == "puppetcore"* && -z "$password" ]]; then
echo "A password parameter is required to install from puppetcore"
exit 1
fi

if [ -n "$PT_yum_source" ]; then
yum_source=$PT_yum_source
elif [[ "$collection" == "puppetcore"* ]]; then
yum_source='https://yum-puppetcore.puppet.com/public'
elif [ "$nightly" = true ]; then
yum_source='http://nightlies.puppet.com/yum'
else
if [[ "$collection" == "puppetcore"* ]]; then
yum_source='https://yum-puppetcore.puppet.com/public'
if [ -z "$password" ]; then
echo "A password parameter is required to install from ${yum_source}"
exit 1
fi
else
if [ "$nightly" = true ]; then
yum_source='http://nightlies.puppet.com/yum'
else
yum_source='http://yum.puppet.com'
fi
fi
yum_source='http://yum.puppet.com'
fi

if [ -n "$PT_apt_source" ]; then
apt_source=$PT_apt_source
elif [[ "$collection" == "puppetcore"* ]]; then
apt_source='https://apt-puppetcore.puppet.com/public'
elif [ "$nightly" = true ]; then
apt_source='http://nightlies.puppet.com/apt'
else
if [[ "$collection" == "puppetcore"* ]]; then
apt_source='https://apt-puppetcore.puppet.com/public'
if [ -z "$password" ]; then
echo "A password parameter is required to install from ${apt_source}"
exit 1
fi
else
if [ "$nightly" = true ]; then
apt_source='http://nightlies.puppet.com/apt'
else
apt_source='http://apt.puppet.com'
fi
fi
apt_source='http://apt.puppet.com'
fi

if [ -n "$PT_mac_source" ]; then
mac_source=$PT_mac_source
elif [[ "$collection" == "puppetcore"* ]]; then
mac_source='https://artifacts-puppetcore.puppet.com/v1/download'
elif [ "$nightly" = true ]; then
mac_source='http://nightlies.puppet.com/downloads'
else
if [ "$nightly" = true ]; then
mac_source='http://nightlies.puppet.com/downloads'
else
mac_source='http://downloads.puppet.com'
fi
mac_source='http://downloads.puppet.com'
fi

if [ -n "$PT_retry" ]; then
Expand Down Expand Up @@ -396,10 +385,14 @@ run_cmd() {
return $rc
}

# do_wget URL FILENAME
# do_wget URL FILENAME [USERNAME] [PASSWORD]
do_wget() {
info "Trying wget..."
run_cmd "wget -O '$2' '$1' 2>$tmp_stderr"
if [[ -n "$3" && -n "$4" ]]; then
run_cmd "wget -O '$2' --user '$3' --password '$4' '$1' 2>$tmp_stderr"
else
run_cmd "wget -O '$2' '$1' 2>$tmp_stderr"
fi
rc=$?

# check for 404
Expand All @@ -409,6 +402,13 @@ do_wget() {
unable_to_retrieve_package
fi

# check for 401
grep "ERROR 401" $tmp_stderr 2>&1 >/dev/null
if test $? -eq 0; then
critical "ERROR 401"
unable_to_retrieve_package
fi

# check for bad return status or empty output
if test $rc -ne 0 || test ! -s "$2"; then
capture_tmp_stderr "wget"
Expand All @@ -418,19 +418,30 @@ do_wget() {
return 0
}

# do_curl URL FILENAME
# do_curl URL FILENAME [USERNAME] [PASSWORD]
do_curl() {
info "Trying curl..."
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
if [[ -n "$3" && -n "$4" ]]; then
run_cmd "curl -1 -sL -u'$3:$4' -D $tmp_stderr '$1' > '$2'"
else
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
fi
rc=$?

# check for 404
grep "404 Not Found" $tmp_stderr 2>&1 >/dev/null
grep "HTTP/.* 404" $tmp_stderr 2>&1 >/dev/null
if test $? -eq 0; then
critical "ERROR 404"
unable_to_retrieve_package
fi

# check for 401
grep "HTTP/.* 401" $tmp_stderr 2>&1 >/dev/null
if test $? -eq 0; then
critical "ERROR 401"
unable_to_retrieve_package
fi

# check for bad return status or empty output
if test $rc -ne 0 || test ! -s "$2"; then
capture_tmp_stderr "curl"
Expand Down Expand Up @@ -544,7 +555,7 @@ do_perl_ff() {
return 1
}

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

if exists wget; then
do_wget $1 $2 && return 0
do_wget $1 $2 $3 $4 && return 0
fi

if exists curl; then
do_curl $1 $2 && return 0
do_curl $1 $2 $3 $4 && return 0
fi

if exists fetch; then
Expand Down Expand Up @@ -822,7 +833,16 @@ case $platform in
if [[ $(uname -p) == "arm" ]]; then
arch="arm64"
fi
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
if [[ "$collection" =~ "puppetcore" ]]; then
dots=$(echo "${version}" | grep -o '\.' | wc -l)
if (( dots >= 3 )); then
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&dev=true"
else
download_url="${mac_source}?version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}"
fi
else
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
fi
;;
*)
critical "Sorry $platform is not supported yet!"
Expand All @@ -837,7 +857,7 @@ fi
if [[ $PT__noop != true ]]; then
download_filename="${tmp_dir}/${filename}"

do_download "$download_url" "$download_filename"
do_download "$download_url" "$download_filename" "$username" "$password"

install_file $filetype "$download_filename"

Expand Down
Loading