#! /bin/bash
#(c) Copyright Barry Kauler, Oct 2010
#License: gpl v2 (/usr/share/doc/legal/gpl-2.0.txt)
#101024 fix bug with internet connection detection.
#101027 fixed little bugs for nvidia.
#101106 make generic so will work in other woof-built puppies, not just wary.
#101106 added support to install a commercial ATI driver.
#101107 ati driver installation (aticonfig --initial) messes up xorg.conf.
#101112 fix paths to which_ati_pkg, which_nvidia_pkg.
#101114 01micko: backslash was missing.
#101116 call 'download_file' instead of running wget directly.
#101117 fglrx fix.
#101118 insert warning to install DRI pkg before upgrade. 
#101129 WRONG for intel upgrade, upgrade pkg has upgraded dri/mesa in it.
#101205 fixes. nobody seems to have got my ati pet to work, remove for now.
#110105 new xorg 7.5 upgrade pet.
#110827 support split nvidia pkgs, nvidia_base and nvidia_kmodule. 110829 bugfix.

export LANG=C
. /etc/DISTRO_SPECS
. /root/.packages/DISTRO_PET_REPOS #101106

#if [ "$DISTRO_COMPAT_VERSION" != "wary5" ];then
# xmessage -bg pink -center "Sorry, this Wizard currently only works in Wary Puppy"
# exit
#fi
#101106 determine where to look for PETs...
PET_DB_FILE="`echo -n "$PACKAGELISTS_PET_ORDER" | cut -f 1 -d ' '`" #exs: Packages-puppy-wary5-official, Packages-puppy-lucid-official, Packages-puppy-5-official
case $DISTRO_COMPAT_VERSION in
 wary*)
  PET_URL='http://distro.ibiblio.org/pub/linux/distributions/quirky/'
 ;;
 *)
  PET_URL='http://distro.ibiblio.org/pub/linux/distributions/puppylinux/'
 ;;
esac
[ "$DISTRO_BINARY_COMPAT" = "t2" ] && PET_URL='http://distro.ibiblio.org/pub/linux/distributions/quirky/'
case $PET_DB_FILE in
 Packages-puppy-wary5-official)
  PET_FOLDER='pet_packages-wary5/'
 ;;
 Packages-puppy-lucid-official)
  PET_FOLDER='pet_packages-lucid/'
 ;;
 *)
  PET_FOLDER='pet_packages-5/'
 ;;
esac

#101107 ati driver installation (aticonfig --initial) messes up xorg.conf... 101117
if [ "`grep '^ #card0driver' /etc/X11/xorg.conf`" != "" ];then
 sed -i -e '/#card0driver/d' /etc/X11/xorg.conf
 sed -i -e 's%^\tDriver *"fglrx".*%\tDriver      "fglrx" #card0driver%' /etc/X11/xorg.conf
 #101117 just in case it is still set to radeon driver...
 sed -i -e 's%^\tDriver *"radeon".*%\tDriver      "radeon" #card0driver%' /etc/X11/xorg.conf
fi

INTERNETCNT=0
if [ "`ifconfig | grep -o '^[pwe][a-z0-9]*'`" != "" ];then #101024
 for ONEIF in `ifconfig | grep -o '^[pwe][a-z0-9]*' | tr '\n' ' '`
 do
  [ -e /sys/class/net/${ONEIF}/statistics/rx_bytes ] && [ `cat /sys/class/net/${ONEIF}/statistics/rx_bytes` -gt 0 ] && INTERNETCNT=1
 done
fi
if [ $INTERNETCNT -eq 0 ];then
 #OFFMSG="<pixmap><input file>/usr/local/video_upgrade/notconnected.png</input></pixmap>"
 #gtkdialog span tag parsing is a bit odd...
 OFFMSG="<text use-markup=\"true\"><label>\"<b><big><span color='"'red'"' background='"'yellow'"'>Currently not connected to Internet! Run this Wizard later (see Setup menu), when Internet working</span></big></b>\"</label></text>"
 #this also works...
 #OFFMSG='<text use-markup="true"><label>"<b><big><span color='"'red'"' background='"'yellow'"'>Currently not connected to Internet! Run this Wizard later (see Setup menu), when Internet working</span></big></b>"</label></text>'
fi

#101118 put up a warning to install DRI pkg first...
#101129 take this out...
#WARNMSG="<text use-markup=\"true\"><label>\"<b><big><span color='"'red'"' background='"'yellow'"'>NOTICE: Install the DRI (mesa) package FIRST, followed by upgrade: we have found DRI pkg gives improved stability</span></big></b>\"</label></text>"


PET_UPGRADE_INTEL="`grep '^xorg_upgrade_intel\-' /root/.packages/${PET_DB_FILE} | cut -f 8 -d '|' | tail -n 1`"
PET_UPGRADE_DEV="`grep '^xorg_upgrade_DEV\-' /root/.packages/${PET_DB_FILE} | cut -f 8 -d '|' | tail -n 1`"
PET_UPGRADE_DRI_EXTRA="`grep '^xorg_upgrade_dri_extra-\-' /root/.packages/${PET_DB_FILE} | cut -f 8 -d '|' | tail -n 1`"
PET_MESA="`grep '^mesa\-[0-9]' /root/.packages/${PET_DB_FILE} | cut -f 8 -d '|' | tail -n 1`"

#101129 find if any already installed...
puiPATTERN='|'"${PET_UPGRADE_INTEL}"'|'
[ "`grep "$puiPATTERN" /root/.packages/user-installed-packages`" != "" ] && FLAG_UPGRADE_INTEL='done'

#101114 01micko: backslash was missing...
echo "#!/bin/sh
PET=\"\$1\" #ex: xorg_upgrade_intel-2.10.0-w5.pet
cd /root
download_file ${PET_URL}${PET_FOLDER}\$PET" > /tmp/petupgradevideo.sh
echo '
if [ $? -ne 0 ];then
 xmessage -bg pink -center "Sorry, download failed"
 exit 1
fi
petget /root/$PET
rm -f /root/$PET
PKGBASE="`basename $PET .pet`"
if [ ! -f /root/.packages/$PKGBASE.files ];then
 xmessage -bg pink -center "Sorry, something went wrong, package downloaded but is not installed"
fi
' >> /tmp/petupgradevideo.sh
chmod 755 /tmp/petupgradevideo.sh

OFFER_MESA="<frame Mesa DRI><hbox>
     <text><label>DRI (Direct Rendering Infrastructure) provides Xorg drivers that will speed up some graphics/video applications that use openGL. This is optional, and will only give a noticeable improvement on a small selection of applications. If you have an Internet connection, click button to download (filesize 12MB):</label></text>
     <vbox>
       <button><input file>/usr/local/video_upgrade/dri48x29.png</input>
       <action>/tmp/petupgradevideo.sh ${PET_MESA} & </action></button>
     </vbox>
   </hbox></frame>"

VIDEODETAILS="`lspci -nn -m | grep 'VGA compatible controller'`"
#ex: 00:02.0 "VGA compatible controller [0300]" "Intel Corporation [8086]" "Mobile 945GM/GMS, 943/940GML Express Integrated Graphics Controller [27a2]" -r03 "Acer Incorporated [ALI] [1025]" "Device [0110]"
#ex: 01:00.0 "VGA compatible controller [0300]" "nVidia Corporation [10de]" "G86 [GeForce 8400M GS] [0427]" -ra1 "Acer Incorporated [ALI] [1025]" "Device [011e]"

MANUFACTURER=""
#if currently running a generic driver, offer the upgrade...
if [ "`readlink /usr/bin/X`" == "Xvesa" ];then
 CURRENTDRIVER="Xvesa"
