summaryrefslogtreecommitdiff
path: root/functions/verify_ptr.sh
blob: 8ce2f6c525496ca800e3478da735d996ca79ad8c (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
verify_ptr() {
  LABEL="$1"
  IP=$(curl -s -H "Authorization: Bearer $LINODE_API_TOKEN" https://api.linode.com/v4/linode/instances \
    | jq -r --arg LABEL "$LABEL" '.data[] | select(.label == $LABEL) | .ipv4[0]')
  LINODE_ID=$(curl -s -H "Authorization: Bearer $LINODE_API_TOKEN" https://api.linode.com/v4/linode/instances \
    | jq -r --arg LABEL "$LABEL" '.data[] | select(.label == $LABEL) | .id')

  if [[ -z "$IP" || -z "$LINODE_ID" ]]; then
    echo "❌ Could not retrieve IP or Linode ID for label '$LABEL'"
    return 1
  fi

  echo "Re-attempting rDNS update for $LABEL ($IP)..."
  PTR_NAME="${LABEL}.doinkle.pro"
  RDNS_PAYLOAD=$(cat <<EOF
{
  "rdns": "$PTR_NAME"
}
EOF
)

  RESPONSE=$(curl -s -w "\nHTTP Status: %{http_code}\n" -X PUT \
    -H "Authorization: Bearer $LINODE_API_TOKEN" \
    -H "Content-Type: application/json" \
    -d "$RDNS_PAYLOAD" \
    "https://api.linode.com/v4/linode/instances/$LINODE_ID/ips/$IP")

  echo "$RESPONSE"
}