1
1
#! /usr/bin/env bash
2
2
3
3
beginswith () { case $2 in " $1 " * ) true ;; * ) false ;; esac ; }
4
-
4
+
5
5
function usage()
6
6
{
7
7
cat << HEREDOC
@@ -12,7 +12,7 @@ function usage()
12
12
-h, --help show this help message and exit
13
13
-v, --version VERSION install a specific puppet-agent version
14
14
-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
16
16
--cleanup remove the puppetlabs repository after installation finishes
17
17
18
18
HEREDOC
@@ -25,6 +25,8 @@ while [[ "$#" -gt 0 ]]; do
25
25
PT_collection=" puppet6"
26
26
elif beginswith " 7." " $PT_version " ; then
27
27
PT_collection=" puppet7"
28
+ elif beginswith " 8." " $PT_version " ; then
29
+ PT_collection=" puppet8"
28
30
else
29
31
PT_collection=" puppet"
30
32
fi ;;
@@ -234,6 +236,9 @@ ID="$(munge_name "$ID")"
234
236
family=" $( munge_name " $family " ) "
235
237
236
238
#! /usr/bin/env bash
239
+
240
+ set -e
241
+
237
242
# Install puppet-agent as a task
238
243
#
239
244
# From https://github.com/petems/puppet-install-shell/blob/master/install_puppet_5_agent.sh
@@ -301,6 +306,11 @@ assert_unmodified_apt_config() {
301
306
fi
302
307
}
303
308
309
+ # Check whether apt-helper is available
310
+ exists_apt_helper () {
311
+ test -x /usr/lib/apt/apt-helper
312
+ }
313
+
304
314
# Check whether python3 and urllib.request are available
305
315
exists_python3_urllib () {
306
316
python3 -c ' import urllib.request' > /dev/null 2>&1
@@ -327,6 +337,16 @@ if [ -n "$PT_version" ]; then
327
337
version=$PT_version
328
338
fi
329
339
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
+
330
350
if [ -n " $PT_collection " ]; then
331
351
# Check whether collection is nightly
332
352
if [[ " $PT_collection " == * " nightly" * ]]; then
343
363
if [ -n " $PT_yum_source " ]; then
344
364
yum_source=$PT_yum_source
345
365
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
348
372
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
350
378
fi
351
379
fi
352
380
353
381
if [ -n " $PT_apt_source " ]; then
354
382
apt_source=$PT_apt_source
355
383
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
358
390
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
360
396
fi
361
397
fi
362
398
363
399
if [ -n " $PT_mac_source " ]; then
364
400
mac_source=$PT_mac_source
365
401
else
366
402
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'
368
404
else
369
405
mac_source=' http://downloads.puppet.com'
370
406
fi
@@ -663,6 +699,27 @@ do_fetch() {
663
699
return 0
664
700
}
665
701
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
+
666
723
do_python3_urllib () {
667
724
info " Trying python3 (urllib.request)..."
668
725
run_cmd " python3 -c 'import urllib.request ; urllib.request.urlretrieve(\" $1 \" , \" $2 \" )'" 2> $tmp_stderr
@@ -756,7 +813,11 @@ do_download() {
756
813
do_python3_urllib $1 $2 && return 0
757
814
fi
758
815
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"
760
821
unable_to_retrieve_package
761
822
}
762
823
@@ -779,12 +840,21 @@ install_file() {
779
840
if echo $2 | grep $pkg ; then
780
841
info " No collection upgrade detected"
781
842
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 "
784
845
fi
785
846
fi
786
847
848
+ repo=" /etc/yum.repos.d/${collection/ core/ } -release.repo"
787
849
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
788
858
exists dnf && PKGCMD=dnf || PKGCMD=yum
789
859
if test " $version " = ' latest' ; then
790
860
run_cmd " ${PKGCMD} install -y puppet-agent && ${PKGCMD} upgrade -y puppet-agent"
@@ -803,12 +873,20 @@ install_file() {
803
873
if echo $2 | grep $pkg ; then
804
874
info " No collection upgrade detected"
805
875
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 "
808
878
fi
809
879
fi
810
880
811
881
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
812
890
if test " $version " = " latest" ; then
813
891
run_cmd " zypper install --no-confirm 'puppet-agent'"
814
892
else
@@ -826,23 +904,31 @@ install_file() {
826
904
if echo $2 | grep $pkg ; then
827
905
info " No collection upgrade detected"
828
906
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 "
831
909
fi
832
910
fi
833
911
834
912
assert_unmodified_apt_config
835
913
836
914
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"
837
923
run_cmd ' apt-get update -y'
838
924
839
925
if test " $version " = ' latest' ; then
840
- run_cmd " apt-get install -y puppet-agent"
926
+ run_cmd " ${frontend} apt-get install -y puppet-agent"
841
927
else
842
928
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} '"
844
930
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} '"
846
932
fi
847
933
fi
848
934
;;
@@ -871,22 +957,31 @@ case $platform in
871
957
info " SLES platform! Lets get you an RPM..."
872
958
873
959
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
880
975
fi
881
976
882
977
filetype=" noarch.rpm"
883
- filename=" ${collection} -release-sles-${platform_version} .noarch.rpm"
978
+ filename=" ${collection/ core / } -release-sles-${platform_version} .noarch.rpm"
884
979
download_url=" ${yum_source} /${filename} "
885
980
;;
886
981
" el" )
887
982
info " Red hat like platform! Lets get you an RPM..."
888
983
filetype=" rpm"
889
- filename=" ${collection} -release-el-${platform_version} .noarch.rpm"
984
+ filename=" ${collection/ core / } -release-el-${platform_version} .noarch.rpm"
890
985
download_url=" ${yum_source} /${filename} "
891
986
;;
892
987
" Amzn" |" Amazon Linux" )
@@ -900,13 +995,13 @@ case $platform in
900
995
elif (( platform_version == 2 || platform_version >= 2023 )) ; then
901
996
platform_package=" amazon"
902
997
fi
903
- filename=" ${collection} -release-${platform_package} -${platform_version} .noarch.rpm"
998
+ filename=" ${collection/ core / } -release-${platform_package} -${platform_version} .noarch.rpm"
904
999
download_url=" ${yum_source} /${filename} "
905
1000
;;
906
1001
" Fedora" )
907
1002
info " Fedora platform! Lets get the RPM..."
908
1003
filetype=" rpm"
909
- filename=" ${collection} -release-fedora-${platform_version} .noarch.rpm"
1004
+ filename=" ${collection/ core / } -release-fedora-${platform_version} .noarch.rpm"
910
1005
download_url=" ${yum_source} /${filename} "
911
1006
;;
912
1007
" Debian" )
@@ -917,7 +1012,7 @@ case $platform in
917
1012
" 12" ) deb_codename=" bookworm" ;;
918
1013
esac
919
1014
filetype=" deb"
920
- filename=" ${collection} -release-${deb_codename} .deb"
1015
+ filename=" ${collection/ core / } -release-${deb_codename} .deb"
921
1016
download_url=" ${apt_source} /${filename} "
922
1017
;;
923
1018
" Linuxmint" |" LinuxMint" )
@@ -934,7 +1029,7 @@ case $platform in
934
1029
" 17" ) deb_codename=" trusty" ;;
935
1030
esac
936
1031
filetype=" deb"
937
- filename=" ${collection} -release-${deb_codename} .deb"
1032
+ filename=" ${collection/ core / } -release-${deb_codename} .deb"
938
1033
download_url=" ${apt_source} /${filename} "
939
1034
;;
940
1035
" Ubuntu" )
@@ -948,7 +1043,7 @@ case $platform in
948
1043
" 24.04" ) deb_codename=" noble" ;;
949
1044
esac
950
1045
filetype=" deb"
951
- filename=" ${collection} -release-${deb_codename} .deb"
1046
+ filename=" ${collection/ core / } -release-${deb_codename} .deb"
952
1047
download_url=" ${apt_source} /${filename} "
953
1048
;;
954
1049
" mac_os_x" )
0 commit comments