Skip to content

Instantly share code, notes, and snippets.

@Knight1
Last active October 18, 2020 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Knight1/e66dacb248ee671d274fd91ee06b15bb to your computer and use it in GitHub Desktop.
Save Knight1/e66dacb248ee671d274fd91ee06b15bb to your computer and use it in GitHub Desktop.
Hetzner Cloud create temporary Windows Servers
#!/bin/bash
ID=`hcloud server list | tail -1 | grep Windoof | awk '{print $1;}'`
CONTEXT=`hcloud context active`
if [ "$CONTEXT" != "testing" ]; then
echo "[CRIT] Aborting, wrong context"
exit
fi
#stop, force stop, snapshot, delete
delete() {
hcloud server shutdown $ID
if [ "$?" != "0" ]; then
sleep 60
hcloud server poweroff $ID
fi
make_snaphot
hcloud server delete $ID
}
#Create snapshot
make_snapshot() {
hcloud server create-image $ID --type snapshot --description `date '+Windoof-%Y-%m-%d_%H-%M'` || echo "[CRIT] Snapshot error" | exit 1
}
#create from snapshot
create() {
if [ "$2" == "latest" ]; then
hcloud image list | grep snapshot | grep Windoof
read -n 1 -p "Select Snapshot ID:" SNAPID
else
SNAPID=`hcloud image list | grep snapshot | grep Windoof | tail -1 | awk '{print $1;}'`
fi
if [ "$SNAPID" == "" ]; then
exit 1
fi
hcloud server create --datacenter 2 --image $SNAPID --name Windoof --type 3
}
case "$1" in
create)
create
;;
delete)
delete
;;
snapshot)
make_snapshot
;;
*)
echo "Nothing selected"
exit
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment