#!/bin/bash # # Toggle individual VM autostart between on and off # if [ $UID -eq 0 ]; then echo "This script should NOT be run as root." exit 1 fi # # Source config file if [ ! -f ~/.vbconfig ]; then echo "Config File ~/.vbconfig not found!" echo "Run: set-folders to create .vbconfig" exit 1 fi . ~/.vbconfig # AUTOSTOPTYPE=savestate # List VM's auto start status $VB_BIN_LOC/820-list-autostart.bash # AS_ENA= AS_DIS= echo " Enter the VM Name you like to toggle autostart. Enter null to Exit" read -p "Enter VM Name: " VB_VM_NAME while [[ ! $VB_VM_NAME == "" ]]; do VM_POWERED_OFF=`VBoxManage showvminfo ${VB_VM_NAME}|\ grep State|grep -c "powered off"` if [ $VM_POWERED_OFF -eq 0 ]; then echo "VM $VB_VM_NAME is up or saved. Please power-down VM to change autostart settings" else CHK_AS=`VBoxManage showvminfo "${VB_VM_NAME}" | grep "Autostart Enabled:" | grep -c on` if [ $CHK_AS -eq 0 ]; then read -p "Auto start currently disabled on $VB_VM_NAME. Enable (y/n):" AS_ENA else read -p "Auto start currently enabled on $VB_VM_NAME. Disable (y/n):" AS_DIS fi if [[ $AS_ENA == "Y" || $AS_ENA == "y" ]]; then VBoxManage modifyvm ${VB_VM_NAME} --autostart-enabled on --autostop-type $AUTOSTOPTYPE echo "Auto start enabled for ${VB_VM_NAME}" fi if [[ $AS_DIS == "Y" || $AS_DIS == "y" ]]; then VBoxManage modifyvm ${VB_VM_NAME} --autostart-enabled off --autostop-type $AUTOSTOPTYPE echo "Auto start disabled for ${VB_VM_NAME}" fi unset AS_ENA unset AS_DIS fi read -p "Enter VM Name: " VB_VM_NAME done # exit