#! /bin/sh

# Purge GConf database and remove obsolete and orphan GNOME
# directories and files.
#
# NOTE: This script requires find and coreutils installed.
#
exec >/var/log/YaST2/gnome-preinstall.log
exec 2>&1
shopt -s nullglob

# Remove complete gconf database. Make a back-up link of old entries.
# After installation those back-ups will be checked, and
# for not-updated ones database entries will be re-built.
# (This will save some time during update.)
if test -d $1/etc/opt/gnome/gconf/schemas ; then
    mkdir -p $1/etc/opt/gnome/gconf/schemas-old
    cd /etc/opt/gnome/gconf/schemas
    for SCHEMAS in * ; do
	ln $SCHEMAS ../schemas-old
    done
fi

# These files and directories are obsolete, and should be removed with its contents.
# /etc/opt/gnome/gconf/gconf.xml.defaults and
# /etc/opt/gnome/gconf/gconf.xml.mandatory are not obsolete, but will be re-generated.
for DIR in \
/etc/opt/gnome/gconf/gconf.xml.defaults \
/etc/opt/gnome/gconf/gconf.xml.mandatory \
/etc/sysconfig/gconf2\
/etc/opt/gnome/gconf/preconf \
/etc/opt/gnome/gconf/schema-install-source \
/etc/opt/gnome/gconf/su \
/etc/opt/gnome/SuSE \
/etc/opt/gnome/share/gnome/distribution-menus \
/etc/opt/gnome2/gconf/2 \
/etc/opt/gnome2/gconf/gconf.xml.defaults \
/etc/opt/gnome2/gconf/schema-install-source \
/etc/opt/gnome/SuSE-quickmenu \
/etc/opt/gnome/X11/applnk \
/etc/gtk-2.0/gdk-pixbuf.loaders \
/etc/gtk-2.0/gtk.immodules \
/etc/pango/pango.modules \
/opt/gnome2/share/mime-info/realplay.keys \
/opt/gnome2/share/mime-info/realplay.mime \
/opt/gnome2/share/applications/realplayer.desktop \
/opt/gnome2/share/apps/Multimedia/realplayer.desktop \
/opt/gnome2/share/dist/installed_schemas_su \
/usr/share/themes/REMOVE_IN_PROGRESS \
/var/opt/gnome2/cache/gstreamer-0.6/registry.xml
  do
  rm -rfv "$1$DIR"
done

# Symlinks to /usr/share/themes in this directory are obsolete
# (created in 8.2 by gtk YOU).
find 2>/dev/null "$1"/opt/gnome2/share/themes -type l -exec sh -c "if ls -l \"{}\" | sed 's/.*-> //' | fgrep usr/share/themes ; then rm -v \"{}\" ; fi" \;
