forked from puppetlabs/install-puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·944 lines (814 loc) · 24.7 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
#!/usr/bin/env bash
beginswith() { case $2 in "$1"*) true;; *) false;; esac; }
function usage()
{
cat << HEREDOC
Usage: install.sh [--version VERSION] [--collection COLLECTION] [--cleanup] [--noop]
optional arguments:
-h, --help show this help message and exit
-v, --version VERSION install a specific puppet-agent version
-c, --collection COLLECTION install a specific puppet-agent collection (e.g. puppet7)
-n, --noop do a dry run, do not change any files
--cleanup remove the puppetlabs repository after installation finishes
HEREDOC
}
while [[ "$#" -gt 0 ]]; do
case $1 in
-v|--version) PT_version="$2"; shift ;
if beginswith "6." "$PT_version"; then
PT_collection="puppet6"
elif beginswith "7." "$PT_version"; then
PT_collection="puppet7"
else
PT_collection="puppet"
fi ;;
-c|--collection) PT_collection="$2"; shift ;;
--cleanup) PT_cleanup=true; shift ;;
-n|--noop) PT__noop=true; shift ;;
-h|--help) usage; exit ;;
*) echo "Unknown parameter passed: $1"; usage; exit 1 ;;
esac
shift
done
# shellcheck disable=SC1000-SC9999
{
#!/bin/bash
# This script may be called outside of a task, e.g. by puppet_agent
# so we have to just paste this code here. *grumbles*
# Exit with an error message and error code, defaulting to 1
fail() {
# Print a message: entry if there were anything printed to stderr
if [[ -s $_tmp ]]; then
# Hack to try and output valid json by replacing newlines with spaces.
error_data="{ \"msg\": \"$(tr '\n' ' ' <"$_tmp")\", \"kind\": \"bash-error\", \"details\": {} }"
else
error_data="{ \"msg\": \"Task error\", \"kind\": \"bash-error\", \"details\": {} }"
fi
echo "{ \"status\": \"failure\", \"_error\": $error_data }"
exit "${2:-1}"
}
validation_error() {
error_data="{ \"msg\": \""$1"\", \"kind\": \"bash-error\", \"details\": {} }"
echo "{ \"status\": \"failure\", \"_error\": $error_data }"
exit 255
}
success() {
echo "$1"
}
determine_command_for_facter_4() {
puppet_version="$(puppet --version)"
if (( ${puppet_version%%.*} == 6 )); then
# puppet 6 with facter 4
facts_command=(facter --json --show-legacy)
else
# puppet 7 with facter 4
facts_command=(puppet facts show --show-legacy --render-as json)
fi
}
maybe_delegate_to_facter() {
[[ $PATH =~ \/opt\/puppetlabs\/bin ]] || export PATH="${PATH}:/opt/puppetlabs/bin"
# Only use facter if we're running as the "facts" task, not the "facts::bash"
# task. This also skips calling facter if we're running as a script, which is
# used by the puppet_agent task.
if [[ $PT__task == facts ]] && type facter &>/dev/null; then
facter_version="$(facter -v)"
if (( ${facter_version%%.*} <= 2 )); then
facts_command=(facter -p --json)
elif (( ${facter_version%%.*} == 3 )); then
facts_command=(facter -p --json --show-legacy)
else
# facter 4
determine_command_for_facter_4
fi
exec -- "${facts_command[@]}"
fi
}
# Get info from one of /etc/os-release or /usr/lib/os-release
# This is the preferred method and is checked first
_systemd() {
# These files may have unquoted spaces in the "pretty" fields even if the spec says otherwise
# source cannot use process subsitution in some versions of bash, so redirect to stdin instead
source /dev/stdin <<<"$(sed 's/ /_/g' "$1")"
# According to `man os-release`, the first entry in ID_LIKE
# should be the one the platform most closely resembles
if [[ $ID = 'rhel' ]]; then
family='RedHat'
elif [[ $ID = 'debian' ]]; then
family='Debian'
elif [[ $ID_LIKE ]]; then
family="${ID_LIKE%% *}"
else
family="${ID}"
fi
}
# Get info from lsb_release
_lsb_release() {
read -r ID < <(lsb_release -si)
read -r VERSION_ID < <(lsb_release -sr)
read -r VERSION_CODENAME < <(lsb_release -sc)
}
# Get info from rhel /etc/*-release files
_rhel() {
family='RedHat'
# slurp the file
ver_info=$(<"$1")
# ID is the first word in the string
ID="${ver_info%% *}"
# Codename is hopefully the word(s) in parenthesis
if echo "$ver_info" | grep -q '('; then
VERSION_CODENAME="${ver_info##*\(}"
VERSION_CODENAME=""${VERSION_CODENAME//[()]/}""
fi
# Get a string like 'release 1.2.3' and grab everything after the space
release=$(echo "$ver_info" | grep -Eo 'release[[:space:]]*[0-9.]+')
VERSION_ID="${release#* }"
}
# Last resort
_uname() {
[[ $ID ]] || ID="$(uname)"
[[ $VERSION_ID ]] || VERSION_ID="$(uname -r)"
}
# Taken from https://github.com/puppetlabs/facter/blob/master/lib/inc/facter/facts/os.hpp
# If not in this list, we just uppercase the first character and lowercase the rest
munge_name() {
case "$1" in
redhat|rhel|red) echo "RedHat" ;;
ol|oracle) echo "OracleLinux" ;;
ubuntu) echo "Ubuntu" ;;
debian) echo "Debian" ;;
centos) echo "CentOS" ;;
cloud) echo "CloudLinux" ;;
virtuozzo) echo "VirtuozzoLinux" ;;
psbm) echo "PSBM" ;;
xenserver) echo "XenServer" ;;
linuxmint) echo "LinuxMint" ;;
sles) echo "SLES" ;;
suse) echo "SuSE" ;;
opensuse) echo "OpenSuSE" ;;
sunos) echo "SunOS" ;;
omni) echo "OmniOS" ;;
openindiana) echo "OpenIndiana" ;;
manjaro) echo "ManjaroLinux" ;;
smart) echo "SmartOS" ;;
openwrt) echo "OpenWrt" ;;
meego) echo "MeeGo" ;;
coreos) echo "CoreOS" ;;
zen) echo "XCP" ;;
kfreebsd) echo "GNU/kFreeBSD" ;;
arista) echo "AristaEOS" ;;
huawei) echo "HuaweiOS" ;;
photon) echo "PhotonOS" ;;
freebsd) echo "FreeBSD" ;;
*) echo "$(tr '[:lower:]' '[:upper:]' <<<"${ID:0:1}")""$(tr '[:upper:]' '[:lower:'] <<<"${ID:1}")"
esac
}
_tmp="$(mktemp)"
exec 2>>"$_tmp"
shopt -s nocasematch
# Use indirection to munge PT_ environment variables
# e.g. "$PT_version" becomes "$version"
for v in ${!PT_*}; do
declare "${v#*PT_}"="${!v}"
done
# Delegate to facter executable if it exists. This function will `exec` and not
# return if facter exists. Otherwise, we'll continue on.
maybe_delegate_to_facter "$@"
if [[ -e /etc/os-release ]]; then
_systemd /etc/os-release
elif [[ -e /usr/lib/os-release ]]; then
_systemd /usr/lib/os-release
fi
# If either systemd is not installed or we didn't get a minor version or codename from os-release
if ! [[ $VERSION_ID ]] || (( ${VERSION_ID%%.*} == ${VERSION_ID#*.} )) || ! [[ $VERSION_CODENAME ]]; then
if [[ -e /etc/fedora-release ]]; then
_rhel /etc/fedora-release
elif [[ -e /etc/centos-release ]]; then
_rhel /etc/centos-release
elif [[ -e /etc/oracle-release ]]; then
_rhel /etc/oracle-release
elif [[ -e /etc/redhat-release ]]; then
_rhel /etc/redhat-release
elif type lsb_release &>/dev/null; then
_lsb_release
else
_uname
fi
fi
full="${VERSION_ID}"
major="${VERSION_ID%%.*}"
# Minor is considered the second part of the version string
IFS='.' read -ra minor <<<"$full"
minor="${minor[1]}"
ID="$(munge_name "$ID")"
family="$(munge_name "$family")"
#!/usr/bin/env bash
# Install puppet-agent as a task
#
# From https://github.com/petems/puppet-install-shell/blob/master/install_puppet_5_agent.sh
# Timestamp
now () {
date +'%H:%M:%S %z'
}
# Logging functions instead of echo
log () {
echo "`now` ${1}"
}
info () {
if [[ $PT__noop != true ]]; then
log "INFO: ${1}"
fi
}
warn () {
log "WARN: ${1}"
}
critical () {
log "CRIT: ${1}"
}
# Check whether a command exists - returns 0 if it does, 1 if it does not
exists() {
if command -v $1 >/dev/null 2>&1
then
return 0
else
return 1
fi
}
# Check whether the apt config file has been modified, warning and exiting early if it has
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
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
fi
# If puppet.list exists, get its md5sum on disk and its md5sum from the puppet-release package
if [[ -n $list_file ]]; then
# For md5sum, the checksum is the first word
file_md5=($(md5sum "$list_file"))
# For dpkg-query with this output format, the sum is the second word
package_md5=($(dpkg-query -W -f='${Conffiles}\n' 'puppet-release' | grep -F "$list_file"))
# If the $package_md5 array is set, and the md5sum on disk doesn't match the md5sum from dpkg-query, it has been modified
if [[ $package_md5 && ${file_md5[0]} != ${package_md5[1]} ]]; then
warn "Configuration file $list_file has been modified from the default. Skipping agent installation."
exit 1
fi
fi
}
# Check whether perl and LWP::Simple module are installed
exists_perl() {
if perl -e 'use LWP::Simple;' >/dev/null 2>&1
then
return 0
else
return 1
fi
}
# Get command line arguments
if [ -n "$PT_version" ]; then
version=$PT_version
fi
if [ -n "$PT_collection" ]; then
# Check whether collection is nightly
if [[ "$PT_collection" == *"nightly"* ]]; then
nightly=true
else
nightly=false
fi
collection=$PT_collection
else
collection='puppet'
fi
if [ -n "$PT_yum_source" ]; then
yum_source=$PT_yum_source
else
if [ "$nightly" = true ]; then
yum_source='http://nightlies.puppet.com/yum'
else
yum_source='http://yum.puppet.com'
fi
fi
if [ -n "$PT_apt_source" ]; then
apt_source=$PT_apt_source
else
if [ "$nightly" = true ]; then
apt_source='http://nightlies.puppet.com/apt'
else
apt_source='http://apt.puppet.com'
fi
fi
if [ -n "$PT_mac_source" ]; then
mac_source=$PT_mac_source
else
if [ "$nightly" = true ]; then
mac_source='http://nightlies.puppet.com/downloads'
else
mac_source='http://downloads.puppet.com'
fi
fi
if [ -n "$PT_retry" ]; then
retry=$PT_retry
else
retry=5
fi
# Track to handle puppet5 to puppet6
if [ -f /opt/puppetlabs/puppet/VERSION ]; then
installed_version=`cat /opt/puppetlabs/puppet/VERSION`
elif which puppet >/dev/null 2>&1; then
installed_version=`puppet --version`
else
installed_version=uninstalled
fi
# Only install the agent in cases where no agent is present, or the version of the agent
# has been explicitly defined and does not match the version of an installed agent.
if [ -z "$version" ]; then
if [ "$installed_version" == "uninstalled" ]; then
info "Version parameter not defined and no agent detected. Assuming latest."
version=latest
else
info "Version parameter not defined and agent detected. Nothing to do."
exit 0
fi
else
info "Version parameter defined: ${version}"
if [ "$version" == "$installed_version" ]; then
info "Version parameter defined: ${version}. Puppet Agent ${version} detected. Nothing to do."
exit 0
elif [ "$version" != "latest" ]; then
puppet_agent_version="$version"
fi
fi
# Error if non-root
if [ `id -u` -ne 0 ]; then
echo "puppet_agent::install task must be run as root"
exit 1
fi
# Retrieve Platform and Platform Version
# Utilize facts implementation when available
if true; then
# Use facts module bash.sh implementation
platform=$ID
platform_version=$full
# Handle CentOS
if test "x$platform" = "xCentOS"; then
platform="el"
# Handle Rocky
elif test "x$platform" = "xRocky"; then
platform="el"
# Handle Oracle
elif test "x$platform" = "xOracle Linux Server"; then
platform="el"
elif test "x$platform" = "xOracleLinux"; then
platform="el"
# Handle Scientific
elif test "x$platform" = "xScientific Linux"; then
platform="el"
elif test "x$platform" = "xScientific"; then
platform="el"
# Handle RedHat
elif test "x$platform" = "xRedHat"; then
platform="el"
# Handle Rocky
elif test "x$platform" = "xRocky"; then
platform="el"
# Handle AlmaLinux
elif test "x$platform" = "xAlmalinux"; then
platform="el"
# If facts task return "Linux" for platform, investigate.
elif test "x$platform" = "xLinux"; then
if test -f "/etc/SuSE-release"; then
if grep -q 'Enterprise' /etc/SuSE-release; then
platform="SLES"
platform_version=`awk '/^VERSION/ {V = $3}; /^PATCHLEVEL/ {P = $3}; END {print V "." P}' /etc/SuSE-release`
else
echo "No builds for platform: SUSE"
exit 1
fi
elif test -f "/etc/redhat-release"; then
platform="el"
platform_version=`sed 's/^.\+ release \([.0-9]\+\).*/\1/' /etc/redhat-release`
fi
# Handle macOS
elif test "x$platform" = "xDarwin"; then
platform="mac_os_x"
# Matching the tab-space with sed is error-prone
platform_version=`sw_vers | awk '/^ProductVersion:/ { print $2 }'`
major_version=`echo $platform_version | cut -d. -f1,2`
# Excepting macOS 10.x, the major version is the first number only
if ! echo "${major_version}" | grep -q '^10\.'; then
major_version=$(echo "${major_version}" | cut -d '.' -f 1);
fi
case $major_version in
"11") platform_version="11";;
"12") platform_version="12";;
*) echo "No builds for platform: $major_version"
exit 1
;;
esac
fi
else
echo "This module depends on the puppetlabs-facts module"
exit 1
fi
if test "x$platform" = "x"; then
critical "Unable to determine platform version!"
exit 1
fi
# Mangle $platform_version to pull the correct build
# for various platforms
major_version=`echo $platform_version | cut -d. -f1`
case $platform in
"el")
platform_version=$major_version
;;
"Fedora")
case $major_version in
"23") platform_version="22";;
*) platform_version=$major_version;;
esac
;;
"Debian")
case $major_version in
"5") platform_version="6";;
"6") platform_version="6";;
"7") platform_version="6";;
esac
;;
"SLES")
platform_version=$major_version
;;
"Amzn"|"Amazon Linux")
case $platform_version in
"2") platform_version="7";;
esac
;;
esac
# Find which version of puppet is currently installed if any
if test "x$platform_version" = "x"; then
critical "Unable to determine platform version!"
exit 1
fi
unable_to_retrieve_package() {
critical "Unable to retrieve a valid package!"
exit 1
}
random_hexdump () {
hexdump -n 2 -e '/2 "%u"' /dev/urandom
}
if test "x$TMPDIR" = "x"; then
tmp="/tmp"
else
tmp=${TMPDIR}
# TMPDIR has trailing file sep for macOS test box
penultimate=$((${#tmp}-1))
if test "${tmp:$penultimate:1}" = "/"; then
tmp="${tmp:0:$penultimate}"
fi
fi
# Random function since not all shells have $RANDOM
if exists hexdump; then
random_number=$(random_hexdump)
else
random_number="`date +%N`"
fi
tmp_dir="$tmp/install.sh.$$.$random_number"
(umask 077 && mkdir $tmp_dir) || exit 1
tmp_stderr="$tmp/stderr.$$.$random_number"
capture_tmp_stderr() {
# spool up tmp_stderr from all the commands we called
if test -f $tmp_stderr; then
output=`cat ${tmp_stderr}`
stderr_results="${stderr_results}\nSTDERR from $1:\n\n$output\n"
fi
}
trap "rm -f $tmp_stderr; rm -rf $tmp_dir; exit $1" 1 2 15
# Run command and retry on failure
# run_cmd CMD
run_cmd() {
eval $1
rc=$?
if test $rc -ne 0; then
attempt_number=0
while test $attempt_number -lt $retry; do
info "Retrying... [$((attempt_number + 1))/$retry]"
eval $1
rc=$?
if test $rc -eq 0; then
break
fi
info "Return code: $rc"
sleep 1s
((attempt_number=attempt_number+1))
done
fi
return $rc
}
# do_wget URL FILENAME
do_wget() {
info "Trying wget..."
run_cmd "wget -O '$2' '$1' 2>$tmp_stderr"
rc=$?
# check for 404
grep "ERROR 404" $tmp_stderr 2>&1 >/dev/null
if test $? -eq 0; then
critical "ERROR 404"
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"
return 1
fi
return 0
}
# do_curl URL FILENAME
do_curl() {
info "Trying curl..."
run_cmd "curl -1 -sL -D $tmp_stderr '$1' > '$2'"
rc=$?
# check for 404
grep "404 Not Found" $tmp_stderr 2>&1 >/dev/null
if test $? -eq 0; then
critical "ERROR 404"
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"
return 1
fi
return 0
}
# do_fetch URL FILENAME
do_fetch() {
info "Trying fetch..."
run_cmd "fetch -o '$2' '$1' 2>$tmp_stderr"
rc=$?
# check for 404
grep "404 Not Found" $tmp_stderr 2>&1 >/dev/null
if test $? -eq 0; then
critical "ERROR 404"
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 "fetch"
return 1
fi
return 0
}
# do_perl URL FILENAME
do_perl() {
info "Trying perl..."
run_cmd "perl -e 'use LWP::Simple; getprint(\$ARGV[0]);' '$1' > '$2' 2>$tmp_stderr"
rc=$?
# check for 404
grep "404 Not Found" $tmp_stderr 2>&1 >/dev/null
if test $? -eq 0; then
critical "ERROR 404"
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 "perl"
return 1
fi
return 0
}
# do_download URL FILENAME
do_download() {
info "Downloading $1"
info " to file $2"
# we try all of these until we get success.
# perl, in particular may be present but LWP::Simple may not be installed
if exists wget; then
do_wget $1 $2 && return 0
fi
if exists curl; then
do_curl $1 $2 && return 0
fi
if exists fetch; then
do_fetch $1 $2 && return 0
fi
if exists_perl; then
do_perl $1 $2 && return 0
fi
critical "Cannot download package as none of wget/curl/fetch/perl-LWP-Simple is found"
unable_to_retrieve_package
}
# install_file TYPE FILENAME
# TYPE is "rpm", "deb", "solaris" or "dmg"
install_file() {
case "$1" in
"rpm")
info "installing puppetlabs yum repo with rpm..."
if test -f "/etc/yum.repos.d/puppetlabs-pc1.repo"; then
info "existing puppetlabs yum repo found, moving to old location"
mv /etc/yum.repos.d/puppetlabs-pc1.repo /etc/yum.repos.d/puppetlabs-pc1.repo.old
fi
if test "x$installed_version" != "xuninstalled"; then
info "Version ${installed_version} detected..."
major=$(echo $installed_version | cut -d. -f1)
pkg="puppet${major}-release"
if echo $2 | grep $pkg; then
info "No collection upgrade detected"
else
info "Collection upgrade detected, replacing puppet${major}-release"
rpm -e "puppet${major}-release"
fi
fi
rpm -Uvh --oldpackage --replacepkgs "$2"
if test "$version" = 'latest'; then
run_cmd "yum install -y puppet-agent && yum upgrade -y puppet-agent"
else
run_cmd "yum install -y 'puppet-agent-${puppet_agent_version}'"
fi
;;
"noarch.rpm")
info "installing puppetlabs yum repo with zypper..."
if test "x$installed_version" != "xuninstalled"; then
info "Version ${installed_version} detected..."
major=$(echo $installed_version | cut -d. -f1)
pkg="puppet${major}-release"
if echo $2 | grep $pkg; then
info "No collection upgrade detected"
else
info "Collection upgrade detected, replacing puppet${major}-release"
zypper remove --no-confirm "puppet${major}-release"
fi
fi
run_cmd "zypper install --no-confirm '$2'"
if test "$version" = "latest"; then
run_cmd "zypper install --no-confirm 'puppet-agent'"
else
run_cmd "zypper install --no-confirm --oldpackage --no-recommends --no-confirm 'puppet-agent-${puppet_agent_version}'"
fi
;;
"deb")
info "Installing puppetlabs apt repo with dpkg..."
if test "x$installed_version" != "xuninstalled"; then
info "Version ${installed_version} detected..."
major=$(echo $installed_version | cut -d. -f1)
pkg="puppet${major}-release"
if echo $2 | grep $pkg; then
info "No collection upgrade detected"
else
info "Collection upgrade detected, replacing puppet${major}-release"
dpkg --purge "puppet${major}-release"
fi
fi
assert_unmodified_apt_config
dpkg -i --force-confmiss "$2"
run_cmd 'apt-get update -y'
if test "$version" = 'latest'; then
run_cmd "apt-get install -y puppet-agent"
else
if test "x$deb_codename" != "x"; then
run_cmd "apt-get install -y 'puppet-agent=${puppet_agent_version}-1${deb_codename}'"
else
run_cmd "apt-get install -y 'puppet-agent=${puppet_agent_version}'"
fi
fi
;;
"dmg" )
info "installing puppetlabs dmg with hdiutil and installer"
mountpoint="$(mktemp -d -t $(random_hexdump))"
/usr/bin/hdiutil attach "${download_filename?}" -nobrowse -readonly -mountpoint "${mountpoint?}"
/usr/sbin/installer -pkg ${mountpoint?}/puppet-agent-*-installer.pkg -target /
/usr/bin/hdiutil detach "${mountpoint?}"
rm -f $download_filename
;;
*)
critical "Unknown filetype: $1"
exit 1
;;
esac
if test $? -ne 0; then
critical "Installation failed"
exit 1
fi
}
info "Downloading Puppet $version for ${platform}..."
case $platform in
"SLES")
info "SLES platform! Lets get you an RPM..."
if [[ $PT__noop != true ]]; then
for key in "puppet" "puppet-20250406"; do
gpg_key="${tmp_dir}/RPM-GPG-KEY-${key}"
do_download "https://yum.puppet.com/RPM-GPG-KEY-${key}" "$gpg_key"
rpm --import "$gpg_key"
rm -f "$gpg_key"
done
fi
filetype="noarch.rpm"
filename="${collection}-release-sles-${platform_version}.noarch.rpm"
download_url="${yum_source}/${filename}"
;;
"el")
info "Red hat like platform! Lets get you an RPM..."
filetype="rpm"
filename="${collection}-release-el-${platform_version}.noarch.rpm"
download_url="${yum_source}/${filename}"
;;
"Amzn"|"Amazon Linux")
info "Amazon platform! Lets get you an RPM..."
filetype="rpm"
filename="${collection}-release-el-${platform_version}.noarch.rpm"
download_url="${yum_source}/${filename}"
;;
"Fedora")
info "Fedora platform! Lets get the RPM..."
filetype="rpm"
filename="${collection}-release-fedora-${platform_version}.noarch.rpm"
download_url="${yum_source}/${filename}"
;;
"Debian")
info "Debian platform! Lets get you a DEB..."
case $major_version in
"10") deb_codename="buster";;
"11") deb_codename="bullseye";;
esac
filetype="deb"
filename="${collection}-release-${deb_codename}.deb"
download_url="${apt_source}/${filename}"
;;
"Linuxmint"|"LinuxMint")
info "Mint platform! Lets get you a DEB..."
case $major_version in
"3") deb_codename="stretch";;
"4") deb_codename="buster";;
"5") deb_codename="bullseye";;
"21") deb_codename="jammy";;
"20") deb_codename="focal";;
"19") deb_codename="bionic";;
"18") deb_codename="xenial";;
"17") deb_codename="trusty";;
esac
filetype="deb"
filename="${collection}-release-${deb_codename}.deb"
download_url="${apt_source}/${filename}"
;;
"Ubuntu")
info "Ubuntu platform! Lets get you a DEB..."
case $platform_version in
"16.10") deb_codename="yakkety";;
"17.04") deb_codename="zesty";;
"18.04") deb_codename="bionic";;
"20.04") deb_codename="focal";;
"22.04") deb_codename="jammy";;
esac
filetype="deb"
filename="${collection}-release-${deb_codename}.deb"
download_url="${apt_source}/${filename}"
;;
"mac_os_x")
info "Mac platform! Lets get you a DMG..."
filetype="dmg"
if test "$version" = "latest"; then
filename="puppet-agent-latest.dmg"
else
filename="puppet-agent-${version}-1.osx${platform_version}.dmg"
fi
arch="x86_64"
if [[ $(uname -p) == "arm" ]]; then
arch="arm64"
fi
download_url="${mac_source}/mac/${collection}/${platform_version}/${arch}/${filename}"
;;
*)
critical "Sorry $platform is not supported yet!"
exit 1
;;
esac
if [[ -n "$PT_absolute_source" ]]; then
download_url=$PT_absolute_source
fi
if [[ $PT__noop != true ]]; then
download_filename="${tmp_dir}/${filename}"
do_download "$download_url" "$download_filename"
install_file $filetype "$download_filename"
if [[ $PT_stop_service = true ]]; then
/opt/puppetlabs/bin/puppet resource service puppet ensure=stopped enable=false
fi
#Cleanup
if test "x$tmp_dir" != "x"; then
rm -r "$tmp_dir"
fi
fi
}
if [[ $PT__noop != true ]]; then
if [[ $PT_cleanup == true ]]; then
info "Cleanup requested, removing ${collection}-release repository..."
case $platform in
SLES|el|Amzn|"Amazon Linux"|Fedora)
rpm -e --allmatches "${collection}"-release
;;
Debian|LinuxMint|Linuxmint|Ubuntu)
apt-get purge "${collection}"-release -y
;;
esac
fi
fi