#!/bin/bash # VirtualBox system starter and connecter #set -x . /home/default PROGRAMS "dialog VBoxManage" # No need to change anything below # The parameters. TEXT="VirtualBox system starter and connecter" #End parameters # Make the list of systems for the menu VBoxManage list vms|grep '{'|sort| \ sed 's/{/"/g' |\ sed 's/}/"/g' |\ awk '{print $0, "\"Not Connected\""}' \ > $TMP.mnu #See which ones are connected for CON in `VBoxManage list runningvms|grep {|awk '{print $NF}'` do echo done #Select the system eval "menu=( $(< $TMP.mnu) )" $DIALOG --backtitle "$TEXT" \ --item-help --title "System selector" \ --menu "Please select one of the distrubutions to run" 15 60 30 \ "${menu[@]}" \ 2>$TMP #Run the command if possible #clear KEY=$? MACHINE=`cat $TMP` case $KEY in 0) LINE "$MACHINE selected";; 1) LINE "Cancel selected";exit;; 2) LINE "Help selected";exit;; 255) LINE "ESC selected";exit;; esac echo "" > $TMP #Get the different ports PORT=`VBoxManage showvminfo "$MACHINE" |grep guest|awk -F, '{print $4}'|awk '{print $NF}'` if [ "$PORT" == "" ] then #Configure the Machine to accept SSH {{{ clear LINE "${txtblu}No port configured${txtoff}" LINE "Existing machines and ports" VBoxManage list vms|grep '{'|awk -F '"' '{print $2}'| while read MACHINE do PORT=`VBoxManage showvminfo "$MACHINE" |grep guest|awk -F, '{print $4}'|awk '{print $NF}'` if [ "$PORT" == "" ] then PORT="none" fi echo "port $PORT : $MACHINE" echo $PORT >> $TMP done PORT=`cat $TMP|sort -n|tail -n 1` let "PORT = $PORT + 1" cat <<-EOF Run the following command. See that ${txtbld}$PORT${txtoff} is not something you already use. ${txtbld}Machine must be down${txtoff} VBoxManage modifyvm "${MACHINE}" --natpf1 "${MACHINE},tcp,,${txtbld}$PORT${txtoff},,22" EOF LINE exit #}}} fi #Launch the machine if not already done RUN=`VBoxManage list runningvms|grep "\"$MACHINE\""` if [ "$RUN" == "" ] then VBoxHeadless -s "$MACHINE" > /dev/null 2>&1 & PCT=100 ( while test $PCT != 0 do cat <