Created
April 13, 2023 02:11
-
-
Save franzwong/8086a2c19b86b0b90adde995667a93cd to your computer and use it in GitHub Desktop.
Rebuild DigitalOcean droplet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function rebuild_droplet() { | |
local -r token=${1} | |
if [[ ${#} -ge 2 ]]; then | |
local -r image_slug=${2} | |
else | |
local -r image_slug=ubuntu-22-04-x64 | |
fi | |
# Assume we only have 1 droplet | |
droplet_id=$(curl -X GET \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer ${token}" \ | |
"https://api.digitalocean.com/v2/droplets?page=1&per_page=1" | jq '.droplets[0].id') | |
curl -X POST \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer ${token}" \ | |
-d '{"type":"rebuild","image":"'"${image_slug}"'"}' \ | |
"https://api.digitalocean.com/v2/droplets/${droplet_id}/actions" | |
} | |
rebuild_droplet "${@} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment