#!/usr/bin/ksh
##############################################################################
#
#  prepgnome2
#  
#    Usage: prepgnome2 [-f]
#       -f fast -- don't prompt the user up front.
#
#  Deinstall any "AIX Toolbox" rpm's that will conflict with installation
#  of GNOME 2.2.1 rpms.
#
#  These are mostly parts of GNOME 1.4, though some may be packages which
#  depend on GNOME 1.4.
##############################################################################
# (C) COPYRIGHT International Business Machines Corp. 2003
# All Rights Reserved
#
# Disclaimer:  This is an unsupported, unwarranted script provided
# for the convenience of users of the 'AIX Toolbox for Linux Applications'.
# It will automatically deinstall some RPMS from your system.
# Use at your own risk.
#
# No Warranty:
# THIS CODE IS PROVIDED BY IBM "AS IS." TO THE EXTENT PERMITTED BY APPLICABLE
# LAW, IBM MAKES NO WARRANTIES OR CONDITIONS EITHER EXPRESS OR IMPLIED,
# INCLUDING WITHOUT LIMITATION ANY WARRANTY OF NON-INFRINGEMENT AND THE
# IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
# REGARDING THE CODE OR TECHNICAL SUPPORT, IF ANY.
#
# Limitation of Liability:
# NEITHER IBM NOR ITS SUPPLIERS ARE LIABLE FOR ANY DIRECT OR INDIRECT DAMAGES,
# INCLUDING WITHOUT LIMITATION, LOST PROFITS, LOST SAVINGS, OR ANY INCIDENTAL,
# SPECIAL, OR OTHER ECONOMIC CONSEQUENTIAL DAMAGES, EVEN IF IBM IS INFORMED OF
# THEIR POSSIBILITY. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR
# LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THE ABOVE EXCLUSION OR
# LIMITATION MAY NOT APPLY TO YOU.
###############################################################################

export PATH=/usr/bin
CONDITIONAL_PKGS=

if [[ "$1" != "-f" ]] ; then
  cat <<EOF
WARNING:
  This script is provided to help prepare your system for installing
GNOME 2.2.1.  Running this will deinstall any packages that are known
to conflict with the GNOME 2.2.1 packages.  This means that if you
continue, most GNOME 1.4 packages will be removed.  You should not run
this from within a GNOME session.

  A few older GNOME-related packages will remain installed, such as earlier
versions of glib, gtk+, and other libraries.  While these are not requried
for GNOME 2.2.1, they do not interfere with it either, and you may have
other apps installed that use these older packages.
EOF

  echo "Proceed to deinstall Gnome 2.2.1 conflict RPMs on the system? y/(n) \c"
  read ans < /dev/tty
  if [ -z "$ans" ] || [ "$ans" != "y" ]
  then
    echo Exiting.
    exit 0
  fi
fi


# If gaim <= 0.52-1 is installed, we can't deinstall gnome-core and
# thus can't install GNOME2.  (You can still run gaim later; just
# install the newest rpm image.)
rpm -q --requires gaim | grep gnome-core >/dev/null 2>&1
[[ $? -eq 0 ]] && CONDITIONAL_PKGS="$CONDITIONAL_PKGS gaim"

# We should remove gnome-utils also, if pre-GNOME2.
# It shares the same name as the GNOME2 gnome-utils package
# (we have to remove it to remove gnome-core).
rpm -q gnome-utils >/dev/null 2>&1 
if [[ $? -eq 0 ]]; then
   # deinstall if < version 2.
   VER=$(rpm -q  --queryformat '%{version}\n' gnome-utils | cut -c1)
   [[ $VER -lt 2 ]] && CONDITIONAL_PKGS="$CONDITIONAL_PKGS gnome-utils"
fi

# Same story with control-center.  See above.
rpm -q control-center >/dev/null 2>&1 
if [[ $? -eq 0 ]]; then
   VER=$(rpm -q  --queryformat '%{version}\n' control-center | cut -c1)
   [[ $VER -lt 2 ]] && CONDITIONAL_PKGS="$CONDITIONAL_PKGS control-center"
fi

# See which of these images here are installed on the system.  Build
# a list of all that are installed, and then deinstall them.

CHECKLIST="$CONDITIONAL_PKGS pygnome-applet xmms-gnome gnome-core-devel \
 gnome-core sawfish-themer sawfish control-center-devel pygnome-capplet \
 bonobo-devel bonobo-conf-devel bonobo-conf bonobo xml-i18n-tools \
 gnome-vfs-devel gnome-vfs gnome-user-docs pygtk-libglade pygtk xscreensaver \
 pygnome-libglade pygnome gnumeric freetype2-devel libxml2-devel libxslt-devel"

DEINST=

for package in $CHECKLIST ; do
  rpm -q $package >/dev/null 2>&1 && DEINST="$DEINST $package"
done

echo "I will attempt to deinstall the following packages so that you can"
echo "install GNOME2 without conflicts:"
echo 
echo $DEINST
echo
if [[ "$1" != "-f" ]] ; then
  print -n "Shall I continue? (y/n) "
  read ans
  if [[ "$ans" != "y" ]] ; then
    echo "Skipping deinstall."
    exit 0
  fi
fi

echo "Deinstalling....."
rpm -e $DEINST
if [[ $? -ne 0 ]] ; then
  echo "There may have been errors in the deinstall, such as unexpected"
  echo "dependencies.  Please check the list and try deinstalling the"
  echo "images individually with rpm -e."
  exit 1
fi
echo "Deinstall complete; you may now install GNOME2 packages without conflicts."

exit 0
# END OF SCRIPT
