-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdebian.sh
executable file
·52 lines (50 loc) · 1.64 KB
/
debian.sh
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
49
50
51
52
#!/bin/bash
# Gérer une VM Debian depuis son terminal en une commande.
# Prérequis : VirtualBox / VBoxManage / Créer une VM / Rediriger le port 2222 vers le port SSH
# Pour la version temporaire : Docker / Docker-Compose
# Commandes disponibles : stop / list <snaps/vms> / rollback / restore <snap> / delete / temp
VM=Debian
SSH_PASSWORD=''
snapshot_folder=''
if [[ $1 == "stop" ]]; then
VBoxManage controlvm "$VM" poweroff --type headless
elif [[ $1 == "snap" ]]; then
if [ -z $2 ]; then
echo "Provide a name for your snapshot ! ($VM snap <name>)"
exit
fi
name=$2
VBoxManage snapshot $VM take $name
elif [[ $1 == "list" ]]; then
if [[ $2 == "snaps" ]]; then
VBoxManage snapshot $VM list
elif [[ $2 == "vms" ]]; then
VBoxManage list vms
fi
elif [[ $1 == "rollback" ]]; then
VBoxManage controlvm "$VM" poweroff --type headless
VBoxManage snapshot $VM restorecurrent
elif [[ $1 == "restore" ]]; then
if [ -z $2 ]; then
echo "Provide a name for your snapshot ! ($VM restore <name>)"
exit
fi
name=$2
VBoxManage controlvm "$VM" poweroff --type headless
VBoxManage snapshot $VM restore $name
elif [[ $1 == "delete" ]]; then
if [ -z $2 ]; then
echo "Provide a name for your snapshot ! ($VM delete <name>)"
exit
fi
name=$2
VBoxManage snapshot $VM delete $name
elif [[ $1 == "temp" ]]; then
sudo docker run -v $HOME:/root -it debian bash
else
RUNNING=$(VBoxManage list runningvms | awk '{print $1}' )
if [ -z $RUNNING ]; then
VBoxManage startvm "$VM" --type headless
fi
sshpass -p $SSH_PASSWORD ssh -A -p 2222 [email protected]
fi