gnome-cleanup revision 15676
1203N/A#!/bin/ksh
1203N/A#
1204N/A# Cleans up the GNOME Desktop user configuration files. This
1203N/A# will return the user to the default desktop configuration.
1203N/A# Useful if the user's configuration has become corrupted.
1203N/A#
1204N/A# By: Brian Cameron <Brian.Cameron@sun.com>
1203N/A
1203N/A# The first argument can be a user name. If so, then the script
1204N/A# will clean up the files for that specified user (if file
1203N/A# permissions permit). If no argument is given, the default value
1203N/A# is the current user.
1203N/A#
1203N/Aif [ $# -ge 1 ]; then
1203N/A LOGNAME="$1"
1204N/A USRHOME=`echo ~$1`
1203N/Aelse
1203N/A USRHOME="$HOME"
1203N/A if [ -z "$LOGNAME" ]; then
1203N/A LOGNAME=`/usr/bin/logname`
1203N/A fi
1203N/Afi
1203N/A
1203N/A# Error if the directory for this user does not exist.
1203N/A#
1203N/Aif [ ! -d "$USRHOME" ]; then
1203N/A echo "\nError: user <$LOGNAME> does not exist on this system.\n"
1203N/A exit 1
1203N/Afi
1203N/A
1203N/A# If USRHOME is the root directory, just set USRHOME to nothing
1203N/A# to avoid double-slash in the output since we refer to files
1203N/A# as $USRHOME/.gconf, for example.
1203N/A#
1203N/Aif [ "$USRHOME" = "/" ]; then
1203N/A USRHOME=""
1203N/Afi
1203N/A
1203N/A# Check if GNOME is running:
1203N/A#
1203N/AGNOME_PROCESSES='(gnome-session|gconfd|gconfd-2|metacity|esd)'
1203N/ARUNNING_PROCESSES=`/usr/bin/pgrep -l -U $LOGNAME "$GNOME_PROCESSES"`
1203N/Arc=$?
1203N/Aif [ $rc -ge 2 ]; then
1203N/A echo "\nError getting user process information for user <$LOGNAME>...\n"
1203N/A exit 1
1203N/Afi
1203N/A
1203N/Aif [ ! -z "$RUNNING_PROCESSES" ]; then
1203N/A echo "\nThe following GNOME processes are still running for user <$LOGNAME>:\n"
1203N/A echo "$RUNNING_PROCESSES"
1203N/A echo "\nPlease log out user <$LOGNAME> from GNOME, so this user has no"
1203N/A echo "GNOME processes running before using gnome-cleanup. For example,"
1203N/A echo "log out, and log into a failsafe session to run gnome-cleanup."
1203N/A echo ""
1203N/A exit 1
1203N/Afi
1203N/A
1203N/A# Use disp_files to echo files back to the screen so that we don't expand
1203N/A# "tmp" wildcard directories like gvfs-${LOGNAME}, otherwise the output
1203N/A# is cumbersome to read since this will echo dozens of files to the screen.
1203N/A#
1203N/Adisp_files=""
1203N/A
1203N/A# GNOME 2.x files
1203N/A#
1203N/Agnome_files="$USRHOME/.dbus $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/registry.* $USRHOME/.local/share"
1203N/A
1203N/A# GNOME 1.4 files
1203N/A#
1203N/Agnome_14_files="$USRHOME/.gnome-help-browser $USRHOME/.gnome_private $USRHOME/.thumbnails $USRHOME/Nautilus"
1203N/A
1203N/Acheck_files=`/bin/ls -d $gnome_files $gnome_14_files 2> /dev/null`
1203N/Aif [ ! -x "$check_files" ]
1203N/Athen
1203N/A disp_files="$disp_files\n$check_files"
1203N/Afi
1203N/A
1203N/A# tmp files
1203N/A#
1203N/Atmp_dirs="/var/tmp $TEMPDIR $TMP $TEMP"
1203N/Atmp_files=""
1203N/A
1203N/Atmp_cleanup="gconfd-${LOGNAME} mapping-${LOGNAME} orbit-${LOGNAME} gvfs-${LOGNAME}*"
1203N/A
1203N/Afor dir in $tmp_dirs; do
1203N/A for cleanup in $tmp_cleanup; do
tmp_files="$dir/$cleanup $tmp_files"
check_files=`/bin/ls -d $dir/$cleanup 2> /dev/null`
if [ ! -x "$check_files" ]
then
disp_files="$disp_files\n$dir/$cleanup"
fi
done
done
has_files=`/bin/ls -d $tmp_files $gnome_files $gnome_14_files 2> /dev/null`
has_user_files=`/bin/ls -d $gnome_files $gnome_14_files 2> /dev/null`
if [ ! -z "$has_files" ]
then
echo "\nUser <$LOGNAME> currently has the following GNOME configuration files:"
echo "$disp_files"
echo "\nDo you wish to remove these files (Y/N) \c"
read input;
if [ "$input" = "Y" -o "$input" = "y" ]
then
# Back up files for debugging.
date=`/usr/bin/date +%F-%H:%M:%S`
tarfile="/tmp/gnome-cleanup-$LOGNAME-$date.tar"
/usr/bin/tar -cf $tarfile $has_user_files
/bin/rm -fR $has_files
rc=$?
if [ $rc = 0 ]; then
echo "\nRemoved..."
echo "\nThe files removed from the user \$HOME directory have been"
echo "backed up to the following file:"
echo "\n$tarfile"
echo "\nIf you ran this program to resolve an issue that was caused"
echo "by the GNOME desktop not functioning properly, then please"
echo "report a bug at http://defect.opensolaris.org/."
echo "\nNote that configuration files may contain sensitive"
echo "information about you. If this is a concern, then it is best"
echo "to not attach this tar file to a publicly visible bug report."
echo "If this is not an issue, then attaching this file would likely"
echo "help to debug the problem. Also note that files in the /tmp"
echo "directory are removed automatically on reboot, so move this"
echo "file to a more permanent location if you want to save it for"
echo "reference or future use."
else
echo "Error removing files..."
fi
else
echo "Not removed..."
fi
echo ""
else
echo "\nUser $LOGNAME does not have any GNOME configuration files.\n"
fi