-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathself-destruct.sh
More file actions
executable file
·48 lines (39 loc) · 1.31 KB
/
Copy pathself-destruct.sh
File metadata and controls
executable file
·48 lines (39 loc) · 1.31 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# self-destruct script for easy-vpn virtual machine
# ==============================================================================
# this script will be uploaded and started in the background, on the virtual
# machine that was created by running easy-vpn with the "up" command
# check arguments
if [[ $# -ne 4 ]]; then
echo "usage: ./self-destruct.sh <API-Provider> <API-Key> <VM-Id> <Uptime>"
exit 1
fi
PROVIDER=$1
API_KEY=$2
VM_ID=$3
UPTIME=$4
echo "Called ./self-destruct.sh ${PROVIDER} ${API_KEY} ${VM_ID} ${UPTIME}"
function destroyVM {
if [[ $PROVIDER == "digitalocean" ]]; then
echo "curl -X DELETE -i -H \"Authorization: Bearer ${API_KEY}\" \"https://api.digitalocean.com/v2/droplets/${VM_ID}\""
curl -X DELETE -i -H "Authorization: Bearer ${API_KEY}" "https://api.digitalocean.com/v2/droplets/${VM_ID}"
exit $?
elif [[ $PROVIDER == "vultr" ]]; then
echo "curl -X POST -i -d \"SUBID=${VM_ID}\" \"https://api.vultr.com/v1/server/destroy?api_key=${API_KEY}\""
curl -X POST -i -d "SUBID=${VM_ID}" "https://api.vultr.com/v1/server/destroy?api_key=${API_KEY}"
exit $?
else
echo "Unknown provider!"
exit 5
fi
}
STARTTIME=`date +%s`
while true; do
CURRENTTIME=`date +%s`
DEADLINE=$(( STARTTIME + UPTIME ))
if [[ $CURRENTTIME -gt $DEADLINE ]]; then
destroyVM
fi
sleep 5
done
exit 0