-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbasic_script.sh
More file actions
executable file
·31 lines (25 loc) · 876 Bytes
/
basic_script.sh
File metadata and controls
executable file
·31 lines (25 loc) · 876 Bytes
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
30
31
#!/usr/bin/env bash
SCRIPTPATH=$( dirname $(realpath "$0") )
vm_name=${vm_name-wireguard-vps}
zone=${zone-nl-ams-1}
type=${type-DEV1-S}
image=debian_bookworm
script="${SCRIPTPATH}/cloud-init/wireguard_pi-hole_unbound.sh"
# prerequisites
for bin in scw jq; do
if ! type -P $bin &>/dev/null; then
echo -e "\nERROR: Prerequisite [${bin}] not found. Abort.\n"; exit 1
fi
done
# create instance
vm_id=$( scw instance server create --output=json ip=new \
type=${type} zone=${zone} image=${image} \
name=${vm_name} cloud-init=@${script} \
| jq -r '.id' )
# Success?
[ -n "$vm_id" ] || exit 1
# attach console
scw instance server console ${vm_id} zone=${zone}
# once console is detached
echo -e "\nCLI to delete VM $vm_name:\n"
echo -e "scw instance server terminate with-ip=true with-block=true zone=$zone $vm_id\n"