#!/usr/bin/env bash # Bash script template from https://betterdev.blog/minimal-safe-bash-script-template/ set -Eeuo pipefail script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P) usage() { cat <&2 -e "${1-}" } die() { local msg=$1 local code=${2-1} # default exit status 1 msg "$msg" exit "$code" } parse_params() { # default values of variables set from params INSTANCE_SIZE='s-1vcpu-1gb' IMAGE='debian-11-x64' while :; do case "${1-}" in -h | --help) usage ;; -v | --verbose) set -x ;; -l | --large) INSTANCE_SIZE='s-4vcpu-8gb' ;; -s | --size) INSTANCE_SIZE="${2-}" shift ;; -i | --image) IMAGE="${2-}" shift ;; -?*) die "Unknown option: $1" ;; *) break ;; esac shift done args=("$@") return 0 } parse_params "$@" if ! command -v doctl &> /dev/null then die "Error! Please make sure that 'doctl' is installed in your path." fi msg "Creating a droplet using image $IMAGE of size $INSTANCE_SIZE." msg "This command will finish once the droplet is created." doctl compute droplet create --region fra1 --ssh-keys "a8:8b:cd:2a:67:80:33:1d:84:52:c7:7b:0a:d6:49:63" --image $IMAGE --wait --size $INSTANCE_SIZE $(date +"instance-%m-%d-%Y-%H-%M")