Skip to content
Open
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
132 changes: 85 additions & 47 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,16 @@ assert_unmodified_apt_config() {
puppet_list=/etc/apt/sources.list.d/puppet.list
puppet7_list=/etc/apt/sources.list.d/puppet7.list
puppet8_list=/etc/apt/sources.list.d/puppet8.list
puppet9_list=/etc/apt/sources.list.d/puppet9.list

if [[ -f $puppet_list ]]; then
list_file=puppet_list
elif [[ -f $puppet7_list ]]; then
list_file=puppet7_list
elif [[ -f $puppet8_list ]]; then
list_file=puppet8_list
elif [[ -f $puppet9_list ]]; then
list_file=puppet9_list
Comment on lines 292 to +294
fi

# If puppet.list exists, get its md5sum on disk and its md5sum from the puppet-release package
Expand Down Expand Up @@ -360,50 +363,46 @@ else
collection='puppet'
fi

if [[ "$collection" != puppetcore*-nightly && "$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*-nightly ]]; then
yum_source='https://artifactory.delivery.puppetlabs.net:443/artifactory/internal_nightly__local/yum'
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*-nightly ]]; then
apt_source='https://artifactory.delivery.puppetlabs.net:443/artifactory/internal_nightly__local/apt'
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*-nightly ]]; then
mac_source='https://artifactory.delivery.puppetlabs.net:443/artifactory/internal_nightly__local/downloads'
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 @@ -518,6 +517,7 @@ if true; then
"13") platform_version="13";;
"14") platform_version="14";;
"15") platform_version="15";;
"26") platform_version="26";;
*) echo "No builds for platform: $major_version"
exit 1
;;
Expand Down Expand Up @@ -633,10 +633,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 @@ -646,6 +650,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
Comment on lines +653 to +655
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 @@ -655,19 +666,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 @@ -781,7 +803,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 @@ -790,11 +812,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
Comment on lines +815 to +819
fi

if exists fetch; then
Expand Down Expand Up @@ -835,7 +857,8 @@ install_file() {
if test "x$installed_version" != "xuninstalled"; then
info "Version ${installed_version} detected..."
major=$(echo $installed_version | cut -d. -f1)
pkg="puppet${major}-release"
pkg=$(rpm -qa --qf '%{NAME}\n' | grep "^puppet${major}.*-release$" | head -1)
[ -z "$pkg" ] && pkg="puppet${major}-release"

if echo $2 | grep $pkg; then
info "No collection upgrade detected"
Expand All @@ -847,7 +870,7 @@ install_file() {

repo="/etc/yum.repos.d/${collection/core/}-release.repo"
rpm -Uvh --oldpackage --replacepkgs "$2"
if [[ "$collection" =~ core ]]; then
if [[ "$collection" != puppetcore*-nightly && "$collection" =~ core ]]; then
if [[ -n $username ]]; then
sed -i "s/^#\?username=.*/username=${username}/" "${repo}"
fi
Expand All @@ -868,7 +891,8 @@ install_file() {
if test "x$installed_version" != "xuninstalled"; then
info "Version ${installed_version} detected..."
major=$(echo $installed_version | cut -d. -f1)
pkg="puppet${major}-release"
pkg=$(rpm -qa --qf '%{NAME}\n' | grep "^puppet${major}.*-release$" | head -1)
[ -z "$pkg" ] && pkg="puppet${major}-release"

if echo $2 | grep $pkg; then
info "No collection upgrade detected"
Expand All @@ -879,7 +903,7 @@ install_file() {
fi

run_cmd "zypper install --no-confirm '$2'"
if [[ "$collection" =~ core ]]; then
if [[ "$collection" != puppetcore*-nightly && "$collection" =~ core ]]; then
if [[ -n $username ]]; then
sed -i "s/^username=.*/username=${username}/" "/etc/zypp/credentials.d/PuppetcoreCreds"
fi
Expand All @@ -899,7 +923,8 @@ install_file() {
if test "x$installed_version" != "xuninstalled"; then
info "Version ${installed_version} detected..."
major=$(echo $installed_version | cut -d. -f1)
pkg="puppet${major}-release"
pkg=$(dpkg-query -W -f='${Package}\n' 2>/dev/null | grep "^puppet${major}.*-release$" | head -1)
[ -z "$pkg" ] && pkg="puppet${major}-release"

if echo $2 | grep $pkg; then
info "No collection upgrade detected"
Expand All @@ -912,7 +937,7 @@ install_file() {
assert_unmodified_apt_config

dpkg -i --force-confmiss "$2"
if [[ "$collection" =~ core ]]; then
if [[ "$collection" != puppetcore*-nightly && "$collection" =~ core ]]; then
auth_conf="/etc/apt/auth.conf.d/apt-puppetcore-puppet.conf"
sed -i "/^#?login/d" "${auth_conf}"
echo "login ${username}" >> "${auth_conf}"
Expand Down Expand Up @@ -1060,7 +1085,20 @@ case $platform in
if [[ $(uname -p) == "arm" ]]; then
arch="arm64"
fi
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
if [[ "$collection" != puppetcore*-nightly && "$collection" =~ core ]]; then
if [[ -z "$version" ]]; then
critical "You must provide a version to install the agent from puppetcore on MacOS/Windows."
exit 1
fi
dots=$(echo "${version}" | grep -o '\.' | wc -l)
if (( dots >= 3 )); then
download_url="${mac_source}?type=native&version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}&dev=true"
else
download_url="${mac_source}?type=native&version=${version}&os_name=osx&os_version=${platform_version}&os_arch=${arch}"
fi
else
download_url="${mac_source}/mac/${collection/core/}/${platform_version}/${arch}/${filename}"
fi
;;
*)
critical "Sorry $platform is not supported yet!"
Expand All @@ -1075,7 +1113,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