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

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12500
Re: Zenity Script Help for getvirtualbox.
« Reply #30 on: June 09, 2010, 12:33:03 AM »
Here is the latest script to download and install Virtualbox 3.2.4 non-ose version with USB support. Need to fix the the exit message if a user presses cancel during the download.

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


# getvirtualbox
#
# Purpose: install the latest VirtualBox into PCLinuxOS
#
# Requirements:
#  - PCLinuxOS installation
#  - working apt-get & Internet connection (not for removal)
#  - zenity, wget, libpython2.5-devel
#
# Version: 3.2.4 (2010-06-09)
#
# 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.4"
package="VirtualBox-3.2.4-62467-Linux_x86.run"
source="http://download.virtualbox.org/virtualbox/3.2.4/"$package
ZEN2="zenity"
SCRIPT_PID=$$


# Function to kill child processes of this script (wget, sed, zenity, etc)
# ..naming it kill_child just doesn't seem right ;)
#=================================================

function exit_kill {
  echo "Killing all child processes of script..  (script pid: $SCRIPT_PID)"
  # check output of ps command for pids that have parent pids (ppid) matching this scripts pid
  for child in $(ps axo ucmd,pid,ppid | awk "{ if ( \$3 == $SCRIPT_PID ) { print \$2 }}")
  do
    echo "Killing child process $child because ppid = $SCRIPT_PID"
    kill -9 $child 2>/dev/null
  done
}



# check for working internet connection
#=================================================
cd /tmp
/bin/rm -f index.html inet.log  VirtualBox*
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"
/bin/rm -f index.html inet.log
exit 0
fi

# clean up and make sure no partial downloads exist in /tmp
/bin/rm -f index.html inet.log VirtualBox*

# download VirtualBox
#=================================================
wget $source 2>&1 | sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s\\nETA \3/' |  (if `$ZEN2 --width 400 --progress --title="$TITLE" --auto-close`;
                 then
                     echo 'Job completed'
                 else
                     exit_kill $SCRIPT_PID
                     # for less verbosity, the following one-liner could replace the exit_kill function:
                     # kill -9 `ps axo ucmd,pid,ppid | awk "{ if ( \$3 == $THIS_PID ) { print \$2 }}"`
                 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


# Create usb group if it doesn't exist, won't hurt if usb group already exists
#=================================================
groupadd usb


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


# add users to group vboxusers and usb
#=================================================
SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
for idx in $SYSUSERS; do usermod -a -G vboxusers,usb $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

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

Offline djohnston

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6227
  • I don't do Windows
Re: Zenity Script Help for getvirtualbox.
« Reply #31 on: June 09, 2010, 12:38:44 AM »
Thanks, Tex. This will come in very handy.
Bare metal                           VBox
AMD Athlon 7750 Dual-Core    Single core
4GiB RAM                              1GiB RAM
nVidia GeForce FX 5200          64MB video
LXDE 32bit                            KDE 64bit

Registered Linux User #416378

Offline travisN000

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1758
Re: Zenity Script Help for getvirtualbox.
« Reply #32 on: June 09, 2010, 12:43:11 AM »
I have a mostly functional version of the script with full zenity feedback (cancel working with exit messages), but I have noticed that if the user has vbox installed from the repo's the .run install script will hang when it asks for permission to continue (zenity eats the script output).

I was going to have the script test for the installed virtualbox package, but I wasn't sure if I should test for all of them, some of them, or just the main one.  Any thoughts ??

« Last Edit: June 09, 2010, 12:50:23 AM by travisn000 »

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12500
Re: Zenity Script Help for getvirtualbox.
« Reply #33 on: June 09, 2010, 12:57:21 AM »
I have a mostly functional version of the script with full zenity feedback (cancel working with exit messages), but I have noticed that if the user has vbox installed from the repo's the .run install script will hang when it asks for permission to continue (zenity eats the script output).

I was going to have the script test for the installed virtualbox package, but I wasn't sure if I should test for all of them, some of them, or just the main one.  Any thoughts ??



I was going to add conflicts to the specfile so when a user installs this version it removes the OSE version.

Spec file to remove or conflicts:
dkms-vboxadditions-3.1.8-2pclos2010.i586.rpm
dkms-virtualbox-3.1.8-2pclos2010.i586.rpm
virtualbox-3.1.8-2pclos2010.i586.rpm
virtualbox-guest-additions-3.1.8-2pclos2010.i586.rpm

Spec file to keep or requires:
x11-driver-input-vboxmouse-3.1.8-2pclos2010.i586.rpm
x11-driver-video-vboxvideo-3.1.8-2pclos2010.i586.rpm


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

Offline travisN000

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1758
Re: Zenity Script Help for getvirtualbox.
« Reply #34 on: June 09, 2010, 01:28:40 AM »
Here is what I have:
Code: [Select]
#!/bin/bash -l