else
 CURRENTDRIVER="`grep '#card0driver' /etc/X11/xorg.conf | cut -f 2 -d '"'`" #'geany
 MANUFACTURER="`cat /etc/X11/xorg.conf | tr '\n' ' ' | tr '\t' ' ' | tr -s ' ' | grep -o '#card0driver .*' | grep -o 'VendorName "[^"]*' | cut -f 2 -d '"'`" #'geany
fi

#if multiple cards, find one most likely to be plugin...
[ "$MANUFACTURER" != "" ] && [ "`echo -n "$VIDEODETAILS" | grep "$MANUFACTURER"`" == "" ] && MANUFACTURER=""
[ "$MANUFACTURER" == "" ] && [ "`echo "$VIDEODETAILS" | grep 'nVidia Corporation'`" != "" ] && MANUFACTURER="nVidia Corporation"
[ "$MANUFACTURER" == "" ] && [ "`echo "$VIDEODETAILS" | grep 'Intel Corporation'`" != "" ] && MANUFACTURER="Intel Corporation"
[ "$MANUFACTURER" == "" ] && MANUFACTURER="`echo -n "$ONECARD" | cut -f 4 -d '"' | rev | cut -f 2-9 -d ' ' | rev`" #'geany
MANUFID="`echo -n "$VIDEODETAILS" | grep "$MANUFACTURER" | cut -f 4 -d '"' | rev | cut -f 2 -d ']' | cut -f 1 -d '[' | rev`" #'geany
DESCRIPTION="`echo -n "$VIDEODETAILS" | grep "$MANUFACTURER" | cut -f 6 -d '"' | rev | cut -f 2-12 -d ' ' | rev | sed -e 's%[^0-9a-zA-Z_ ,/]%%g'`" #'geany
DEVICEID="`echo -n "$VIDEODETAILS" | grep "$MANUFACTURER" | cut -f 6 -d '"' | rev | cut -f 2 -d ']' | cut -f 1 -d '[' | rev`" #'geany

#MANUFACTURER="nVidia Corporation" #TEST
#MANUFID='10DE' #TEST
#DEVICEID='0041' #TEST

HEADERMSG="<text><label>Your computer has an '${MANUFACTURER}' video chip:</label></text>
   <text use-markup=\"true\"><label>\"<b>${DESCRIPTION}</b>
PCI chip numbers: ${MANUFID}:${DEVICEID}\"</label></text>"

case "$MANUFACTURER" in
 "Intel Corporation") #8086:
  case $CURRENTDRIVER in
   vesa)
    GENERICMSG0="<text><label>X is currently using '${CURRENTDRIVER}' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances.</label></text>"
    GENERICMSG="<text><label>X is currently using '${CURRENTDRIVER}' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. If you want snappier performance, you might want to try this upgrade:</label></text>"
   ;;
   Xvesa)
    GENERICMSG0="<text><label>X is currently using '${CURRENTDRIVER}' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. Xvesa also has other limitations as it is not a true Xorg driver, for example the screen refresh frequency is not adjustable and you might notice flicker. You might also find video playing to be restricted.</label></text>"
    GENERICMSG="<text><label>X is currently using '${CURRENTDRIVER}' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. Xvesa also has other limitations as it is not a true Xorg driver, for example the screen refresh frequency is not adjustable and you might notice flicker. You might also find video playing to be restricted. If you want snappier performance, you might want to try this upgrade:</label></text>"
   ;;
   *)
    GENERICMSG0="<text><label>X is currently using the '${CURRENTDRIVER}' driver which is the correct driver for this chip. You really don't need to upgrade.</label></text>"
    GENERICMSG="<text><label>X is currently using the '${CURRENTDRIVER}' driver which is the correct driver for this chip. You really don't need to upgrade. However, some applications will be snappier if you install the Mesa package:</label></text>
    ${OFFER_MESA}
    <text use-markup=\"true\"><label>\"<span color='"'red'"' background='"'yellow'"'>It is recommended that you do <b>NOT</b> click any of the buttons below!</span>\"</label></text>"
    WARNMSG="" #101118
   ;;
  esac
  WARNMSG="" #101129
  INTEL_DEV_MSG="    <frame Developer files><hbox>
     <text><label>If you are a developer, or have any need to compile packages, then also download these two packages. The first has the extra files needed for compiling with the upgraded X. Note that this package may enable you to compile other advanced Xorg drivers, other than Intel, that will not work with the original X server and/or require KMS. The second package has DRI drivers for non-Intel hardware. If you are a user and know nothing about compiling, do not download these packages.</label></text>
     <vbox>
       <button><input file>/usr/local/lib/X11/pixmaps/x24.png</input>
       <action>/tmp/petupgradevideo.sh ${PET_UPGRADE_DEV} & </action></button>
       <button><input file>/usr/local/lib/X11/pixmaps/x24.png</input>
       <action>/tmp/petupgradevideo.sh ${PET_UPGRADE_DRI_EXTRA} & </action></button>
     </vbox>
   </hbox></frame>" #101205
  OFFER_MSG="<frame Upgrade Intel driver>${WARNMSG}<hbox>
     <text><label>Clicking this button will download and install Xorg server 1.6.0 and Intel driver 2.10.0. Please note that this is a fairly radical upgrade, that will run the kernel with KMS (Kernel Mode Setting) turned on and upgrades many files. If you have an Internet connection, click button (filesize is 7.5MB):</label></text>
     <vbox>
       <button><input file>/usr/local/video_upgrade/intel48x32.png</input>
       <action>/tmp/petupgradevideo.sh ${PET_UPGRADE_INTEL} & </action></button>
     </vbox>
   </hbox></frame>
   ${INTEL_DEV_MSG}
