#! /bin/bash

if test "$UID" != 0 -a "$USER" != root; then
    echo "You must be root to start $0."
    exit 1
fi

echo "Rebuilding gconf schemas database from scratch in 5 seconds."
sleep 5
echo "Rebuilding..."

rm -rf /etc/opt/gnome/gconf/gconf.xml.defaults /etc/opt/gnome/gconf/gconf.xml.mandatory
umask 0022
mkdir /etc/opt/gnome/gconf/gconf.xml.defaults /etc/opt/gnome/gconf/gconf.xml.mandatory

export GCONF_CONFIG_SOURCE=`/opt/gnome/bin/gconftool-2 --get-default-source`
shopt -s nullglob
cd /etc/opt/gnome/gconf/schemas

for SCHEMAS in /etc/opt/gnome/gconf/schemas/*.schemas ; do
    /opt/gnome/bin/gconftool-2 --makefile-install-rule $SCHEMAS >/dev/null
done

for SCHEMAS in /etc/opt/gnome/gconf/schemas/*.entries ; do
    /opt/gnome/bin/gconftool-2 --direct --config-source=$GCONF_CONFIG_SOURCE --load $SCHEMAS
done

if test -d /usr/local/etc/gconf/schemas ; then
    cd /usr/local/etc/gconf/schemas

    for SCHEMAS in /usr/local/etc/gconf/schemas/*.schemas ; do
	/opt/gnome/bin/gconftool-2 --makefile-install-rule $SCHEMAS >/dev/null
    done

    for SCHEMAS in /usr/local/etc/gconf/schemas/*.entries ; do
	/opt/gnome/bin/gconftool-2 --direct --config-source=$GCONF_CONFIG_SOURCE --load $SCHEMAS
    done
fi

echo "Done."
