dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 16642efe0d574c97bd66d92b5d130b3db8e53a54
parent ac537d1dfcba3d0a3d30bc859009b2e7513a661d
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Sun, 17 May 2020 13:58:42 +0200

vbox: suspend also resumes from savestate if needed

Former-commit-id: 842d5e126569555a20cf4636c698c640b9e9a229
Diffstat:
Mscripts/vbox | 25++++++++++++++++++++++---
Mshell/zsh-completions-mine/_vbox | 3++-
2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/scripts/vbox b/scripts/vbox @@ -18,9 +18,24 @@ pause() { [ $# -eq 1 ] || die "Only one argument: VM name" VBoxManage controlvm "$1" pause } +suspend() { + [ $# -eq 1 ] || die "Only one argument: VM name" + VBoxManage controlvm "$1" savestate +} resume() { [ $# -eq 1 ] || die "Only one argument: VM name" - VBoxManage controlvm "$1" resume + vminfo="$(VBoxManage showvminfo "$1")" + if [ "$(awk '/^State/ { print $2 }' <<< "$vminfo")" = "saved" ]; then + snapshots="$(awk '/^Snapshot folder/ { print $3 }' <<< "$vminfo")" + snapfile="$(find "$snapshots" -name "*.sav" -exec stat -c "%y %n" {} + | sort -r | head -n1 | cut -d " " -f 4-)" + + [ -n "$snapfile" ] \ + && echo "VM suspended, resuming from saved state..." \ + && VBoxManage startvm "$1" --type headless + else + echo "VM paused, resuming..." + VBoxManage controlvm "$1" resume + fi } ls() { VBoxManage list vms @@ -73,7 +88,7 @@ while (( "$#" )); do echo "Usage:" echo "start vmname start a VM" echo "stop vmname stop a VM" - echo "ls ls VMs" + echo "list, ls ls VMs" echo "running list running VMs" echo "share /local/path vmname /mount/point share a local folder" echo "unshare /local/path unshare a local folder" @@ -112,7 +127,7 @@ case "$1" in shift; stop "$@"; ;; - "ls") + "ls"|"list") ls; ;; "running") @@ -146,6 +161,10 @@ case "$1" in shift; pause "$@"; ;; + "suspend") + shift; + suspend "$@"; + ;; "resume") shift; resume "$@"; diff --git a/shell/zsh-completions-mine/_vbox b/shell/zsh-completions-mine/_vbox @@ -10,6 +10,7 @@ _vbox() { 'start:start a VM' 'stop:stop a VM' 'pause:pause a VM' + 'suspend:suspend a VM' 'resume:resume a paused VM' 'ls:list known VMs' 'info:get information about a VM' @@ -41,7 +42,7 @@ _vbox() { ':hostpath:_files -/' \ :machine:_vboxmachines ;; - start|stop|status|info|shared|pause|resume) + start|stop|status|info|shared|pause|suspend|resume) _arguments \ :machine:_vboxmachines ;;