some_scripts/revert-vbox

27 lines
605 B
Bash
Executable File

#!/bin/bash
if [[ -z $1 ]]; then
echo 'all or vm-name'
fi
typeset -a machines
if [[ $1 = 'all' ]]; then
machines=$(vboxmanage list runningvms | awk '{print $1}' | sed 's/"//g' )
else
machines=("$@")
fi
for i in ${machines[@]}; do
snapshot=$(vboxmanage snapshot $i list | sed -n 1p | awk '{print $2}')
echo -e " \033[0;36m \n vm ${i} snapshot ${snapshot} \033[0m "
if [[ $2 = 'stop' ]]; then
vboxmanage controlvm $i poweroff
sleep 1
else
vboxmanage controlvm $i poweroff
sleep 2
vboxmanage snapshot $i restore "$shapshot"
sleep 2
vboxmanage startvm $i
fi
done