commit efe94320166ea75f6ca8f0a731ba5be628e6ee9f
parent 0b9836738f6ddf56ac7af29361c4674c14fe6c13
Author: Alex Balgavy <alex@balgavy.eu>
Date: Sat, 13 Mar 2021 18:54:35 +0100
vbox: moved out to separate repo
Diffstat:
2 files changed, 0 insertions(+), 238 deletions(-)
diff --git a/scripts/vbox b/scripts/vbox
@@ -1,186 +0,0 @@
-#!/usr/bin/env bash
-die() {
- echo "$1" >&2
- exit 1
-}
-
-command -v gstat &>/dev/null && statcmd="gstat"
-start() {
- [ $# -eq 1 ] || die "Only one argument: VM name"
- VBoxManage startvm "$1" --type headless
-}
-
-stop() {
- [ $# -eq 1 ] || die "Only one argument: VM name"
- VBoxManage controlvm "$1" acpipowerbutton
-}
-
-open() {
- [ $# -eq 1 ] || die "Only one argument: VM name"
- VBoxManage startvm "$1" --type separate
-}
-
-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"
- 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 "${statcmd:-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
-}
-
-running() {
- VBoxManage list runningvms
-}
-
-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() {
- [ $# -eq 2 ] || die "Not enough arguments"
- [ -d $1 ] || die "$1 is not a directory or does not exist"
- VBoxManage sharedfolder remove "$2" --name "$(basename $(realpath "$1"))" --transient
-}
-
-sharetmp() {
- [ $# -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" --transient
-}
-
-shared() {
- [ $# -eq 1 ] || die "Not enough arguments"
- VBoxManage showvminfo "$1" | grep '^Name: .*Host path: '
-}
-PARAMS=""
-
-while (( "$#" )); do
- case "$1" in
- -h|--help)
- echo "Usage:"
- echo "start vmname start a VM"
- echo "stop vmname stop a VM"
- echo "open vmname open a VM, starting it if necessary"
- 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"
- 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
- shift
- break
- ;;
- -*) # unsupported flags
- echo "Unsupported flag $1" >&2
- exit 1
- ;;
- *) # preserve positional arguments
- PARAMS="$PARAMS $1"
- shift
- ;;
- esac
-done
-eval set -- "$PARAMS"
-
-[ $# -ge 1 ] || die "Not enough arguments provided."
-
-case "$1" in
- "start")
- shift;
- start "$@";
- ;;
- "stop")
- shift;
- stop "$@";
- ;;
- "open")
- shift;
- open "$@";
- ;;
- "ls"|"list")
- ls;
- ;;
- "running")
- running;
- ;;
- "share")
- shift;
- share "$@";
- ;;
- "unshare")
- shift;
- unshare "$@";
- ;;
- "sharetmp")
- shift;
- sharetmp "$@";
- ;;
- "shared")
- shift;
- shared "$@";
- ;;
- "info")
- shift;
- info "$@";
- ;;
- "status")
- shift;
- status "$@";
- ;;
- "pause")
- shift;
- pause "$@";
- ;;
- "suspend")
- shift;
- suspend "$@";
- ;;
- "resume")
- shift;
- resume "$@";
- ;;
- *)
- die "Unsupported command $1";
- ;;
-esac
diff --git a/shell/zsh-completions-mine/_vbox b/shell/zsh-completions-mine/_vbox
@@ -1,52 +0,0 @@
-#compdef vbox
-_vboxmachines() {
- VBoxManage list vms | egrep -o '^"[^"]+"' 2>/dev/null | sed -e 's|"||g' | while read machine; do
- _wanted 'machine' expl 'machine' compadd $machine
- done
-}
-_vbox() {
- local -a arguments
- arguments=(
- 'start:start a VM'
- 'stop:stop a VM'
- 'open:open a VM, starting it if necessary'
- 'pause:pause a VM'
- 'suspend:suspend 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'
- 'sharetmp:temporarily share a local folder'
- 'shared:list shared folders for a VM'
- )
- local context state line expl
- local -A opt_args
- _arguments '*:: :->subcmds' && return 0
-
- if (( CURRENT == 1 )); then
- _describe -t commands "vbox commands" arguments -V1
- return
- fi
-
- case "$words[1]" in
- share|sharetmp)
- _arguments \
- ':hostpath:_files -/' \
- :machine:_vboxmachines \
- ':name: :'
- ;;
- unshare)
- _arguments \
- ':hostpath:_files -/' \
- :machine:_vboxmachines
- ;;
- start|stop|open|status|info|shared|pause|suspend|resume)
- _arguments \
- :machine:_vboxmachines
- ;;
- esac
- return 1
-}