summaryrefslogtreecommitdiff
path: root/vps/functions/destroy_vps_by_label.sh
diff options
context:
space:
mode:
Diffstat (limited to 'vps/functions/destroy_vps_by_label.sh')
-rwxr-xr-xvps/functions/destroy_vps_by_label.sh28
1 files changed, 28 insertions, 0 deletions
diff --git a/vps/functions/destroy_vps_by_label.sh b/vps/functions/destroy_vps_by_label.sh
new file mode 100755
index 0000000..09d807e
--- /dev/null
+++ b/vps/functions/destroy_vps_by_label.sh
@@ -0,0 +1,28 @@
+destroy_vps_by_label() {
+ LABEL="$1"
+ echo "Looking for VPS with label '$LABEL'..."
+ 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 "$LINODE_ID" ]; then
+ echo "Error: No Linode found with label '$LABEL'"
+ exit 1
+ fi
+
+ read -rp "Are you sure you want to destroy VPS '$LABEL' (ID: $LINODE_ID)? [y/N] " confirm
+ if [[ "$confirm" =~ ^[Yy]$ ]]; then
+ echo "Destroying Linode with ID $LINODE_ID (label: $LABEL)..."
+ HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE \
+ https://api.linode.com/v4/linode/instances/$LINODE_ID \
+ -H "Authorization: Bearer $LINODE_API_TOKEN")
+
+ if [[ "$HTTP_STATUS" == "204" ]]; then
+ echo "✅ Linode $LABEL (ID $LINODE_ID) has been destroyed."
+ else
+ echo "❌ Failed to destroy VPS. HTTP status: $HTTP_STATUS"
+ fi
+ else
+ echo "Cancelled. VPS '$LABEL' not destroyed."
+ fi
+}