-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·69 lines (57 loc) · 1.83 KB
/
bootstrap.sh
File metadata and controls
executable file
·69 lines (57 loc) · 1.83 KB
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
#!/usr/bin/env bash
set -eu
# Script principle:
# 1) Idempotent. It should be possible to run this script multiple times.
function log {
echo "[$(date --rfc-3339=ns)] ${1}"
}
function install {
dpkg -s "$1" && return 0
for attempt in {1..5}; do
if ! apt install -y "$1"; then
echo "Could not install ${1} after attempt ${attempt}"
apt update -y --fix-missing
sleep 2
else
break
fi
done
}
function initialise_securepuppet {
SP_DIR="/etc/securepuppet/modules/secure/manifests"
if [ ! -d "$SP_DIR" ]; then
log "Creating secure puppet module directory at: $SP_DIR"
mkdir -p "$SP_DIR"
fi
SP_MFST="${SP_DIR}/init.pp"
if ! grep 'class secure' "$SP_MFST" 1> /dev/null 2> /dev/null; then
log "Creating secure puppet manifest file: $SP_MFST"
echo 'class secure {}' > "$SP_MFST"
fi
chmod -R 600 /etc/securepuppet
}
if [ -f "/root/puppet/.git/HEAD" ]; then
log "/root/puppet/ already exists, not re-cloning"
else
log 'Updating apt repos'
apt update -y
log 'Upgrading apt packages'
# https://askubuntu.com/a/1431746
NEEDRESTART_MODE=a apt upgrade -y
log 'Installing git and puppet'
install git
install puppet
log 'Installing puppet modules'
puppet module install puppetlabs-cron_core
puppet module install puppetlabs-sshkeys_core
puppet module install puppetlabs-stdlib
puppet module install puppetlabs-apt
log 'Cloning puppet confs repo to /root/puppet'
/usr/bin/git clone --depth=1 https://github.com/AWooldrige/puppet.git /root/puppet
log 'Installing puppet modules'
initialise_securepuppet
fi
log 'Complete, now:'
log ' 1) Optional: populate /etc/securepuppet'
log ' 2) Optional: modify local /root/puppet'
log ' 3) cd /root/puppet && ./apply.sh'