summaryrefslogtreecommitdiffstats
path: root/bin/terminate
blob: b2e30b73bc407537b00d3e9aff4753ee12db583f (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
#!/usr/bin/env bash
set -eu
set -o pipefail

script_path="$(realpath "$(dirname "$0")")"
secrets_bin="${script_path}/secrets"

case "$1" in
tozt | algo | mail | mail2)
    "$secrets_bin" open
    trap '"$secrets_bin" close' EXIT
    case "$1" in
    tozt)
        hostname=tozt.net
        ;;
    algo)
        hostname=algo.tozt.net
        ;;
    mail)
        hostname=mail.tozt.net
        ;;
    mail2)
        hostname=mail2.tozt.net
        ;;
    esac
    doctl -t "$(cat /mnt/digitalocean)" compute droplet delete "$hostname"
    ;;
*)
    echo "unknown host $1" >&2
    exit 1
    ;;
esac