« VirtualBox lanceur zenity » : différence entre les versions

De Le Wiki du Forum-Debian.fr
Aller à la navigation Aller à la recherche
m (change <pre> en ajout d'un espace en début de ligne)
m (<syntaxhighlight lang="bash" line="line">)
 
Ligne 9 : Ligne 9 :
== Le Script ==
== Le Script ==


#!/bin/bash
<syntaxhighlight lang="bash" line="line">
# subject: VirtualBox Launcher by Zenity...
#!/bin/bash
# subject: VirtualBox Launcher by Zenity...
# author: Stephane HUC, alias PengouinPdt
 
# email: devs@stephane-huc.net
# author: Stephane HUC, alias PengouinPdt
# email: devs@stephane-huc.net
# License texts:
 
#
# License texts:
#    GNU General Public License version 3 (GPL-3)
#
#
#    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'.
#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/"
 
vmdir="/home/$USER/VirtualBox VMs/"
function display_goodbye() {
 
function display_goodbye() {
zenity --notification --title="Au Revoir !" --timeout=7 \
 
--text="*** Au revoir ! ***"
zenity --notification --title="Au Revoir !" --timeout=7 \
--text="*** Au revoir ! ***"
exit;
 
exit;
}
 
}
function echos_welcome() {
 
    i=0
function echos_welcome() {
    i=0
    while [ "$i" -le "$count" ]; do
 
        if [ -n "${NAME[$i]}" ]; then
    while [ "$i" -le "$count" ]; do
            let j=i+1
        if [ -n "${NAME[$i]}" ]; then
            echo "$j";
            let j=i+1
            echo "${NAME[$i]}";
            echo "$j";
            echo "${DESC[$i]}";
            echo "${NAME[$i]}";
            unset j;
            echo "${DESC[$i]}";
        fi
            unset j;
let i=i+1;
        fi
done
let i=i+1;
done
unset i;
 
unset i;
    }
 
    }
function list_dir() {
 
    i=0
function list_dir() {
    i=0
    for dir in $(ls "${vmdir}"); do
 
    for dir in $(ls "${vmdir}"); do
        NAME[$i]="${dir}"
 
        MSSG[$i]=$(egrep "name=\"${dir}\"" "${vmdir}${dir}/${dir}.vbox" | awk -F'"' '{print $6}')
        NAME[$i]="${dir}"
        DESC[$i]=$(echo ${MSSG[$i]} | sed -e "s/\_64/\ \(64\ bit\)/g")
        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
        let i=i+1;
    done
    count=${#NAME[@]}
 
    unset i;
    count=${#NAME[@]}
    }
    unset i;
    }
function starter_vbox() {
 
function starter_vbox() {
    optirun=$(which optirun)
 
    virtualbox=$(which virtualbox)
    optirun=$(which optirun)
    virtualbox=$(which virtualbox)
    if [ -e $optirun ]; then
 
        $optirun $virtualbox --startvm ${NAME[$choice]}
    if [ -e $optirun ]; then
    else
        $optirun $virtualbox --startvm ${NAME[$choice]}
        $virtualbox --startvm ${NAME[$choice]}
    else
    fi
        $virtualbox --startvm ${NAME[$choice]}
    fi
    }
 
    }
function welcome() {
 
function welcome() {
    choice=$( echos_welcome | zenity --list --title="VBox Launcher" \
 
--text="Veuillez indiquer quelle VBox lancer :" \
    choice=$( echos_welcome | zenity --list --title="VBox Launcher" \
--column="Choix" --column="Nom" --column="Description" );
--text="Veuillez indiquer quelle VBox lancer :" \
--column="Choix" --column="Nom" --column="Description" );
    if [ $? -eq 1 ]; then display_goodbye; fi
 
    if [ $? -eq 1 ]; then display_goodbye; fi
    choice=$(echo "$choice - 1" | bc)
 
    choice=$(echo "$choice - 1" | bc)
    }
 
    }
list_dir
 
welcome
list_dir
starter_vbox
welcome
starter_vbox
</syntaxhighlight>
   
   
[[Catégorie:Programmation]]
[[Catégorie:Programmation]]
[[Catégorie:Scripts]]
[[Catégorie:Scripts]]

Dernière version du 20 février 2017 à 06:41

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