blob: 3cca3a4f332bc417ce5eae74673c446b2a60674f (
plain) (
blame)
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
|
#!/usr/bin/env bash
set -eu
set -o pipefail
echo "Creating droplet for mail..."
data=$(doctl \
-t "$(cat /mnt/digitalocean)" \
compute droplet create \
mail \
--image debian-9-x64 \
--region nyc3 \
--size s-1vcpu-1gb \
--ssh-keys 23160354 \
--volumes ef47eab9-d497-11e8-a1fd-0a58ac146edf \
--format ID,PublicIPv4 \
--no-header \
--wait)
id=$(echo "$data" | awk '{print $1}')
ip=$(echo "$data" | awk '{print $2}')
echo "Created droplet with id $id and ip $ip"
echo "Creating DNS entry for $ip..."
record_id=$(doctl \
-t "$(cat /mnt/digitalocean)" \
compute domain records list \
tozt.net \
--format Name,Type,ID \
--no-header \
| grep '^newsmtp2 \+A ' \
| awk '{print $3}'
)
doctl \
-t "$(cat /mnt/digitalocean)" \
compute domain records update \
tozt.net \
--record-id "$record_id" \
--record-type A \
--record-name newsmtp2 \
--record-data "$ip" \
--record-ttl 60
echo "Done creating DNS entry"
echo "Provisioning droplet..."
conf_location="/usr/local/share/puppet-tozt"
conf_repo="git://github.com/doy/puppet-tozt"
remote() {
# shellcheck disable=SC2029
ssh root@"$ip" "$@"
}
apt() {
remote env DEBIAN_FRONTEND=noninteractive apt-get -yq "$@"
}
ensure_conf_exists() {
if remote test -d "$conf_location"; then
remote "cd '$conf_location' && git pull"
else
remote "mkdir -p '$conf_location'"
remote "cd '$conf_location' && git clone '$conf_repo' ."
fi
remote "cd '$conf_location' && git submodule update --init --recursive"
}
while ! remote true; do
sleep 5
done
apt update
apt upgrade
apt install git puppet
ensure_conf_exists
scp -r /mnt/puppet/mail/ root@"$ip":/usr/local/share/puppet-tozt/mail/secret/files
remote "cd '$conf_location' && puppet apply --modulepath=./mail -e 'include mail'"
echo "Done"
|