# getvirtualbox
#
# Purpose: install the latest VirtualBox into PCLinuxOS
#
# Requirements:
#  - PCLinuxOS installation
#  - working apt-get & Internet connection (not for removal)
#  - zenity, wget, libpython2.5-devel
#
# Version: 3.2.4 (2010-06-09)
#
# 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
#



# verbose output for debugging
#=================================================
if [ "$1" == "--debug" ]; then set -xv; fi


# define some variables
#=================================================
TITLE="GetVirtualBox 3.2.4"
package="VirtualBox-3.2.4-62467-Linux_x86.run"
source="http://download.virtualbox.org/virtualbox/3.2.4/"$package
ZEN2="zenity"
SCRIPT_PID=$$


#NOT NEEDED
# Check if zenity is installed...
#=================================================
if [ -f /usr/bin/kdialog ]; then
    DIALOG=kdialog
else
    DIALOG=gdialog
fi

if [ ! -e /usr/bin/zenity ]; then
  $DIALOG --yesno "Zenity is required for this script,\nWould you like to install it now?"
  if [ "$?" == "0" ]; then
    synaptic
  else
    $DIALOG --sorry "Exiting now"
    exit 1
  fi
fi



# test for super user privliges
#=================================================
if [ "$UID" != "0" ]; then
    $ZEN2 --error --title="$TITLE" --text="Please run this script as root!"
    exit 1
fi


#NOT NEEDED
# check that package managers are closed
#=================================================
for idx in synaptic smart ksmarttray kpackage apt-get
do
 if [ -n "`pidof $idx`" ]; then
  MSG=$"Please close the package manager <b>'$idx'</b> \nand then run GetVirtualBox again.\n\n(Script will exit.)"
  $ZEN2 --title="$TITLE" --error --text "$MSG"
  exit 1
 fi
done


#NOT NEEDED
# check if vbox rpm is installed
#=================================================
MSG=$"A VirtualBox package has already been installed from synaptic. \n\nAll VirtualBox packages <b><i>except</i> x11 vbox drivers</b> \nmust be removed before continuing\n\n(Script will Terminate.)"

rpm -q virtualbox && $ZEN2 --title="$TITLE" --error --text "$MSG" && exit 1 && synaptic
rpm -q virtualbox-guest-additions && $ZEN2 --title="$TITLE" --error --text "$MSG" && exit 1 && synaptic
rpm -q dkms-vboxadditions && $ZEN2 --title="$TITLE" --error --text "$MSG" && exit 1 && synaptic
rpm -q dkms-virtualbox  && $ZEN2 --title="$TITLE" --error --text "$MSG" && exit 1 && synaptic




# 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 1
fi

# clean up and make sure no partial downloads exist in /tmp
/bin/rm -f index.html inet.log VirtualBox*


# download VirtualBox
#=================================================
#MSG=$"Downloading VirtualBox (53mb). Please be patient..."

dl_txt=$"Download speed:"
eta_txt=$"Estimated time:"

wget $source 2>&1 \
  | sed -u "s/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# ${dl_txt} \\\t\\\t\2\/s\\\n${eta_txt}\\\t\\\t\3/" \
  | ( if `$ZEN2 --width 400 --progress --title="$TITLE" --auto-close`; then
echo 'Job completed'
wget_cancelled="n"
      else
kill `ps axo ucmd,pid,ppid | grep wget | awk "{ if ( \\$3 == $SCRIPT_PID ) { print \\$2 }}"`
$ZEN2 --width 400 --title="$TITLE" --error --text=$"Download and installation canceled."
exit 1
      fi )





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

# GOOD FEEDBACK
# run the installer
#=================================================
MSG=$"Installing VirtualBox. Please be patient..."
( sh $package ) 2>&1 | $ZEN2 --title="$TITLE" --text-info --editable --width=500 --height=500 > vb_install.log

grep $"Error" vb_install.log >/dev/null && $ZEN2 --title="$TITLE" --error --text=$"Installation failed." && exit 1
grep $"Abort" vb_install.log >/dev/null && $ZEN2 --title="$TITLE" --error --text=$"Installation failed." && exit 1


# Create usb group if it doesn't exist
#=================================================
groupadd usb


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


# add users to group vboxusers and usb
#=================================================
SYSUSERS=`cat /etc/passwd | grep "/home/.*/bash" |grep "[0-9][0-9][0-9]" |cut -d: -f1`
for idx in $SYSUSERS; do usermod -a -G vboxusers,usb $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: \n<b>PCmenu -> More Applications -> Emulators</b>.\n\nHave fun\!"
$ZEN2 --info --title="$TITLE" --text="$MSG"

exit 0


