Skip to content

Commit 63e4e0d

Browse files
authored
Merge pull request #30 from puppetlabs/PA-6790-add-osx-15-x86_64-to-the-install-puppet-script
(PA-6790): Add support for Puppet 8 & osx-15-x86_64
2 parents 0e27f25 + 79ae828 commit 63e4e0d

File tree

3 files changed

+132
-35
lines changed

3 files changed

+132
-35
lines changed

install.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#!/usr/bin/env bash
1616
1717
beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
18-
18+
1919
function usage()
2020
{
2121
cat << HEREDOC
@@ -26,7 +26,7 @@
2626
-h, --help show this help message and exit
2727
-v, --version VERSION install a specific puppet-agent version
2828
-c, --collection COLLECTION install a specific puppet-agent collection (e.g. puppet7)
29-
-n, --noop do a dry run, do not change any files
29+
-n, --noop do a dry run, do not change any files
3030
--cleanup remove the puppetlabs repository after installation finishes
3131
3232
HEREDOC
@@ -39,6 +39,8 @@
3939
PT_collection="puppet6"
4040
elif beginswith "7." "$PT_version"; then
4141
PT_collection="puppet7"
42+
elif beginswith "8." "$PT_version"; then
43+
PT_collection="puppet8"
4244
else
4345
PT_collection="puppet"
4446
fi ;;

install.sh

+127-32
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
4-
4+
55
function usage()
66
{
77
cat << HEREDOC
@@ -12,7 +12,7 @@ function usage()
1212
-h, --help show this help message and exit
1313
-v, --version VERSION install a specific puppet-agent version
1414
-c, --collection COLLECTION install a specific puppet-agent collection (e.g. puppet7)
15-
-n, --noop do a dry run, do not change any files
15+
-n, --noop do a dry run, do not change any files
1616
--cleanup remove the puppetlabs repository after installation finishes
1717
1818
HEREDOC
@@ -25,6 +25,8 @@ while [[ "$#" -gt 0 ]]; do
2525
PT_collection="puppet6"
2626
elif beginswith "7." "$PT_version"; then
2727
PT_collection="puppet7"
28+
elif beginswith "8." "$PT_version"; then
29+
PT_collection="puppet8"
2830
else
2931
PT_collection="puppet"
3032
fi ;;
@@ -234,6 +236,9 @@ ID="$(munge_name "$ID")"
234236
family="$(munge_name "$family")"
235237

236238
#!/usr/bin/env bash
239+
240+
set -e
241+
237242
# Install puppet-agent as a task
238243
#
239244
# From https://github.com/petems/puppet-install-shell/blob/master/install_puppet_5_agent.sh
@@ -301,6 +306,11 @@ assert_unmodified_apt_config() {
301306
fi
302307
}
303308

309+
# Check whether apt-helper is available
310+
exists_apt_helper() {
311+
test -x /usr/lib/apt/apt-helper
312+
}
313+
304314
# Check whether python3 and urllib.request are available
305315
exists_python3_urllib() {
306316
python3 -c 'import urllib.request' >/dev/null 2>&1
@@ -327,6 +337,16 @@ if [ -n "$PT_version" ]; then
327337
version=$PT_version
328338
fi
329339

340+
if [ -n "$PT_username" ]; then
341+
username=$PT_username
342+
else
343+
username='forge-key'
344+
fi
345+
346+
if [ -n "$PT_password" ]; then
347+
password=$PT_password
348+
fi
349+
330350
if [ -n "$PT_collection" ]; then
331351
# Check whether collection is nightly
332352
if [[ "$PT_collection" == *"nightly"* ]]; then
@@ -343,28 +363,44 @@ fi
343363
if [ -n "$PT_yum_source" ]; then
344364
yum_source=$PT_yum_source
345365
else
346-
if [ "$nightly" = true ]; then
347-
yum_source='https://artifactory.delivery.puppetlabs.net:443/artifactory/internal_nightly__local/yum'
366+
if [[ "$collection" == "puppetcore"* ]]; then
367+
yum_source='https://yum-puppetcore.puppet.com/public'
368+
if [ -z "$password" ]; then
369+
echo "A password parameter is required to install from ${yum_source}"
370+
exit 1
371+
fi
348372
else
349-
yum_source='http://yum.puppet.com'
373+
if [ "$nightly" = true ]; then
374+
yum_source='http://nightlies.puppet.com/yum'
375+
else
376+
yum_source='http://yum.puppet.com'
377+
fi
350378
fi
351379
fi
352380

353381
if [ -n "$PT_apt_source" ]; then
354382
apt_source=$PT_apt_source
355383
else
356-
if [ "$nightly" = true ]; then
357-
apt_source='http://nightlies.puppet.com/apt'
384+
if [[ "$collection" == "puppetcore"* ]]; then
385+
apt_source='https://apt-puppetcore.puppet.com/public'
386+
if [ -z "$password" ]; then
387+
echo "A password parameter is required to install from ${apt_source}"
388+
exit 1
389+
fi
358390
else
359-
apt_source='http://apt.puppet.com'
391+
if [ "$nightly" = true ]; then
392+
apt_source='http://nightlies.puppet.com/apt'
393+
else
394+
apt_source='http://apt.puppet.com'
395+
fi
360396
fi
361397
fi
362398

363399
if [ -n "$PT_mac_source" ]; then
364400
mac_source=$PT_mac_source
365401
else
366402
if [ "$nightly" = true ]; then
367-
mac_source='https://artifactory.delivery.puppetlabs.net:443/artifactory/internal_nightly__local/downloads'
403+
mac_source='http://nightlies.puppet.com/downloads'
368404
else
369405
mac_source='http://downloads.puppet.com'
370406
fi
@@ -663,6 +699,27 @@ do_fetch() {
663699
return 0
664700
}
665701

702+
do_apt_helper() {
703+
info "Trying apt-helper..."
704+
run_cmd "/usr/lib/apt/apt-helper download-file '$1' '$2'" 2>$tmp_stderr
705+
rc=$?
706+
707+
# check for 404
708+
grep "E: Failed to fetch .* 404 " $tmp_stderr 2>&1 >/dev/null
709+
if test $? -eq 0; then
710+
critical "ERROR 404"
711+
unable_to_retrieve_package
712+
fi
713+
714+
# check for bad return status or empty output
715+
if test $rc -ne 0 && test ! -s "$2" ; then
716+
capture_tmp_stderr "apthelper"
717+
return 1
718+
fi
719+
720+
return 0
721+
}
722+
666723
do_python3_urllib() {
667724
info "Trying python3 (urllib.request)..."
668725
run_cmd "python3 -c 'import urllib.request ; urllib.request.urlretrieve(\"$1\", \"$2\")'" 2>$tmp_stderr
@@ -756,7 +813,11 @@ do_download() {
756813
do_python3_urllib $1 $2 && return 0
757814
fi
758815

759-
critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple/perl-File-Fetch/python3 is found"
816+
if exists_apt_helper; then
817+
do_apt_helper $1 $2 && return 0
818+
fi
819+
820+
critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple/perl-File-Fetch/python3/apt-helper is found"
760821
unable_to_retrieve_package
761822
}
762823

@@ -779,12 +840,21 @@ install_file() {
779840
if echo $2 | grep $pkg; then
780841
info "No collection upgrade detected"
781842
else
782-
info "Collection upgrade detected, replacing puppet${major}-release"
783-
rpm -e "puppet${major}-release"
843+
info "Collection upgrade detected, replacing $pkg"
844+
rpm -e "$pkg"
784845
fi
785846
fi
786847

848+
repo="/etc/yum.repos.d/${collection/core/}-release.repo"
787849
rpm -Uvh --oldpackage --replacepkgs "$2"
850+
if [[ "$collection" =~ core ]]; then
851+
if [[ -n $username ]]; then
852+
sed -i "s/^#\?username=.*/username=${username}/" "${repo}"
853+
fi
854+
if [[ -n $password ]]; then
855+
sed -i "s/^#\?password=.*/password=${password}/" "${repo}"
856+
fi
857+
fi
788858
exists dnf && PKGCMD=dnf || PKGCMD=yum
789859
if test "$version" = 'latest'; then
790860
run_cmd "${PKGCMD} install -y puppet-agent && ${PKGCMD} upgrade -y puppet-agent"
@@ -803,12 +873,20 @@ install_file() {
803873
if echo $2 | grep $pkg; then
804874
info "No collection upgrade detected"
805875
else
806-
info "Collection upgrade detected, replacing puppet${major}-release"
807-
zypper remove --no-confirm "puppet${major}-release"
876+
info "Collection upgrade detected, replacing $pkg"
877+
zypper remove --no-confirm "$pkg"
808878
fi
809879
fi
810880

811881
run_cmd "zypper install --no-confirm '$2'"
882+
if [[ "$collection" =~ core ]]; then
883+
if [[ -n $username ]]; then
884+
sed -i "s/^username=.*/username=${username}/" "/etc/zypp/credentials.d/PuppetcoreCreds"
885+
fi
886+
if [[ -n $password ]]; then
887+
sed -i "s/^password=.*/password=${password}/" "/etc/zypp/credentials.d/PuppetcoreCreds"
888+
fi
889+
fi
812890
if test "$version" = "latest"; then
813891
run_cmd "zypper install --no-confirm 'puppet-agent'"
814892
else
@@ -826,23 +904,31 @@ install_file() {
826904
if echo $2 | grep $pkg; then
827905
info "No collection upgrade detected"
828906
else
829-
info "Collection upgrade detected, replacing puppet${major}-release"
830-
dpkg --purge "puppet${major}-release"
907+
info "Collection upgrade detected, replacing $pkg"
908+
dpkg --purge "$pkg"
831909
fi
832910
fi
833911

834912
assert_unmodified_apt_config
835913

836914
dpkg -i --force-confmiss "$2"
915+
if [[ "$collection" =~ core ]]; then
916+
auth_conf="/etc/apt/auth.conf.d/apt-puppetcore-puppet.conf"
917+
sed -i "/^#?login/d" "${auth_conf}"
918+
echo "login ${username}" >> "${auth_conf}"
919+
sed -i "/^#?password/d" "${auth_conf}"
920+
echo "password ${password}" >> "${auth_conf}"
921+
fi
922+
frontend="DEBIAN_FRONTEND=noninteractive"
837923
run_cmd 'apt-get update -y'
838924

839925
if test "$version" = 'latest'; then
840-
run_cmd "apt-get install -y puppet-agent"
926+
run_cmd "${frontend} apt-get install -y puppet-agent"
841927
else
842928
if test "x$deb_codename" != "x"; then
843-
run_cmd "apt-get install -y 'puppet-agent=${puppet_agent_version}-1${deb_codename}'"
929+
run_cmd "${frontend} apt-get install -y 'puppet-agent=${puppet_agent_version}-1${deb_codename}'"
844930
else
845-
run_cmd "apt-get install -y 'puppet-agent=${puppet_agent_version}'"
931+
run_cmd "${frontend} apt-get install -y 'puppet-agent=${puppet_agent_version}'"
846932
fi
847933
fi
848934
;;
@@ -871,22 +957,31 @@ case $platform in
871957
info "SLES platform! Lets get you an RPM..."
872958

873959
if [[ $PT__noop != true ]]; then
874-
for key in "puppet" "puppet-20250406"; do
875-
gpg_key="${tmp_dir}/RPM-GPG-KEY-${key}"
876-
do_download "https://yum.puppet.com/RPM-GPG-KEY-${key}" "$gpg_key"
877-
rpm --import "$gpg_key"
878-
rm -f "$gpg_key"
879-
done
960+
if [[ "$collection" =~ core ]]; then
961+
for key in "puppet"; do
962+
gpg_key="${tmp_dir}/RPM-GPG-KEY-${key}"
963+
do_download "https://yum-puppetcore.puppet.com/public/RPM-GPG-KEY-${key}" "$gpg_key"
964+
rpm --import "$gpg_key"
965+
rm -f "$gpg_key"
966+
done
967+
else
968+
for key in "puppet" "puppet-20250406"; do
969+
gpg_key="${tmp_dir}/RPM-GPG-KEY-${key}"
970+
do_download "https://yum.puppet.com/RPM-GPG-KEY-${key}" "$gpg_key"
971+
rpm --import "$gpg_key"
972+
rm -f "$gpg_key"
973+
done
974+
fi
880975
fi
881976

882977
filetype="noarch.rpm"
883-
filename="${collection}-release-sles-${platform_version}.noarch.rpm"
978+
filename="${collection/core/}-release-sles-${platform_version}.noarch.rpm"
884979
download_url="${yum_source}/${filename}"
885980
;;
886981
"el")
887982
info "Red hat like platform! Lets get you an RPM..."
888983
filetype="rpm"
889-
filename="${collection}-release-el-${platform_version}.noarch.rpm"
984+
filename="${collection/core/}-release-el-${platform_version}.noarch.rpm"
890985
download_url="${yum_source}/${filename}"
891986
;;
892987
"Amzn"|"Amazon Linux")
@@ -900,13 +995,13 @@ case $platform in
900995
elif (( platform_version == 2 || platform_version >= 2023 )); then
901996
platform_package="amazon"
902997
fi
903-
filename="${collection}-release-${platform_package}-${platform_version}.noarch.rpm"
998+
filename="${collection/core/}-release-${platform_package}-${platform_version}.noarch.rpm"
904999
download_url="${yum_source}/${filename}"
9051000
;;
9061001
"Fedora")
9071002
info "Fedora platform! Lets get the RPM..."
9081003
filetype="rpm"
909-
filename="${collection}-release-fedora-${platform_version}.noarch.rpm"
1004+
filename="${collection/core/}-release-fedora-${platform_version}.noarch.rpm"
9101005
download_url="${yum_source}/${filename}"
9111006
;;
9121007
"Debian")
@@ -917,7 +1012,7 @@ case $platform in
9171012
"12") deb_codename="bookworm";;
9181013
esac
9191014
filetype="deb"
920-
filename="${collection}-release-${deb_codename}.deb"
1015+
filename="${collection/core/}-release-${deb_codename}.deb"
9211016
download_url="${apt_source}/${filename}"
9221017
;;
9231018
"Linuxmint"|"LinuxMint")
@@ -934,7 +1029,7 @@ case $platform in
9341029
"17") deb_codename="trusty";;
9351030
esac
9361031
filetype="deb"
937-
filename="${collection}-release-${deb_codename}.deb"
1032+
filename="${collection/core/}-release-${deb_codename}.deb"
9381033
download_url="${apt_source}/${filename}"
9391034
;;
9401035
"Ubuntu")
@@ -948,7 +1043,7 @@ case $platform in
9481043
"24.04") deb_codename="noble";;
9491044
esac
9501045
filetype="deb"
951-
filename="${collection}-release-${deb_codename}.deb"
1046+
filename="${collection/core/}-release-${deb_codename}.deb"
9521047
download_url="${apt_source}/${filename}"
9531048
;;
9541049
"mac_os_x")

0 commit comments

Comments
 (0)