#!/bin/bash # # Simple wrapper around VBoxManage. # # Parameters STORE="/var/cache/virtualbox/" BASENAME="`basename $0`" COMMAND="$1" VM="$2" shift 2 # Usage function usage { echo "usage: $BASENAME [vm]" exit 1 } # Execute commands inside a virtual machine function vbox_exec { local bin="$1" shift local command="guestcontrol" local options="execute --username vagrant --password vagrant --image $bin" options="$options --verbose --wait-exit --wait-stdout --wait-stderr --environment \"DISPLAY=:0\" -- $*" vbox_run $command $options } # VBoxManage wrapper function vbox_run { local command="$1" shift VBoxManage $command $VM $* } # Build options if [ ! -z "$VM" ]; then if [ "$COMMAND" == "up" ]; then vbox_run startvm elif [ "$COMMAND" == "down" ]; then vbox_run controlvm savestate elif [ "$COMMAND" == "halt" ]; then vbox_run controlvm poweroff elif [ "$COMMAND" == "upgrade" ]; then vbox_exec /home/vagrant/apps/hydra/hydractl upgrade clean elif [ "$COMMAND" == "zerofree" ]; then vbox_exec /usr/bin/sudo /usr/bin/apt-get install zerofree vbox_exec /usr/bin/sudo /usr/bin/apt-get clean vbox_exec /usr/bin/sudo /sbin/telinit 1 vbox_exec /bin/mount -o remount,ro / vbox_exec /usr/sbin/zerofree /dev/sda1 vbox_exec /sbin/halt for vdi in `ls $STORE/$VM/*.vdi`; do VBoxManage modifyhd --compact $vdi done elif [ "$COMMAND" == "exec" ]; then vbox_exec $* else usage fi elif [ "$COMMAND" == "status" ]; then vbox_run runningvms list else usage fi # Fix window titles xdotool search --name "$VM .* Oracle VM VirtualBox" set_window --name $VM