"
  if [ "$FLAG_UPGRADE_INTEL" = "done" ];then #101129
   GENERICMSG=""
   OFFER_MSG="<text use-markup=\"true\"><label>\"<span color='"'red'"' background='"'yellow'"'>Upgrade package '${PET_UPGRADE_INTEL}' already installed</span>\"</label></text>
   ${INTEL_DEV_MSG}"
  fi
 ;;
 "nVidia Corporation") #10DE:
  /usr/local/video_upgrade/which_nvidia_pkg $DEVICEID $PET_DB_FILE #writes to /tmp/vuw_nvidia_pkg. 101106 10112
  PET_NVIDIA="`cat /tmp/vuw_nvidia_pkg`"
  case $CURRENTDRIVER in
   vesa)
    GENERICMSG0="<text><label>X is currently using '${CURRENTDRIVER}' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances.</label></text>"
    GENERICMSG="<text><label>X is currently using '${CURRENTDRIVER}' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. If you want snappier performance, you might want to try this upgrade:</label></text>"
   ;;
   Xvesa)
    GENERICMSG0="<text><label>X is currently using '${CURRENTDRIVER}' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. Xvesa also has other limitations as it is not a true Xorg driver, for example the screen refresh frequency is not adjustable and you might notice flicker. You might also find video playing to be restricted.</label></text>"
    GENERICMSG="<text><label>X is currently using '${CURRENTDRIVER}' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. Xvesa also has other limitations as it is not a true Xorg driver, for example the screen refresh frequency is not adjustable and you might notice flicker. You might also find video playing to be restricted. If you want snappier performance, you might want to try this upgrade:</label></text>"
   ;;
   nv)
    GENERICMSG0="<text><label>X is currently using the 'nv' driver, which is the correct driver for this video hardware. This driver is satisfactory.</label></text>"
    GENERICMSG="<text><label>X is currently using the 'nv' driver, which is the correct driver for this video hardware. This driver is satisfactory. However, some applications will be snappier if you install the Mesa package:</label></text>
    ${OFFER_MESA}
    <text use-markup=\"true\"><label>\"Alternatively: the 'nv' driver may be noticeably slow with some graphics/video applications, and if you want faster rendering and more control over the display settings, you might want to <b>try the commercial nVidia driver</b>:\"</label></text>"
   ;;
   nvidia)
    GENERICMSG0="<text use-markup=\"true\"><label>\"<b>Currently using the 'nvidia' driver, so you have already upgraded!</b>\"</label></text>"
    GENERICMSG="<text use-markup=\"true\"><label>\"<b>Currently using the 'nvidia' driver, so you have already upgraded!</b>\"</label></text>"
   ;;
  esac
  if [ "$PET_NVIDIA" == "" ];then
   OFFER_MSG="<frame Commercial nVidia driver><text use-markup=\"true\"><label>\"<b>Sorry, do not have a PET package that supports your video chip. Suggest that you go to the nVidia website and download a driver (look in Puppy Forum for other users experiences with doing this)</b>\"</label></text></frame>"
  else
  
   if [ "`echo "$PET_NVIDIA" | grep 'nvidia_kmodule'`" != "" ];then #110827
    NVIDIA_BASE="`echo "$PET_NVIDIA" | grep '^nvidia_base' | tail -n 1`"
    NVIDIA_KMODULE="`echo "$PET_NVIDIA" | grep '^nvidia_kmodule' | tail -n 1`"
    if [ "`grep "$NVIDIA_BASE" /root/.packages/user-installed-packages`" = "" ];then
     PETSIZE=`grep "$NVIDIA_BASE" /root/.packages/${PET_DB_FILE} | head -n 1 | cut -f 6 -d '|' | rev | cut -c 2-9 | rev`
     PETSIZE2=`expr $PETSIZE \/ 3`
     SIZEUNIT="`grep "$NVIDIA_BASE" /root/.packages/${PET_DB_FILE} | head -n 1 | cut -f 6 -d '|' | rev | cut -c 1`"
     UNITS="KB"
     [ "$SIZEUNIT" = "M" ] && UNITS="MB"
     OFFER_MSG_BASE="<hbox>
     <text><label>Clicking this button will download and install '${NVIDIA_BASE}'. This is a closed-source commercial product, provided by nVidia Corporation. It gives maximum performance and also has a GUI to finetune the settings. (when installed will occupy ${PETSIZE}${UNITS}, the PET package to download is approx.  ${PETSIZE2}${UNITS}):</label></text>
     <vbox>
       <button><input file>/usr/local/video_upgrade/nvidia48x32.png</input>
       <action>/tmp/petupgradevideo.sh ${NVIDIA_BASE} & </action></button>
     </vbox>
     </hbox>
     <text><label>You must ALSO install the following package, please install both immediately, one after the other:</label></text>"
    else
     OFFER_MSG_BASE="<text><label>The 'nvidia_base' package has already been installed, so all that you need to do now is install the 'nvidia_kmodule' kernel driver. You should reboot afterward to activate it:</label></text>"
    fi
    PETSIZE=`grep "$NVIDIA_KMODULE" /root/.packages/${PET_DB_FILE} | head -n 1 | cut -f 6 -d '|' | rev | cut -c 2-9 | rev`
    PETSIZE2=`expr $PETSIZE \/ 3`
    SIZEUNIT="`grep "$NVIDIA_KMODULE" /root/.packages/${PET_DB_FILE} | head -n 1 | cut -f 6 -d '|' | rev | cut -c 1`"
    UNITS="KB"
    [ "$SIZEUNIT" = "M" ] && UNITS="MB"
    OFFER_MSG="<frame Commercial nVidia driver>${WARNMSG}
    ${OFFER_MSG_BASE}
    <hbox>
     <text><label>Clicking this button will download and install '${NVIDIA_KMODULE}'. This package has the kernel driver module. (when installed will occupy ${PETSIZE}${UNITS}, the PET package to download is approx.  ${PETSIZE2}${UNITS}):</label></text>
     <vbox>
       <button><input file>/usr/local/video_upgrade/nvidia48x32.png</input>
       <action>/tmp/petupgradevideo.sh ${NVIDIA_KMODULE} & </action></button>
     </vbox>
    </hbox></frame>"

   else #single pkg, as before...
    PET_NVIDIA="`echo "$PET_NVIDIA" | grep -v -E 'nvidia_base|nvidia_kmodule' | tail -n 1`"
    PETSIZE=`grep "$PET_NVIDIA" /root/.packages/${PET_DB_FILE} | head -n 1 | cut -f 6 -d '|' | rev | cut -c 2-9 | rev`
    PETSIZE2=`expr $PETSIZE \/ 3`
    SIZEUNIT="`grep "$PET_NVIDIA" /root/.packages/${PET_DB_FILE} | head -n 1 | cut -f 6 -d '|' | rev | cut -c 1`"
    UNITS="KB"
    [ "$SIZEUNIT" = "M" ] && UNITS="MB"
    OFFER_MSG="<frame Commercial nVidia driver>${WARNMSG}<hbox>
     <text><label>Clicking this button will download and install '${PET_NVIDIA}'. This is a closed-source commercial product, provided by nVidia Corporation. It gives maximum performance and also has a GUI to finetune the settings. (when installed will occupy ${PETSIZE}${UNITS}, the PET package to download is approx.  ${PETSIZE2}${UNITS}):</label></text>
     <vbox>
       <button><input file>/usr/local/video_upgrade/nvidia48x32.png</input>
       <action>/tmp/petupgradevideo.sh ${PET_NVIDIA} & </action></button>
     </vbox>
    </hbox></frame>"
   fi
  
  fi
 ;;
 "ATI Technologies Inc") #1002:
  /usr/local/video_upgrade/which_ati_pkg $DEVICEID $PET_DB_FILE #writes to /tmp/vuw_ati_pkg. 101106 101112
  PET_ATI="`cat /tmp/vuw_ati_pkg`"
  case $CURRENTDRIVER in
   vesa)
    GENERICMSG0="<text><label>X is currently using 'vesa' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances.</label></text>"
    GENERICMSG="<text><label>X is currently using 'vesa' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. If you want snappier performance, you might want to try this upgrade:</label></text>"
   ;;
   Xvesa)
    GENERICMSG0="<text><label>X is currently using 'Xvesa' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. Xvesa also has other limitations as it is not a true Xorg driver, for example the screen refresh frequency is not adjustable and you might notice flicker. You might also find video playing to be restricted.</label></text>"
    GENERICMSG="<text><label>X is currently using 'Xvesa' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. Xvesa also has other limitations as it is not a true Xorg driver, for example the screen refresh frequency is not adjustable and you might notice flicker. You might also find video playing to be restricted. If you want snappier performance, you might want to try this upgrade:</label></text>"
   ;;
   *)
    GENERICMSG0="<text><label>X is currently using the '${CURRENTDRIVER}' driver, which is the correct driver for this video hardware. This driver is satisfactory.</label></text>"
    GENERICMSG="<text><label>X is currently using the '${CURRENTDRIVER}' driver, which is the correct driver for this video hardware. This driver is satisfactory. However, some applications will be snappier if you install the Mesa package:</label></text>
    ${OFFER_MESA}
    <text use-markup=\"true\"><label>\"<b>Alternatively:</b> the '${CURRENTDRIVER}' driver is fine, but for even faster graphics/video rendering and more control over the display settings, you might want to <b>try the commercial ATI driver</b>:\"</label></text>"
   ;;
  esac
  #101205 nobody seems to have got my ati pet to work, remove for now...
  #if [ "$PET_ATI" == "" ];then #101106
   OFFER_MSG="<frame Commercial ATI driver><pixmap><input file>/usr/local/video_upgrade/ati48x32.png</input></pixmap><text use-markup=\"true\"><label>\"<b>Sorry, do (yet) not have a PET package that supports your video chip. Suggest that you go to the ATI website and download a driver (look in Puppy Forum for other users experiences with doing this)</b>\"</label></text></frame>"
  #else
  # PETSIZE=`grep "$PET_ATI" /root/.packages/${PET_DB_FILE} | head -n 1 | cut -f 6 -d '|' | rev | cut -c 2-9 | rev`
  # PETSIZE2=`expr $PETSIZE \/ 3`
  # SIZEUNIT="`grep "$PET_ATI" /root/.packages/${PET_DB_FILE} | head -n 1 | cut -f 6 -d '|' | rev | cut -c 1`"
  # UNITS="KB"
  # [ "$SIZEUNIT" = "M" ] && UNITS="MB"
  # OFFER_MSG="<frame Commercial ATI driver>${WARNMSG}<hbox>
  #   <text><label>Clicking this button will download and install '${PET_ATI}'. This is a closed-source commercial product, provided by ATI Corporation. It gives maximum performance and also has a GUI to finetune the settings. (when installed will occupy ${PETSIZE}${UNITS}, the PET package to download is approx.  ${PETSIZE2}${UNITS}):</label></text>
  #   <vbox>
  #     <button><input file>/usr/local/video_upgrade/ati48x32.png</input>
  #     <action>/tmp/petupgradevideo.sh ${PET_ATI} & </action></button>
  #   </vbox>
  # </hbox></frame>"
  #fi
 ;;
 *)
  case $CURRENTDRIVER in
   vesa)
    GENERICMSG="<text><label>X is currently using 'vesa' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances, however Wary does not have a hardware-specific driver for your video chip.</label></text>"
    GENERICMSG0="$GENERICMSG"
   ;;
   Xvesa)
    GENERICMSG="<text><label>X is currently using 'Xvesa' which is a generic unaccelerated driver. This driver is slow and you may notice the sluggishness under certain circumstances. Xvesa also has other limitations as it is not a true Xorg driver, for example the screen refresh frequency is not adjustable and you might notice flicker. You might also find video playing to be restricted. If possible, you should use the 'vesa' Xorg driver, that is another generic driver but is a true Xorg driver and is in msome ways superior. Sorry, but Wary does not have a hardware-specific Xorg driver for your video chip.</label></text>"
    GENERICMSG0="$GENERICMSG"
   ;;
   *)
    GENERICMSG0="<text><label>X is currently using the '${CURRENTDRIVER}' driver which is the correct driver for this chip. So, you have nothing more to do.</label></text>"
    GENERICMSG="<text><label>X is currently using the '${CURRENTDRIVER}' driver which is the correct driver for this chip. So, you have nothing more to do, however, some applications will be snappier if you install the Mesa package:</label></text>
    ${OFFER_MESA}"
   ;;
  esac
 ;;
