Home | History | Annotate | Download | only in ext-sources
      1 #!/bin/ksh
      2 #
      3 # Cleans up the GNOME Desktop user configuration files.  This
      4 # will return the user to the default desktop configuration.
      5 # Useful if the user's configuration has become corrupted.
      6 # 
      7 # By: Brian Cameron <Brian.Cameron (at] sun.com>
      8 
      9 # The first argument can be a user name.  If so, then the script
     10 # will clean up the files for that specified user (if file
     11 # permissions permit).  If no argument is given, the default value
     12 # is the current user.
     13 #
     14 if [ $# -ge 1 ]; then
     15   LOGNAME="$1"
     16   USRHOME=`echo ~$1`
     17 else
     18   USRHOME="$HOME"
     19   if [ -z "$LOGNAME" ]; then
     20     LOGNAME=`/usr/bin/logname`
     21   fi
     22 fi
     23 
     24 # Error if the directory for this user does not exist.
     25 #
     26 if [ ! -d "$USRHOME" ]; then
     27    echo "\nError: user <$LOGNAME> does not exist on this system.\n"
     28    exit 1
     29 fi
     30 
     31 # If USRHOME is the root directory, just set USRHOME to nothing
     32 # to avoid double-slash in the output since we refer to files
     33 # as $USRHOME/.gconf, for example.
     34 #
     35 if [ "$USRHOME" = "/" ]; then
     36    USRHOME=""
     37 fi
     38 
     39 # Check if GNOME is running:
     40 #
     41 GNOME_PROCESSES='(gnome-session|gconfd|gconfd-2|metacity|esd)'
     42 RUNNING_PROCESSES=`/usr/bin/pgrep -l -U $LOGNAME "$GNOME_PROCESSES"`
     43 rc=$?
     44 if [ $rc -ge 2 ]; then
     45    echo "\nError getting user process information for user <$LOGNAME>...\n"
     46    exit 1
     47 fi
     48 
     49 if [ ! -z "$RUNNING_PROCESSES" ]; then
     50    echo "\nThe following GNOME processes are still running for user <$LOGNAME>:\n"
     51    echo "$RUNNING_PROCESSES"
     52    echo "\nPlease log out user <$LOGNAME> from GNOME, so this user has no"
     53    echo "GNOME processes running before using gnome-cleanup.  For example,"
     54    echo "log out, and log into a failsafe session to run gnome-cleanup."
     55    echo ""
     56    exit 1
     57 fi
     58 
     59 # Use disp_files to echo files back to the screen so that we don't expand
     60 # "tmp" wildcard directories like gvfs-${LOGNAME}, otherwise the output
     61 # is cumbersome to read since this will echo dozens of files to the screen.
     62 #
     63 disp_files=""
     64 
     65 # GNOME 2.x files
     66 #
     67 gnome_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 $USRHOME/.config"
     68 
     69 # GNOME 1.4 files
     70 #
     71 gnome_14_files="$USRHOME/.gnome-help-browser $USRHOME/.gnome_private $USRHOME/.thumbnails $USRHOME/Nautilus"
     72 
     73 check_files=`/bin/ls -d $gnome_files $gnome_14_files 2> /dev/null`
     74 if [ ! -x "$check_files" ]
     75 then
     76    disp_files="$disp_files\n$check_files"
     77 fi
     78 
     79 # tmp files
     80 #
     81 tmp_dirs="/var/tmp $TEMPDIR $TMP $TEMP"
     82 tmp_files=""
     83 
     84 tmp_cleanup="gconfd-${LOGNAME} mapping-${LOGNAME} orbit-${LOGNAME} gvfs-${LOGNAME}*"
     85 
     86 for dir in $tmp_dirs; do
     87    for cleanup in $tmp_cleanup; do
     88       tmp_files="$dir/$cleanup $tmp_files"
     89 
     90       check_files=`/bin/ls -d $dir/$cleanup 2> /dev/null`
     91       if [ ! -x "$check_files" ]
     92       then
     93          disp_files="$disp_files\n$dir/$cleanup"
     94       fi
     95    done
     96 done
     97    
     98 has_files=`/bin/ls -d $tmp_files $gnome_files $gnome_14_files 2> /dev/null`
     99 has_user_files=`/bin/ls -d $gnome_files $gnome_14_files 2> /dev/null`
    100 
    101 if [ ! -z "$has_files" ]
    102 then
    103    echo "\nUser <$LOGNAME> currently has the following GNOME configuration files:"
    104    echo "$disp_files"
    105    echo "\nDo you wish to remove these files (Y/N) \c"
    106    read input;
    107 
    108    if [ "$input" = "Y" -o "$input" = "y" ]
    109    then
    110       # Back up files for debugging.
    111       date=`/usr/bin/date +%F-%H:%M:%S`
    112       tarfile="/tmp/gnome-cleanup-$LOGNAME-$date.tar"
    113       /usr/bin/tar -cf $tarfile $has_user_files
    114 
    115       /bin/rm -fR $has_files
    116       rc=$?
    117       if [ $rc = 0 ]; then
    118          echo "\nRemoved..."
    119          echo "\nThe files removed from the user \$HOME directory have been"
    120          echo "backed up to the following file:"
    121          echo "\n$tarfile"
    122          echo "\nIf you ran this program to resolve an issue that was caused"
    123          echo "by the GNOME desktop not functioning properly, then please"
    124          echo "report a bug at http://defect.opensolaris.org/."
    125          echo "\nNote that configuration files may contain sensitive"
    126          echo "information about you.  If this is a concern, then it is best"
    127          echo "to not attach this tar file to a publicly visible bug report."
    128          echo "If this is not an issue, then attaching this file would likely"
    129          echo "help to debug the problem.  Also note that files in the /tmp"
    130          echo "directory are removed automatically on reboot, so move this"
    131          echo "file to a more permanent location if you want to save it for"
    132          echo "reference or future use."
    133       else
    134          echo "Error removing files..."
    135       fi
    136    else
    137       echo "Not removed..."
    138    fi
    139    echo ""
    140 else
    141    echo "\nUser $LOGNAME does not have any GNOME configuration files.\n"
    142 fi
    143