]> git.phdru.name Git - vbox-scripts.git/commitdiff
Initial import
authorOleg Broytman <phd@phdru.name>
Mon, 15 Jul 2019 16:48:51 +0000 (19:48 +0300)
committerOleg Broytman <phd@phdru.name>
Mon, 15 Jul 2019 16:48:51 +0000 (19:48 +0300)
create [new file with mode: 0755]
delete [new file with mode: 0755]
eject-dvd [new file with mode: 0755]
get-vbox-guestadd-extpack [new file with mode: 0755]
run [new file with mode: 0755]
shutdown [new file with mode: 0755]

diff --git a/create b/create
new file mode 100755 (executable)
index 0000000..fc10d41
--- /dev/null
+++ b/create
@@ -0,0 +1,31 @@
+#! /bin/sh
+
+if [ $# -le 1 -o $# -ge 7 ]; then
+   echo "Usage: $0 vm_name iso_file [os_type [disk_size [memory [video_mem]]]]" >&2
+   echo "Example: $0 Debian debian.iso Debian 10000 512" >&2
+   exit 1
+fi
+
+VM_NAME="$1"
+ISO_IMAGE="$2"
+VM_OS_TYPE="${3:-Linux}"
+DISK_SIZE="${4:-1024}"
+VM_MEM="${5:-1024}"
+VM_VMEM="${6:-128}"
+
+VBoxManage createvm --name "$VM_NAME" --ostype "$VM_OS_TYPE" --register &&
+VBoxManage modifyvm "$VM_NAME" --memory "$VM_MEM" --vram "$VM_VMEM" --ioapic on &&
+
+VBoxManage createhd --filename "$HOME/VirtualBox VMs/$VM_NAME/$VM_NAME".vdi --size "$DISK_SIZE" --format VDI &&
+VBoxManage storagectl "$VM_NAME" --name "SATA Controller" --add sata --controller IntelAhci --bootable on &&
+VBoxManage storageattach "$VM_NAME" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$HOME/VirtualBox VMs/$VM_NAME/$VM_NAME".vdi &&
+
+VBoxManage storagectl "$VM_NAME" --name "IDE Controller" --add ide --controller PIIX4 &&
+VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium "$ISO_IMAGE" &&
+VBoxManage modifyvm "$VM_NAME" --boot1 dvd --boot2 disk --boot3 none --boot4 none &&
+
+VBoxManage modifyvm "$VM_NAME" --nic1 nat &&
+VBoxManage modifyvm "$VM_NAME" --natpf1 SSH,tcp,localhost,2022,localhost,22 &&
+
+#VBoxManage showvminfo "$VM_NAME" &&
+exec VBoxManage startvm "$VM_NAME"
diff --git a/delete b/delete
new file mode 100755 (executable)
index 0000000..44cd0ac
--- /dev/null
+++ b/delete
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 vm_name" >&2
+   exit 1
+fi
+
+VM_NAME="$1"
+exec VBoxManage unregistervm "$VM_NAME" --delete
diff --git a/eject-dvd b/eject-dvd
new file mode 100755 (executable)
index 0000000..279ab27
--- /dev/null
+++ b/eject-dvd
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 vm_name" >&2
+   exit 1
+fi
+
+VM_NAME="$1"
+exec VBoxManage storageattach "$VM_NAME" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium none
diff --git a/get-vbox-guestadd-extpack b/get-vbox-guestadd-extpack
new file mode 100755 (executable)
index 0000000..23c0f18
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 version" >&2
+   exit 1
+fi
+
+cd "$HOME/VirtualBox VMs" && \
+ww "http://download.virtualbox.org/virtualbox/$1/VBoxGuestAdditions_$1.iso" \
+   "http://download.virtualbox.org/virtualbox/$1/Oracle_VM_VirtualBox_Extension_Pack-$1.vbox-extpack" &&
+
+exec sudo VBoxManage extpack install --replace \
+   "Oracle_VM_VirtualBox_Extension_Pack-$1.vbox-extpack"
diff --git a/run b/run
new file mode 100755 (executable)
index 0000000..52c3d37
--- /dev/null
+++ b/run
@@ -0,0 +1,25 @@
+#! /bin/sh
+
+if lsmod | grep -Fq kvm; then
+   if ! sudo rmmod kvm_intel kvm; then
+      echo "Kvm modules cannot be removed, abort" 1>&2
+      exit 1
+   fi
+fi
+
+if ! lsmod | grep -Fq vboxdrv; then
+   if ! sudo modprobe vboxdrv; then
+      sudo /etc/init.d/vboxdrv setup
+   fi
+fi
+
+if ! lsmod | grep -Fq vboxdrv; then
+   echo "vboxdrv not found, abort" 1>&2
+   exit 1
+fi
+
+if [ -n "$1" ]; then
+   exec VBoxManage startvm "$@"
+else
+   exec VirtualBox
+fi
diff --git a/shutdown b/shutdown
new file mode 100755 (executable)
index 0000000..57756b4
--- /dev/null
+++ b/shutdown
@@ -0,0 +1,9 @@
+#! /bin/sh
+
+if [ -z "$1" ]; then
+   echo "Usage: $0 vm_name [poweroff]" >&2
+   exit 1
+fi
+
+VM_NAME="$1"
+exec VBoxManage controlvm "$VM_NAME" ${2:-acpipowerbutton}