#! /bin/sh

# source debconf library
. /usr/share/debconf/confmodule

#############################################################
# Change default gconf path file so it uses desktop-profiles
# IF (and only if) the user explicitly agreed to this
#############################################################
db_get desktop-profiles/replace-gconf-system-wide-path-file || true
if (test "$RET" = true); then
  # if gconf 2 path file is present and doesn't include the generated path file
  # then replace path file
  if (test -e /etc/gconf/2/path) ; then
    if ! ( (grep '/var/cache/desktop-profiles/\$(USER)_mandatory.path' /etc/gconf/2/path > /dev/null) ||
           (grep '/var/cache/desktop-profiles/\$(USER)_defaults.path'  /etc/gconf/2/path > /dev/null) ); then
      mv /etc/gconf/2/path /etc/gconf/2/path.pre-desktop-profiles;
      cp /usr/share/doc/desktop-profiles/examples/path /etc/gconf/2/path;
    fi;
  # if gconf 1 path file is present and doesn't include the generated path file
  # then replace path file
  elif (test -e /etc/gconf/2/path) ; then
    if ! ( (grep '/var/cache/desktop-profiles/\$(USER)_mandatory.path' /etc/gconf/1/path > /dev/null) ||
           (grep '/var/cache/desktop-profiles/\$(USER)_defaults.path'  /etc/gconf/1/path > /dev/null) ); then
      mv /etc/gconf/2/path /etc/gconf/1/path.pre-desktop-profiles;
      cp -f /usr/share/doc/desktop-profiles/examples/path /etc/gconf/1/path;
    fi;
  fi;  
fi;

#DEBHELPER#
