Author Topic: Zenity Script Help for getvirtualbox.  (Read 8114 times)

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12519
Zenity Script Help for getvirtualbox.
« on: June 06, 2010, 06:43:10 AM »
Let me preface this by saying that bash scripting is not my strong suite. Here is a working bash script that will download and install Virtualbox 3.2.2 Non OSE edition with USB support. I need someone to help convert it to a zenity script so we can add it as a package to the repository as GetVirtualBox. Something similar to what we do for GetOpenOffice. If Oracle won't make a PCLinuxOS  prebuilt rpm like they do for other distributions then we will provide a way to get the Non OSE version installed for our members.


Code: [Select]
#!/bin/bash -l

# getvirtualbox
#
# Copyright (C) 2010 Bill Reynolds <texstar@gmail.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#


# check for working internet connection
#=================================================
cd /tmp
/bin/rm -f index.html inet.log
echo "Testing your Internet connection..."
( wget --timeout=15 http://www.google.com/index.html -o inet.log ) 2>&1


if [ ! -f /tmp/index.html ]; then
echo "No Internet connection found.\n\nExiting..."
exit 0
fi

# clean up
/bin/rm -f index.html inet.log


# download VirtualBox
#=================================================
echo "Downloading VirtualBox"
wget -nc http://download.virtualbox.org/virtualbox/3.2.2/VirtualBox-3.2.2-62298-Linux_x86.run

#make file executable
#=================================================
chmod a+x VirtualBox-3.2.2-62298-Linux_x86.run

# run the installer
#=================================================
sh VirtualBox-3.2.2-62298-Linux_x86.run

# Virtualbox installer automatically adds vboxusers group
#=================================================


# add users to group vboxusers
#=================================================
SYSUSERS=`cat /etc/passwd | grep "/bin/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
SYSUSERS=${SYSUSERS/named/}
for idx in $SYSUSERS
 do INP1= usermod -G vboxusers $idx; done


# Remove created symlink and make actual desktop file
#=================================================
if [ -f /usr/share/applications/virtualbox.desktop ]; then
/bin/rm -rf /usr/share/applications/virtualbox.desktop
fi

# create menu entry for PCLinuxOS
#=================================================
cat >/usr/share/applications/virtualbox.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Oracle VM VirtualBox
GenericName=Virtual Machine
Type=Application
Exec=VirtualBox
TryExec=VirtualBox
DocPath=file:///opt/VirtualBox/UserManual.pdf
Icon=VBox
Categories=Emulator;System;X-MandrivaLinux-MoreApplications-Emulators;
Comment=Run several virtual systems on a single host computer
EOF


# clean up
#=================================================
/bin/rm -f VirtualBox-3.2.2-62298-Linux_x86.run

echo "Done"


Thanks for any help on this.
Tex
« Last Edit: June 06, 2010, 06:44:53 AM by Texstar »

Thanks to everyone who donates. You keep the servers running.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Zenity Script Help for getvirtualbox.
« Reply #1 on: June 06, 2010, 07:04:17 AM »
I'll have a look and see if I can do anything. (And keep my fingers crossed that someone better at this comes along to help. ;D)

Offline menotu

  • PCLinuxOS Tester
  • Super Villain
  • *******
  • Posts: 15304
  • ┌∩┐(◕_◕)┌∩┐
Re: Zenity Script Help for getvirtualbox.
« Reply #2 on: June 06, 2010, 07:18:48 AM »
Quote
If Oracle won't make a PCLinuxOS  prebuilt rpm like they do for other distributions then we will provide a way to get the Non OSE version installed for our members.

What can I say! Tex, you're a Diamond Geezer!!

==================================

Edit: I run the script on a clean install and it went fine.

Only one error message  (full Konsole output on attached txt file)

Verifying archive integrity... All good.
Uncompressing VirtualBox for Linux installation..........
VirtualBox Version 3.2.2 r62298 (2010-06-02T14:46:45Z) installer
Installing VirtualBox to /opt/VirtualBox
tar: Record size = 8 blocks
Python found: python, installing bindings...
error: invalid Python installation: unable to open /usr/lib/python2.5/config/Makefile (No such file or directory)
Building the VirtualBox vboxdrv kernel module
Building the VirtualBox netflt kernel module
Building the VirtualBox netadp kernel module

VirtualBox has been installed successfully.
« Last Edit: June 06, 2010, 11:50:25 AM by menotu »
PCLinuxOS 32bit KDE 4.10.1; kernel-3.4.11-pclos1.bfs & 64bit 3.2.18bfs; NVidia GeForce 8400GS 1GB 310.19 driver

Sony Vaio SVE1513A4ESI Laptop, Intel Core i5, 2.6GHz, 6GB RAM, 750GB, 15.6" Intel HD Graphics 4000

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12519
Re: Zenity Script Help for getvirtualbox.
« Reply #3 on: June 06, 2010, 12:53:09 PM »
Quote
If Oracle won't make a PCLinuxOS  prebuilt rpm like they do for other distributions then we will provide a way to get the Non OSE version installed for our members.

What can I say! Tex, you're a Diamond Geezer!!

==================================

Edit: I run the script on a clean install and it went fine.

Only one error message  (full Konsole output on attached txt file)

Verifying archive integrity... All good.
Uncompressing VirtualBox for Linux installation..........
VirtualBox Version 3.2.2 r62298 (2010-06-02T14:46:45Z) installer
Installing VirtualBox to /opt/VirtualBox
tar: Record size = 8 blocks
Python found: python, installing bindings...
error: invalid Python installation: unable to open /usr/lib/python2.5/config/Makefile (No such file or directory)
Building the VirtualBox vboxdrv kernel module
Building the VirtualBox netflt kernel module
Building the VirtualBox netadp kernel module

VirtualBox has been installed successfully.

The python script error is due to not having libpython2.5-devel installed. This would be a requires when installing the rpm package of getvirtualbox as well as conflicting with the old virtualbox packages one might have installed.

Thanks for testing.


Thanks to everyone who donates. You keep the servers running.

Offline menotu

  • PCLinuxOS Tester
  • Super Villain
  • *******
  • Posts: 15304
  • ┌∩┐(◕_◕)┌∩┐
Re: Zenity Script Help for getvirtualbox.
« Reply #4 on: June 06, 2010, 01:46:07 PM »
Quote
The python script error is due to not having libpython2.5-devel installed. This would be a requires when installing the rpm package of getvirtualbox as well as conflicting with the old virtualbox packages one might have installed.

Installed libpython2.5-devel (2.5.2-4pclos2010)

Then run your script again and this time no error messages.

Have attached the full output in case its of any use.

PCLinuxOS 32bit KDE 4.10.1; kernel-3.4.11-pclos1.bfs & 64bit 3.2.18bfs; NVidia GeForce 8400GS 1GB 310.19 driver

Sony Vaio SVE1513A4ESI Laptop, Intel Core i5, 2.6GHz, 6GB RAM, 750GB, 15.6" Intel HD Graphics 4000

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12519
Re: Zenity Script Help for getvirtualbox.
« Reply #5 on: June 06, 2010, 02:47:04 PM »
Since Neal is napping I'm trying my hand at zenity.

Code: [Select]
#!/bin/bash -l

# getvirtualbox
#
# Copyright (C) 2010 Bill Reynolds <texstar@gmail.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

# define some variables
#=================================================
TITLE="GetVirtualBox 3.2.2"
source="http://download.virtualbox.org/virtualbox/3.2.2/VirtualBox-3.2.2-62298-Linux_x86.run"
package="VirtualBox-3.2.2-62298-Linux_x86.run"
ZEN2="zenity"


# check for working internet connection
#=================================================
cd /tmp
/bin/rm -f index.html inet.log
MSG=$"Testing your Internet connection..."
( wget --timeout=15 http://www.google.com/index.html -o inet.log ) 2>&1 | $ZEN2 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close


if [ ! -f /tmp/index.html ]; then
MSG=$"No Internet connection found.\n\nExiting..."
$ZEN2 --title="$TITLE" --error --text "$MSG"
exit 0
fi

# clean up
/bin/rm -f index.html inet.log


# make sure no partial downloads exist in /tmp
#=================================================
/bin/rm -f VirtualBox*


# download VirtualBox
#=================================================
MSG=$"Downloading VirtualBox (53mb). Please be patient..."
( wget $source ) 2>&1 | $ZEN2 --width 500 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close

#make file executable
#=================================================
chmod a+x $package

# run the installer
#=================================================
MSG=$"Installing VirtualBox. Please be patient..."
( sh $package ) 2>&1 | $ZEN2 --width 500 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close


# Virtualbox installer automatically adds vboxusers group
#=================================================


# add users to group vboxusers
#=================================================
SYSUSERS=`cat /etc/passwd | grep "/bin/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
SYSUSERS=${SYSUSERS/named/}
for idx in $SYSUSERS
 do INP1= usermod -G vboxusers $idx; done


# Remove created symlink and make actual desktop file
#=================================================
if [ -f /usr/share/applications/virtualbox.desktop ]; then
/bin/rm -rf /usr/share/applications/virtualbox.desktop
fi

# create menu entry for PCLinuxOS
#=================================================
cat >/usr/share/applications/virtualbox.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Oracle VM VirtualBox
GenericName=Virtual Machine
Type=Application
Exec=VirtualBox
TryExec=VirtualBox
DocPath=file:///opt/VirtualBox/UserManual.pdf
Icon=VBox
Categories=Emulator;System;X-MandrivaLinux-MoreApplications-Emulators;
Comment=Run several virtual systems on a single host computer
EOF


# clean up
#=================================================
/bin/rm -f $package

# the end
#=================================================
MSG=$"VirtualBox is now available from the menu under\nPCmenu -> More Applications -> Emulators.\n\nHave fun\!"
$ZEN2 --width 500 --title="$TITLE" --info --text="$MSG"
exit 0

The only issue I have now is if I press the Cancel button during the process nothing happens and it doesn't exit.

« Last Edit: June 06, 2010, 03:05:01 PM by Texstar »

Thanks to everyone who donates. You keep the servers running.

Offline Joble

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 6804
  • USA - Mountain Time
Re: Zenity Script Help for getvirtualbox.
« Reply #6 on: June 06, 2010, 03:56:49 PM »
This was a bug reported in 2009 and according to this thread still an issue as of January:
https://bugs.launchpad.net/zenity/+bug/316904

And another one:
http://www.linuxplanet.com/linuxplanet/tutorials/6838/2/
Quote
We'll need to do a little bash programming to show off some of Zenity's more powerful capabilities. When you cascade multiple dialog boxes, you want to make it possible for a user to cancel the whole process when the "Cancel" button is clicked. This is done through the use of a special variable ($?) that Zenity sets when each dialog box exits. To check for the cancel button you must add this code after each call to Zenity:

if [ $? = 1 ];
then exit
fi


I don't know much about zenity, but I hope it helps.  (Oh darn, that's pretty geeky.)
Search First.
Forum Rules
Hero means I talk a lot, nothing more, nothing less!
Have an Awesome Day!
Healthy System

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Zenity Script Help for getvirtualbox.
« Reply #7 on: June 06, 2010, 04:18:52 PM »
Sorry, Tex. Wasn't napping. Had to wait out another storm. ::) We've been getting some with lightening that you could see in Texas, if you happened to be looking this way when it strikes. (Okay, that's a slight exaggeration. ;D)

The script Joble posted should do the job. Have you tried it yet?
Quote
you must add this code after each call to Zenity:

if [ $? = 1 ];
then exit
fi

« Last Edit: June 06, 2010, 04:30:11 PM by Neal »

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12519
Re: Zenity Script Help for getvirtualbox.
« Reply #8 on: June 06, 2010, 05:14:31 PM »
Sorry, Tex. Wasn't napping. Had to wait out another storm. ::) We've been getting some with lightening that you could see in Texas, if you happened to be looking this way when it strikes. (Okay, that's a slight exaggeration. ;D)

The script Joble posted should do the job. Have you tried it yet?
Quote
you must add this code after each call to Zenity:

if [ $? = 1 ];
then exit
fi



I don't know where to put it.


Thanks to everyone who donates. You keep the servers running.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Zenity Script Help for getvirtualbox.
« Reply #9 on: June 06, 2010, 05:17:31 PM »
At any place in the script where zenity is called, this script should be added. That would be in about 6 or 7 places, I think.

Edit: This may help explain it:
http://www.linuxplanet.com/linuxplanet/tutorials/6838/2/
« Last Edit: June 06, 2010, 05:40:13 PM by Neal »

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12519
Re: Zenity Script Help for getvirtualbox.
« Reply #10 on: June 06, 2010, 05:29:12 PM »
At any place in the script where zenity is called, this script should be added. That would be in about 6 or 7 places, I think.



# download VirtualBox
#=================================================
# maybe here?
if [ $? = 1 ];
then exit 0
fi
MSG=$"Downloading VirtualBox (53mb). Please be patient..."
( wget $source ) 2>&1 | $ZEN2 --width 500 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close

# maybe here?
if [ $? = 1 ];
then exit 0
fi

nope neither works...??? I dunno...   :'(

Thanks to everyone who donates. You keep the servers running.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Zenity Script Help for getvirtualbox.
« Reply #11 on: June 06, 2010, 05:47:13 PM »
Maybe:
cd /tmp
/bin/rm -f index.html inet.log
MSG=$"Testing your Internet connection..."
( wget --timeout=15 http://www.google.com/index.html -o inet.log ) 2>&1 | $ZEN2 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close | if [ $? = 1 ];
then exit
fi


Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Zenity Script Help for getvirtualbox.
« Reply #12 on: June 06, 2010, 06:22:46 PM »
Made a few changes:
Code: [Select]
#!/bin/bash -l

# getvirtualbox
#
# Copyright (C) 2010 Bill Reynolds <texstar@gmail.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

# define some variables
#=================================================
TITLE="GetVirtualBox 3.2.2"
source="http://download.virtualbox.org/virtualbox/3.2.2/VirtualBox-3.2.2-62298-Linux_x86.run"
package="VirtualBox-3.2.2-62298-Linux_x86.run"
ZEN2="zenity"


# check for working internet connection
#=================================================
cd /tmp
/bin/rm -f index.html inet.log
MSG=$"Testing your Internet connection..."
( wget --timeout=15 http://www.google.com/index.html -o inet.log ) 2>&1 | $ZEN2 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close | if [ $? = 1 ];
then exit
fi


if [ ! -f /tmp/index.html ]; then
MSG=$"No Internet connection found.\n\nExiting..."
$ZEN2 --title="$TITLE" --error --text "$MSG" | if [ $? = 1 ];
then exit
exit 0
fi


# clean up
/bin/rm -f index.html inet.log


# make sure no partial downloads exist in /tmp
#=================================================
/bin/rm -f VirtualBox*


# download VirtualBox
#=================================================
MSG=$"Downloading VirtualBox (53mb). Please be patient..."
( wget $source ) 2>&1 | $ZEN2 --width 500 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close | if [ $? = 1 ];
then exit | if [ $? = 1 ];
then exit
fi

#make file executable
#=================================================
chmod a+x $package

# run the installer
#=================================================
MSG=$"Installing VirtualBox. Please be patient..."
( sh $package ) 2>&1 | $ZEN2 --width 500 --title="$TITLE" --progress --text "$MSG" --pulsate --auto-close | if [ $? = 1 ];
then exit
fi


# Virtualbox installer automatically adds vboxusers group
#=================================================


# add users to group vboxusers
#=================================================
SYSUSERS=`cat /etc/passwd | grep "/bin/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
SYSUSERS=${SYSUSERS/named/}
for idx in $SYSUSERS
 do INP1= usermod -G vboxusers $idx; done


# Remove created symlink and make actual desktop file
#=================================================
if [ -f /usr/share/applications/virtualbox.desktop ]; then
/bin/rm -rf /usr/share/applications/virtualbox.desktop
fi

# create menu entry for PCLinuxOS
#=================================================
cat >/usr/share/applications/virtualbox.desktop << EOF
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Oracle VM VirtualBox
GenericName=Virtual Machine
Type=Application
Exec=VirtualBox
TryExec=VirtualBox
DocPath=file:///opt/VirtualBox/UserManual.pdf
Icon=VBox
Categories=Emulator;System;X-MandrivaLinux-MoreApplications-Emulators;
Comment=Run several virtual systems on a single host computer
EOF


# clean up
#=================================================
/bin/rm -f $package

# the end
#=================================================
Mline 124: syntax error: unexpected end of fileSG=$"VirtualBox is now available from the menu under\nPCmenu -> More Applications -> Emulators.\n\nHave fun\!"
$ZEN2 --width 500 --title="$TITLE" --info --text="$MSG"

exit 0
Launching it via terminal returns:
Code: [Select]
line 124: syntax error: unexpected end of file
 ::) :P ::)


Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12519
Re: Zenity Script Help for getvirtualbox.
« Reply #13 on: June 06, 2010, 06:24:56 PM »
I have this odd feeling the blind is leading the blind here.  ;D ;D ;D


Thanks to everyone who donates. You keep the servers running.

Offline gseaman

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3793
Re: Zenity Script Help for getvirtualbox.
« Reply #14 on: June 06, 2010, 10:51:33 PM »
Most scripts have to end with a new empty line. This may correct that error. But what do I know? (Not much  ;))

Galen