summaryrefslogtreecommitdiff
path: root/genesisctl.sh
blob: 21fdf7df7de70a4b4171144ced16a9077741bb01 (plain)
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
#!/usr/bin/env bash
# genesisctl - Genesis VPS Provisioning and Reboot CLI
# Usage:
#   genesisctl provision <label> <region> <type> <image> [root_pass]
#   genesisctl reboot <linode-id>
#   genesisctl list regions|types|images
#   genesisctl ultra <label> [root_pass]
#   genesisctl safe <label> [root_pass]
#   genesisctl micro <label> [root_pass]
#   genesisctl mastodon <label> [root_pass]
#   genesisctl destroy <label>

LINODE_API_TOKEN="f8b1552bf1f2f791e16fed0c1474d56014330de1c33810527523e44a7389cb6f"

# Package presets
PACKAGE_ULTRA_REGION="us-east"
PACKAGE_ULTRA_TYPE="g6-dedicated-4"
PACKAGE_ULTRA_IMAGE="linode/ubuntu22.04"

PACKAGE_SAFE_REGION="us-east"
PACKAGE_SAFE_TYPE="g6-standard-2"
PACKAGE_SAFE_IMAGE="linode/ubuntu22.04"

PACKAGE_MICRO_REGION="us-east"
PACKAGE_MICRO_TYPE="g6-nanode-1"
PACKAGE_MICRO_IMAGE="linode/ubuntu22.04"

PACKAGE_MASTODON_REGION="us-east"
PACKAGE_MASTODON_TYPE="g6-standard-4"
PACKAGE_MASTODON_IMAGE="linode/ubuntu22.04"

for f in functions/*.sh; do source "$f"; done

# Helper for DNS pre-propagation check (used after provisioning)
await_dns_propagation() {
  HOSTNAME="$1"
  EXPECTED_IP="$2"

  echo "⏳ Waiting for DNS A record to propagate for $HOSTNAME to $EXPECTED_IP..."
  for i in {1..10}; do
    ACTUAL_IP=$(dig +short "$HOSTNAME")
    if [[ "$ACTUAL_IP" == "$EXPECTED_IP" ]]; then
      echo "✅ DNS A record found: $HOSTNAME → $EXPECTED_IP"
      return 0
    fi
    echo "...still waiting ($i/10)..."
    sleep 10
  done
  echo "❌ DNS A record for $HOSTNAME did not propagate in time. Skipping rDNS setup."
  return 1
}

case "$1" in
  provision)
    provision_vps "$2" "$3" "$4" "$5" "$6"
    ;;
  reboot)
    reboot_vps "$2"
    ;;
  destroy)
    destroy_vps_by_label "$2"
    ;;
  safe)
    provision_vps "$2" "$PACKAGE_SAFE_REGION" "$PACKAGE_SAFE_TYPE" "$PACKAGE_SAFE_IMAGE" "$3"
    ;;
  ultra)
    provision_vps "$2" "$PACKAGE_ULTRA_REGION" "$PACKAGE_ULTRA_TYPE" "$PACKAGE_ULTRA_IMAGE" "$3"
    ;;
  micro)
    provision_vps "$2" "$PACKAGE_MICRO_REGION" "$PACKAGE_MICRO_TYPE" "$PACKAGE_MICRO_IMAGE" "$3"
    ;;
  mastodon)
    provision_vps "$2" "$PACKAGE_MASTODON_REGION" "$PACKAGE_MASTODON_TYPE" "$PACKAGE_MASTODON_IMAGE" "$3"
    ;;
  backup)
    enable_backups_by_label "$2"
    ;;
  disable-backup)
    disable_backups_by_label "$2"
    ;;
  status)
    status_vps "$2"
    ;;
  listvps)
    list_all_vps
    ;;
  disable)
    disable_ip "$2"
    ;;
  resize)
    resize_vps "$2" "$3"
    ;;
  safe-create)
    safe_create_dataset "$2" "$3"
    ;;
  verify_ptr)
    verify_ptr "$2"
    ;;
  *)
    echo "Usage: $0 <command> [...]"
    echo "Available commands: provision, reboot, destroy, safe, ultra, micro, mastodon"
    exit 1
    ;;
esac