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 ""
     28    echo "Error: user $LOGNAME does not exist on this system."
     29    echo ""
     30    exit 1
     31 fi
     32 
     33 # If USRHOME is the root directory, just set USRHOME to nothing
     34 # to avoid double-slash in the output since we refer to files
     35 # as $USRHOME/.gconf, for example.
     36 #
     37 if [ "$USRHOME" = "/" ]; then
     38    USRHOME=""
     39 fi
     40 
     41 # Check if GNOME is running:
     42 #
     43 GNOME_PROCESSES='(gnome-session|gconfd|gconfd-2|metacity|esd)'
     44 RUNNING_PROCESSES=`/usr/bin/pgrep -l -U $LOGNAME "$GNOME_PROCESSES"`
     45 rc=$?
     46 if [ $rc -ge 2 ]; then
     47    echo ""
     48    echo "Error getting user process information for user $LOGNAME..."
     49    echo ""
     50    exit 1
     51 fi
     52 
     53 if [ ! -z "$RUNNING_PROCESSES" ]; then
     54    echo ""
     55    echo "The following GNOME processes are still running for user $LOGNAME:"
     56    echo ""
     57    echo "$RUNNING_PROCESSES"
     58    echo ""
     59    echo "Please log out user $LOGNAME from GNOME, so this user has no"
     60    echo "GNOME processes running before using gnome-cleanup.  For example,"
     61    echo "log out, and log into a failsafe session to run gnome-cleanup."
     62    echo ""
     63    exit 1
     64 fi
     65 
     66 # GNOME 2.x files
     67 #
     68 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"
     69 
     70 # GNOME 1.4 files
     71 #
     72 gnome_14_files="$USRHOME/.gimp-1.2 $USRHOME/.gnome-help-browser $USRHOME/.gnome_private $USRHOME/.thumbnails $USRHOME/Nautilus"
     73 
     74 # /var/tmp files
     75 #
     76 var_tmp_dirs1="/var/tmp/gconfd-${LOGNAME} /var/tmp/mapping-${LOGNAME} /var/tmp/orbit-${LOGNAME}"
     77 
     78 # Also check the TMP environment variable for /var/tmp files.
     79 #
     80 var_tmp_dirs2="$TMP/gconfd-${LOGNAME} $TMP/mapping-${LOGNAME} $TMP/orbit-${LOGNAME}"
     81 
     82 has_files=`/bin/ls -1d $gnome_files $gnome_14_files $var_tmp_dirs1 $var_tmp_dirs2 2> /dev/null`
     83 
     84 if [ ! -z "$has_files" ]
     85 then
     86    echo ""
     87    echo "User $LOGNAME currently has the following GNOME configuration files:"
     88    echo ""
     89    echo "$has_files"
     90    echo ""
     91    echo "Do you wish to remove these files (Y/N) \c"
     92    read input;
     93 
     94    if [ "$input" = "Y" -o "$input" = "y" ]
     95    then
     96       /bin/rm -fR $has_files
     97       rc=$?
     98       if [ $rc = 0 ]; then
     99          echo "Removed..."
    100       else
    101          echo "Error removing files..."
    102       fi
    103    else
    104       echo "Not removed..."
    105    fi
    106    echo ""
    107 else
    108    echo ""
    109    echo "User $LOGNAME does not have any GNOME configuration files."
    110    echo ""
    111 fi
    112