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