« Last Edit: June 09, 2010, 02:08:23 AM by Texstar »

Offline djohnston

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6227
  • I don't do Windows
Re: Zenity Script Help for getvirtualbox.
« Reply #35 on: June 09, 2010, 02:36:48 AM »
I started Synaptic and removed packages in Tex's list. I saved Tex's script as getvirtualbox.sh. I marked it executable and copied it to the /root directory. Ran the script as root. Waited a while for DKMS modules to build. They must have, because I didn't see any kernel module activity in verbose mode on next reboot. Never hurts to check. Works like a charm. Results are shown below. Thanks, Tex.

installing


installed


menu


favorites


logo


success



Bare metal                           VBox
AMD Athlon 7750 Dual-Core    Single core
4GiB RAM                              1GiB RAM
nVidia GeForce FX 5200          64MB video
LXDE 32bit                            KDE 64bit

Registered Linux User #416378

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12500
Re: Zenity Script Help for getvirtualbox.
« Reply #36 on: June 09, 2010, 03:16:08 AM »
I will have a package in the repos to play with called getvirtualbox-3.2.4-1pclos2010.i586.rpm shortly.


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

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15845
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Zenity Script Help for getvirtualbox.
« Reply #37 on: June 09, 2010, 03:19:22 AM »
 :D Great!

Offline Xenaflux

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 3834
Re: Zenity Script Help for getvirtualbox.
« Reply #38 on: June 09, 2010, 03:40:38 AM »
Quote
I will have a package in the repos to play with called getvirtualbox-3.2.4-1pclos2010.i586.rpm shortly.

Is that going to overwrite my existing virtualbox 3.1.8 ( the non-OSE version ) ?

Thanks
Xena
The great thing in this world is not so much where we stand,
as in what direction we are moving.
                                                    (Oliver Wendell Holmes )

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12500
Re: Zenity Script Help for getvirtualbox.
« Reply #39 on: June 09, 2010, 03:43:12 AM »
Quote
I will have a package in the repos to play with called getvirtualbox-3.2.4-1pclos2010.i586.rpm shortly.

Is that going to overwrite my existing virtualbox 3.1.8 ( the non-OSE version ) ?

Thanks
Xena

This will remove and replace the existing VirtualBox 3.18 OSE packages that are in the repo. It will also replace any previous VirtualBox installations done with Oracle's runtime installer. It will not delete your existing VDI's.

« Last Edit: June 09, 2010, 03:46:47 AM by Texstar »

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

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12500
Re: Zenity Script Help for getvirtualbox.
« Reply #40 on: June 09, 2010, 03:53:47 AM »
:D Great!

I love it when a plan comes together.  ;D

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

Offline hoos

  • Sr. Member
  • ****
  • Posts: 375
  • E=mc²
Re: Zenity Script Help for getvirtualbox.
« Reply #41 on: June 09, 2010, 04:03:48 AM »
Excellent script so far...
However usb entries are all greyed out still, as is the
case from 3.2.0 onwards.
3.1.8 PUEL (PClinuxOS variant) works though.

Any thoughts on this?

         Thanks, cheers, Hoos.
You have to be efficient if you're going to be lazy

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12500
Re: Zenity Script Help for getvirtualbox.
« Reply #42 on: June 09, 2010, 04:11:05 AM »
Excellent script so far...
However usb entries are all greyed out still, as is the
case from 3.2.0 onwards.
3.1.8 PUEL (PClinuxOS variant) works though.

Any thoughts on this?

         Thanks, cheers, Hoos.


Don't know. Looks good to me here. Is this what you mean?




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

Offline hoos

  • Sr. Member
  • ****
  • Posts: 375
  • E=mc²
Re: Zenity Script Help for getvirtualbox.
« Reply #43 on: June 09, 2010, 04:32:47 AM »
I'm afraid not,
the setup like you're showing is allright, same as mine
only I have my scanner added.
But after starting the vm (XP, W7) in the upper left hand corner
under 'devices' the usb entries are greyed out;
e.g. my scanner cannot be mounted nor any other usb devices
such as my ext. hd etc.

            Ch, Hoos.
You have to be efficient if you're going to be lazy

Offline Texstar

  • Administrator
  • Super Villain
  • *****
  • Posts: 12500
Re: Zenity Script Help for getvirtualbox.
« Reply #44 on: June 09, 2010, 04:36:06 AM »
I'm afraid not,
the setup like you're showing is allright, same as mine
only I have my scanner added.
But after starting the vm (XP, W7) in the upper left hand corner
under 'devices' the usb entries are greyed out;
e.g. my scanner cannot be mounted nor any other usb devices
such as my ext. hd etc.

            Ch, Hoos.

Have you reported it to Oracle or searched their forum for a possible solution?

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