commit c78547399a5906e064caa5ebfca115be09659c96
parent 7d9ffe51c2a35645b4858cff94cea69456d9efbd
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Fri, 15 May 2020 13:06:21 +0200
vbox: extra commands
Former-commit-id: bcf2c1a3bc03f964d299c53e11fcbc35207fcbe1
Diffstat:
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/scripts/vbox b/scripts/vbox
@@ -14,6 +14,14 @@ stop() {
VBoxManage controlvm "$1" acpipowerbutton
}
+pause() {
+ [ $# -eq 1 ] || die "Only one argument: VM name"
+ VBoxManage controlvm "$1" pause
+}
+resume() {
+ [ $# -eq 1 ] || die "Only one argument: VM name"
+ VBoxManage controlvm "$1" resume
+}
ls() {
VBoxManage list vms
}
@@ -26,11 +34,19 @@ info() {
VBoxManage showvminfo "$1"
}
+status() {
+ VBoxManage showvminfo "$1" | awk -F' +' '/^State/ { print $2 }'
+}
+
# share /folder/path vmname /mount/point
share() {
[ $# -eq 3 ] || die "Not enough arguments"
[ -d $1 ] || die "$1 is not a directory or does not exist"
VBoxManage sharedfolder add "$2" --name "$(basename $(realpath "$1"))" --hostpath "$(realpath "$1")" --automount --auto-mount-point "$3"
+ if [ $? -ne 0 ]; then
+ echo "Could not add shared folder, machine is probably running."
+ echo "Stop the machine to add a permanent folder, or use sharetmp to add a transient folder."
+ fi
}
unshare() {
@@ -63,6 +79,10 @@ while (( "$#" )); do
echo "unshare /local/path unshare a local folder"
echo "sharetmp /local/path vmname /mount/point temporarily share a local folder"
echo "shared list shared folders"
+ echo "pause pause a running VM"
+ echo "resume resume a paused VM"
+ echo "info get information about a VM"
+ echo "status print a VM's status"
exit 0
;;
--) # end arg parsing
@@ -118,6 +138,18 @@ case "$1" in
shift;
info "$@";
;;
+ "status")
+ shift;
+ status "$@";
+ ;;
+ "pause")
+ shift;
+ pause "$@";
+ ;;
+ "resume")
+ shift;
+ resume "$@";
+ ;;
*)
die "Unsupported command $1";
;;
diff --git a/shell/zsh-completions-mine/_vbox b/shell/zsh-completions-mine/_vbox
@@ -9,8 +9,11 @@ _vbox() {
arguments=(
'start:start a VM'
'stop:stop a VM'
+ 'pause:pause a VM'
+ 'resume:resume a paused VM'
'ls:list known VMs'
'info:get information about a VM'
+ 'status:get status of a VM'
'running:list currently running VMs'
'share:share a local folder'
'unshare:unshare a local folder'
@@ -38,7 +41,7 @@ _vbox() {
':hostpath:_files -/' \
:machine:_vboxmachines
;;
- start|stop|info|shared)
+ start|stop|status|info|shared|pause|resume)
_arguments \
:machine:_vboxmachines
;;