forked from puppetlabs/install-puppet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.rb
73 lines (63 loc) · 2.3 KB
/
install.rb
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
# This script generates an install.sh file which can be used to install
# puppet-agent on supported FOSS POSIX platforms.
#
# The script leverages tasks from the puppet_agent and facts modules, and
# attempts to change as few things as possible.
# we just need the variables from here
facts_script = `sed '/munge_name "$family"/q' < modules/facts/tasks/bash.sh`
install_script = File.read('modules/puppet_agent/tasks/install_shell.sh')
.sub('[ -f "$PT__installdir/facts/tasks/bash.sh" ]', 'true')
.sub('$(bash $PT__installdir/facts/tasks/bash.sh "platform")', '$ID')
.sub('$(bash $PT__installdir/facts/tasks/bash.sh "release")', '$full')
File.write('install.sh', <<-SH)
#!/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
{
#{facts_script}
#{install_script}
}
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
SH