summaryrefslogtreecommitdiff
path: root/functions/resize_vps.sh
blob: c06ea91c07c82d3f876e312f7a61846ce7b1c970 (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
resize_vps() {
  LABEL="$1"
  NEW_TYPE="$2"

  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 "❌ No Linode found with label '$LABEL'"
    exit 1
  fi

  echo "Resizing Linode '$LABEL' to type '$NEW_TYPE'..."

  HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $LINODE_API_TOKEN" \
    -d '{"type": "'"$NEW_TYPE"'"}' \
    https://api.linode.com/v4/linode/instances/$LINODE_ID/resize)

  if [[ "$HTTP_STATUS" == "200" ]]; then
    echo "✅ Linode $LABEL resized to $NEW_TYPE."
  else
    echo "❌ Failed to resize VPS. HTTP status: $HTTP_STATUS"
  fi
}