VirtualBox lanceur zenity

De Le Wiki du Forum-Debian.fr
Aller à la navigation Aller à la recherche

Informations

Ce script Bash utilise Zenity, pour permettre le choix et le lancement des machines virtuelles VirtualBox.

Petit plus, si vous êtes dans le cas d'une configuration matérielle ayant une carte nVidia avec la technologie Optimus, ce script utilisera optirun avant de lancer la machine virtuelle ...

Lanceur Zenity pour machines VirtualBox

Le Script

#!/bin/bash
# subject: VirtualBox Launcher by Zenity...

# author: Stephane HUC, alias PengouinPdt
# email: devs@stephane-huc.net

# License texts:
#
#    GNU General Public License version 3 (GPL-3)
#
#On Debian systems, the full text of the GNU General Public License version 3
#can be found in the file `/usr/share/common-licenses/GPL-3'.
#

vmdir="/home/$USER/VirtualBox VMs/"

function display_goodbye() {

	zenity --notification --title="Au Revoir !" --timeout=7 \
		--text="*** Au revoir ! ***"

	exit;

	}

function echos_welcome() {
    i=0

    while [ "$i" -le "$count" ]; do
        if [ -n "${NAME[$i]}" ]; then
            let j=i+1
            echo "$j";
            echo "${NAME[$i]}";
            echo "${DESC[$i]}";
            unset j;
        fi
		let i=i+1;
	done

	unset i;

    }

function list_dir() {
    i=0

    for dir in $(ls "${vmdir}"); do

        NAME[$i]="${dir}"
        MSSG[$i]=$(egrep "name=\"${dir}\"" "${vmdir}${dir}/${dir}.vbox" | awk -F'"' '{print $6}')
        DESC[$i]=$(echo ${MSSG[$i]} | sed -e "s/\_64/\ \(64\ bit\)/g")

        let i=i+1;
    done

    count=${#NAME[@]}
    unset i;
    }

function starter_vbox() {

    optirun=$(which optirun)
    virtualbox=$(which virtualbox)

    if [ -e $optirun ]; then
        $optirun $virtualbox --startvm ${NAME[$choice]}
    else
        $virtualbox --startvm ${NAME[$choice]}
    fi

    }

function welcome() {

    choice=$( echos_welcome | zenity --list --title="VBox Launcher" \
		--text="Veuillez indiquer quelle VBox lancer :" \
		--column="Choix" --column="Nom" --column="Description" );

    if [ $? -eq 1 ]; then display_goodbye; fi

    choice=$(echo "$choice - 1" | bc)

    }

list_dir
welcome
starter_vbox