#!/bin/ksh
#
# Cleans up the GNOME Desktop user configuration files. This
# will return the user to the default desktop configuration.
# Useful if the user's configuration has become corrupted.
#
# By: Brian Cameron <[email protected]>
# The first argument can be a user name. If so, then the script
# will clean up the files for that specified user (if file
# permissions permit). If no argument is given, the default value
# is the current user.
#
if [ $# -ge 1 ]; then
LOGNAME="$1"
USRHOME=`echo ~$1`
else
USRHOME="$HOME"
if [ -z "$LOGNAME" ]; then
LOGNAME=`/usr/bin/logname`
fi
fi
# Error if the directory for this user does not exist.
#
if [ ! -d "$USRHOME" ]; then
echo ""
echo "Error: user $LOGNAME does not exist on this system."
echo ""
exit 1
fi
# If USRHOME is the root directory, just set USRHOME to nothing
# to avoid double-slash in the output since we refer to files
# as $USRHOME/.gconf, for example.
#
if [ "$USRHOME" = "/" ]; then
USRHOME=""
fi
# Check if GNOME is running:
#
GNOME_PROCESSES='(gnome-session|gconfd|gconfd-2|metacity|esd)'
RUNNING_PROCESSES=`/usr/bin/pgrep -l -U $LOGNAME "$GNOME_PROCESSES"`
rc=$?
if [ $rc -ge 2 ]; then
echo ""
echo "Error getting user process information for user $LOGNAME..."
echo ""
exit 1
fi
if [ ! -z "$RUNNING_PROCESSES" ]; then
echo ""
echo "The following GNOME processes are still running for user $LOGNAME:"
echo ""
echo "$RUNNING_PROCESSES"
echo ""
echo "Please log out user $LOGNAME from GNOME, so this user has no"
echo "GNOME processes running before using gnome-cleanup. For example,"
echo "log out, and log into a failsafe session to run gnome-cleanup."
echo ""
exit 1
fi
# GNOME 2.x files
#
gnome_files="$USRHOME/.gconf $USRHOME/.gconfd $USRHOME/.gnome $USRHOME/.gnome-desktop $USRHOME/.gnome2 $USRHOME/.gnome2_private $USRHOME/.metacity $USRHOME/.nautilus $USRHOME/.esd_auth $USRHOME/.gtkrc $USRHOME/.gtkrc-1.2-gnome2 $USRHOME/.nautilus-metafile.xml $USRHOME/.gstreamer-0.10 $USRHOME/.local/share"
# GNOME 1.4 files
#
gnome_14_files="$USRHOME/.gimp-1.2 $USRHOME/.gnome-help-browser $USRHOME/.gnome_private $USRHOME/.thumbnails $USRHOME/Nautilus"
# /var/tmp files
#
var_tmp_dirs1="/var/tmp/gconfd-${LOGNAME} /var/tmp/mapping-${LOGNAME} /var/tmp/orbit-${LOGNAME}"
# Also check the TMP environment variable for /var/tmp files.
#
var_tmp_dirs2="$TMP/gconfd-${LOGNAME} $TMP/mapping-${LOGNAME} $TMP/orbit-${LOGNAME}"
has_files=`/bin/ls -1d $gnome_files $gnome_14_files $var_tmp_dirs1 $var_tmp_dirs2 2> /dev/null`
if [ ! -z "$has_files" ]
then
echo ""
echo "User $LOGNAME currently has the following GNOME configuration files:"
echo ""
echo "$has_files"
echo ""
echo "Do you wish to remove these files (Y/N) \c"
read input;
if [ "$input" = "Y" -o "$input" = "y" ]
then
/bin/rm -fR $has_files
rc=$?
if [ $rc = 0 ]; then
echo "Removed..."
else
echo "Error removing files..."
fi
else
echo "Not removed..."
fi
echo ""
else
echo ""
echo "User $LOGNAME does not have any GNOME configuration files."
echo ""
fi