esac

#   <hbox>
#     <vbox>
#       <button><input file>/usr/local/video_upgrade/nvidia48x32.png</input></button>
#     </vbox>
#   </hbox>
#   <hbox>
#     <vbox>
#       <button><input file>/usr/local/video_upgrade/ati48x32.png</input></button>
#     </vbox>
#   </hbox>


export VIDEOUPGRADE_DLG="<window title=\"Video Driver Upgrade Wizard\" icon-name=\"gtk-select-color\">
 <vbox>
   ${OFFMSG}
   ${HEADERMSG}
   ${GENERICMSG}
   ${OFFER_MSG}
   
   <hbox>
     <button><input file>/usr/local/lib/X11/mini-icons/mini.exit.xpm</input><action type=\"exit\">EXIT</action></button>
   </hbox>
 </vbox>
</window>
"

UPFLAG="`cat /root/.packages/woof-installed-packages /root/.packages/user-installed-packages | grep '^zzx_upgrade_73_'`"
ALTMSG=""
if [ "$UPFLAG" = "" ];then
 ALTMSG="<text><label>There is currently a choice of two different upgrade paths:</label></text>
 <frame Mesa/nVidia/ATI/Intel>
  <hbox>
   <text><label>This offers various upgrades depending on your current hardware. Probably best choice, see what is offered, if you don't like it then you can come back here go for the next option. Note, even if you have the correct driver for your hardware, the Mesa upgrade can improve performance, so do check this out:</label></text>
   <vbox>
   <button><input file>/usr/local/lib/X11/pixmaps/x24.png</input><action type=\"exit\">CHOICE1</action></button>
   </vbox>
  </hbox>
 </frame>
 
 <frame Xorg 7.5>
  <hbox>
   <text><label>Xorg is version 7.3. This option performs a major upgrade to Xorg 7.5. Even if you already have the correct driver for your hardware, this upgrade may improve behaviour (or may not). This option also includes Mesa for faster performance. If you are currently only able to use 'vesa' or 'Xvesa', this upgrade may find a correct hardware driver.</label></text>
   <vbox>
   <button><input file>/usr/local/lib/X11/pixmaps/x24.png</input><action type=\"exit\">CHOICE2</action></button>
   </vbox>
  </hbox>
 </frame>
 
 "
