This repository has been archived by the owner on Jul 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_puppet.sh
106 lines (92 loc) · 1.94 KB
/
install_puppet.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
#!/bin/bash
set -euo pipefail
set -o nounset
if [ -d "$1" ]
then
readonly CTX="$1"
else
readonly CTX=$(dirname `readlink -f $0`)
fi
# Installs puppet, git, etc
install_deps()
{
if $(which apt)
then
apt-get install -y git puppet gnupg2 ruby-dev build-essential
else
{
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-7.noarch.rpm
} || {
echo '[i] Already added rpm'
}
yum groupinstall -y "Development tools"
yum install -y git puppet gpg ruby-devel
fi
}
# Utilities related to puppet
install_gems()
{
if ! $(gem list -i gpgme)
then
echo '[i] Installing gems'
# @todo ? should be moved to Gemfile?
gem install r10k librarian-puppet puppet-lint hiera-eyaml hiera-eyaml-gpg ruby_gpg gpgme
fi
}
# Some quick validation before running the script
preinstall()
{
if [[ `id -u` -ne 0 ]]
then
echo '[!] You need to run this as sudo!'
return 1
fi
if [[ ! -f "${CTX}/README.md" ]]
then
echo '[!] Script must be in context of the repo it came with'
return 2
fi
}
# Configuring puppet after installation
configure()
{
if [ "$CTX" != '/etc/puppet' ]
then
# Copy and overwrite
cp -rf $CTX/* /etc/puppet
cp -rf $CTX/.git /etc/puppet/.git
fi
# @todo cleanup old environment
cd /etc/puppet
# If not .git directory ... is not a repo
if [ ! -d .git ]
then
echo '[!] Does not appear to be a git repo'
return 3
fi
# If there is a master branch rename to production
{
git branch | grep production
} || {
echo '[i] Creating production branch off master'
git branch production
}
}
# Final touches
postinstall()
{
# Force set a path to ensure r10k can run
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/sbin:/home/vagrant/bin
cd /etc/puppet
r10k deploy environment -p
}
main()
{
echo "[i] Installing puppet, running from ${CTX} ..."
preinstall
install_deps
install_gems
configure
postinstall
}
main