summaryrefslogtreecommitdiffstats
path: root/bin/helpers/launch-tozt
blob: 0d93aac6baea4936f73e221e3fa04dd72e983f1f (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
#!/usr/bin/env bash
set -eu
set -o pipefail

echo "Creating droplet for tozt..."
id=$(doctl \
    -t "$(cat /mnt/digitalocean)" \
    compute droplet create \
    tozt \
    --image debian-9-x64 \
    --region nyc3 \
    --size s-1vcpu-1gb \
    --ssh-keys 23160354 \
    --volumes 4206344e-cf4f-11e8-a5a7-0a58ac1465db \
    --format ID \
    --no-header \
    --wait)
echo "Created droplet with id $id"

echo "Assigning floating ip to tozt..."
# XXX this returns an error for some reason, but actually succeeds:
# Error: could not assign IP to droplet: json: cannot unmarshal number
# 2328181259 into Go struct field Action.resource_id of type int
doctl \
    -t "$(cat /mnt/digitalocean)" \
    compute floating-ip-action assign \
    138.197.58.11 \
    "$id" || true
echo "Done assigning floating ip"

echo "Provisioning droplet..."

host="${1:-tozt.net}"
conf_location="/usr/local/share/puppet-tozt"
conf_repo="git://github.com/doy/puppet-tozt"

remote() {
    # shellcheck disable=SC2029
    ssh root@"$host" "$@"
}

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

if remote test ! -e /usr/bin/pacman; then
    remote apt-get -y update
    remote apt-get -y install git
    ensure_conf_exists
    remote "cd '$conf_location/digitalocean-debian-to-arch' && bash install.sh --i_understand_that_this_droplet_will_be_completely_wiped --extra_packages 'puppet git ruby-shadow'"
    sleep 30
    while ! remote true; do
        sleep 30
    done
fi

ensure_conf_exists
scp -r /mnt/puppet/tozt/ root@"$host":/usr/local/share/puppet-tozt/modules/secret/files
remote "cd '$conf_location' && puppet apply --modulepath=./modules manifests"

echo "Done"