fi
 
#110105
export ALTUPGRADE_DLG="<window title=\"Video Driver Upgrade Wizard\" icon-name=\"gtk-select-color\">
 <vbox>
   ${OFFMSG}
   ${HEADERMSG}
   ${GENERICMSG0}
   ${ALTMSG}
   
   <hbox>
     <button><input file>/usr/local/lib/X11/mini-icons/mini.exit.xpm</input><action type=\"exit\">EXIT</action></button>
   </hbox>
 </vbox>
</window>
"

RETVALS="`gtkdialog3 --program=ALTUPGRADE_DLG`"
eval "$RETVALS"

case $EXIT in
 CHOICE1)
  gtkdialog3 --program=VIDEOUPGRADE_DLG
 ;;
 CHOICE2)
  PET_UPGRADE_XORG75="`grep '^zxx_upgrade_73_to_75_nokms\-' /root/.packages/${PET_DB_FILE} | cut -f 8 -d '|' | tail -n 1`"
  PET_UPGRADE_XORG75_DEV="`grep '^zxx_upgrade_73_to_75_nokms_DEV\-' /root/.packages/${PET_DB_FILE} | cut -f 8 -d '|' | tail -n 1`"
  export CHOICE2_DLG="<window title=\"Video Driver Upgrade Wizard\" icon-name=\"gtk-select-color\">
   <vbox>
    <hbox>
     <text><label>Click this button to download and install the upgrade to Xorg 7.5. The package is a bit big as it contains the complete mesa 7.6 package. The xorg-server is 1.7.5. Note that the most recent drivers are chosen that work without KMS (Kernel Mode Setting). (19MB):</label></text>
     <vbox>
      <button><input file>/usr/local/lib/X11/pixmaps/x24.png</input>
       <action>/tmp/petupgradevideo.sh ${PET_UPGRADE_XORG75} & </action>
      </button>
     </vbox>
    </hbox>
    <hbox>
     <text><label>FOR DEVELOPERS: If you want to compile source packages, you will need this package in addition to the above (4.2MB):</label></text>
     <vbox>
      <button><input file>/usr/local/lib/X11/pixmaps/x24.png</input>
       <action>/tmp/petupgradevideo.sh ${PET_UPGRADE_XORG75_DEV} & </action>
      </button>
     </vbox>
    </hbox>
    <hbox>
     <button><input file>/usr/local/lib/X11/mini-icons/mini.exit.xpm</input><action type=\"exit\">EXIT</action></button>
    </hbox>
   </vbox>
  </window>
  "
  gtkdialog3 --program=CHOICE2_DLG
 ;;
esac


###END###
