aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2015-08-20 22:50:18 -0300
committerSilvio Rhatto <rhatto@riseup.net>2015-08-20 22:50:18 -0300
commitc7880e6581dd80346dcbe9fdb40965360b8fcba8 (patch)
tree5d5790c8b6f880ba30fa3a4d6a867872011c0e1d
parent8ab4037e85e18e0cdd288040e2aec1ba5db2dee2 (diff)
downloadvbox-c7880e6581dd80346dcbe9fdb40965360b8fcba8.tar.gz
vbox-c7880e6581dd80346dcbe9fdb40965360b8fcba8.tar.bz2
Refactor and exec action
-rwxr-xr-xvbox64
1 files changed, 34 insertions, 30 deletions
diff --git a/vbox b/vbox
index 6b6935a..1a82600 100755
--- a/vbox
+++ b/vbox
@@ -14,48 +14,52 @@ function usage {
exit 1
}
-# TODO
# Execute commands inside a virtual machine
-#function vbox_exec {
-#}
+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 -- $*"
+
+ 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
- OPTIONS=""
- COMMAND="startvm"
+ vbox_run startvm
elif [ "$COMMAND" == "down" ]; then
- OPTIONS="savestate"
- COMMAND="controlvm"
+ vbox_run controlvm savestate
elif [ "$COMMAND" == "halt" ]; then
- OPTIONS="poweroff"
- COMMAND="controlvm"
+ vbox_run controlvm poweroff
elif [ "$COMMAND" == "upgrade" ]; then
- OPTIONS="execute --username vagrant --password vagrant --image /home/vagrant/apps/hydra/hydractl"
- OPTIONS="$OPTIONS --verbose --wait-exit --wait-stdout --wait-stderr -- upgrade clean"
- COMMAND="guestcontrol"
- # TODO
- #elif [ "$COMMAND" == "zerofree" ]; then
- # vbox_exec $VM apt-get install zerofree
- # vbox_exec $VM apt-get clean
- # vbox_exec $VM telinit 1
- # vbox_exec $VM mount -o remount,ro /
- # vbox_exec $VM zerofree /dev/sda1
- # vbox_exec $VM halt
- # VBoxManage modifyhd --compact /var/cache/virtualbox/$box/$box.vdi
- # exit
- #elif [ "$COMMAND" == "zerofree" ]; then
- # shift
- # vbox_exec $*
+ 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
+ VBoxManage modifyhd --compact /var/cache/virtualbox/$box/$box.vdi
+ elif [ "$COMMAND" == "exec" ]; then
+ shift 2
+ vbox_run $*
else
usage
fi
elif [ "$COMMAND" == "status" ]; then
- OPTIONS="runningvms"
- COMMAND="list"
+ vbox_run runningvms list
else
usage
fi
-
-# Dispatch
-VBoxManage $COMMAND $VM $OPTIONS