gnome-cleanup revision 15615
ac4e70ff8955669341f435bc0a734a17c01af124Mark Andrews#!/bin/ksh
5ae0e2c8b72fa44237edeb37d1945b1c3535ca39Automatic Updater#
5ae0e2c8b72fa44237edeb37d1945b1c3535ca39Automatic Updater# Cleans up the GNOME Desktop user configuration files. This
59dd3b3cd954239d98ef52cd26328856cb6f2975Automatic Updater# will return the user to the default desktop configuration.
59dd3b3cd954239d98ef52cd26328856cb6f2975Automatic Updater# Useful if the user's configuration has become corrupted.
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater#
59dd3b3cd954239d98ef52cd26328856cb6f2975Automatic Updater# By: Brian Cameron <Brian.Cameron@sun.com>
a3b428812703d22a605a9f882e71ed65f0ffdc65Mark Andrews
bb93c8542756719b53096b9939e4041d0966026fAutomatic Updater# The first argument can be a user name. If so, then the script
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater# will clean up the files for that specified user (if file
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# permissions permit). If no argument is given, the default value
ac4e70ff8955669341f435bc0a734a17c01af124Mark Andrews# is the current user.
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater#
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellingtonif [ $# -ge 1 ]; then
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater LOGNAME="$1"
5c0fc20d6e59216d9a142409e5fdb498153aeaa5Automatic Updater USRHOME=`echo ~$1`
56874aef380a64a2c183b7c282c3e7a361d67fa1Automatic Updaterelse
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews USRHOME="$HOME"
56874aef380a64a2c183b7c282c3e7a361d67fa1Automatic Updater if [ -z "$LOGNAME" ]; then
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews LOGNAME=`/usr/bin/logname`
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews fi
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsfi
04eba969cb9a54bbda2896db2067c07b2ac5ba16Automatic Updater
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews# Error if the directory for this user does not exist.
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews#
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrewsif [ ! -d "$USRHOME" ]; then
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews echo "\nError: user <$LOGNAME> does not exist on this system.\n"
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews exit 1
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafssonfi
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# If USRHOME is the root directory, just set USRHOME to nothing
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson# to avoid double-slash in the output since we refer to files
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# as $USRHOME/.gconf, for example.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington#
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updaterif [ "$USRHOME" = "/" ]; then
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews USRHOME=""
fc3576328379e813ccf6b3a6e66d9bb701a79c83Automatic Updaterfi
298c514fff250c1a147176cfbbc1c0ca441d1ea5Automatic Updater
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews# Check if GNOME is running:
bbb069be941f649228760edcc241122933c066d2Automatic Updater#
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark AndrewsGNOME_PROCESSES='(gnome-session|gconfd|gconfd-2|metacity|esd)'
3098364bcdd7a719fbafa5fc8d2cc9e90e5a5989Automatic UpdaterRUNNING_PROCESSES=`/usr/bin/pgrep -l -U $LOGNAME "$GNOME_PROCESSES"`
9d330c054e02f52cefd8dc0e71550b0fe07e077eAutomatic Updaterrc=$?
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsif [ $rc -ge 2 ]; then
ca904804e43f663f08eb1ac9d6d617930b9a3cd3Automatic Updater echo "\nError getting user process information for user <$LOGNAME>...\n"
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews exit 1
3a6600c8d319275d73c36eb625f77103cd83e824Automatic Updaterfi
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsif [ ! -z "$RUNNING_PROCESSES" ]; then
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews echo "\nThe following GNOME processes are still running for user <$LOGNAME>:\n"
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson echo "$RUNNING_PROCESSES"
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews echo "\nPlease log out user <$LOGNAME> from GNOME, so this user has no"
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews echo "GNOME processes running before using gnome-cleanup. For example,"
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews echo "log out, and log into a failsafe session to run gnome-cleanup."
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews echo ""
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson exit 1
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrewsfi
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson# Use disp_files to echo files back to the screen so that we don't expand
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# "tmp" wildcard directories like gvfs-${LOGNAME}, otherwise the output
d145b64cacc8d9cda51f9924ec70cd4661c3e2cfAutomatic Updater# is cumbersome to read since this will echo dozens of files to the screen.
bb93c8542756719b53096b9939e4041d0966026fAutomatic Updater#
2a31bd531072824ef252c18303859d6af7451b00Francis Dupontdisp_files=""
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont# GNOME 2.x files
2a31bd531072824ef252c18303859d6af7451b00Francis Dupont#
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsgnome_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"
6f046a065e5543f8cd7e2f24991c65d2372f4c8dMark Andrews
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrews# GNOME 1.4 files
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrews#
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsgnome_14_files="$USRHOME/.gnome-help-browser $USRHOME/.gnome_private $USRHOME/.thumbnails $USRHOME/Nautilus"
a8644ebab678a1de66cbfaabb513651a739958afAutomatic Updater
4b2cb1422c7c600fbc13b1cb06a8b4693bc11af8Mark Andrewscheck_files=`/bin/ls -d $gnome_files $gnome_14_files 2> /dev/null`
c651f15b30f1dae5cc2f00878fb5da5b3a35a468Mark Andrewsif [ ! -x "$check_files" ]
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updaterthen
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater disp_files="$disp_files\n$check_files"
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrewsfi
efb0e886f18894a1d2489f1ad74ad14b579e11c7Mark Andrews
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrews# tmp files
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson#
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrewstmp_dirs="/var/tmp $TEMPDIR $TMP $TEMP"
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrewstmp_files=""
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrewstmp_cleanup="gconfd-${LOGNAME} mapping-${LOGNAME} orbit-${LOGNAME} gvfs-${LOGNAME}*"
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson
aa1d397c4736cd86540555193d71e55fa3b37b2aMark Andrewsfor dir in $tmp_dirs; do
d145b64cacc8d9cda51f9924ec70cd4661c3e2cfAutomatic Updater for cleanup in $tmp_cleanup; do
19b3dc94bce93fa76bd7e066f9298630dbc9dcb4Automatic Updater tmp_files="$dir/$cleanup $tmp_files"
bb93c8542756719b53096b9939e4041d0966026fAutomatic Updater
bb93c8542756719b53096b9939e4041d0966026fAutomatic Updater check_files=`/bin/ls -d $dir/$cleanup 2> /dev/null`
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater if [ ! -x "$check_files" ]
5ae0e2c8b72fa44237edeb37d1945b1c3535ca39Automatic Updater then
4cda4fd158d6ded5586bacea8c388445d99611eaAutomatic Updater disp_files="$disp_files\n$dir/$cleanup"
3098364bcdd7a719fbafa5fc8d2cc9e90e5a5989Automatic Updater fi
19b3dc94bce93fa76bd7e066f9298630dbc9dcb4Automatic Updater done
d145b64cacc8d9cda51f9924ec70cd4661c3e2cfAutomatic Updaterdone
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater
5ae0e2c8b72fa44237edeb37d1945b1c3535ca39Automatic Updaterhas_files=`/bin/ls -d $tmp_files $gnome_files $gnome_14_files 2> /dev/null`
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updaterif [ ! -z "$has_files" ]
5ae0e2c8b72fa44237edeb37d1945b1c3535ca39Automatic Updaterthen
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater echo "\nUser <$LOGNAME> currently has the following GNOME configuration files:"
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater echo "$disp_files"
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater echo "\nDo you wish to remove these files (Y/N) \c"
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater read input;
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater if [ "$input" = "Y" -o "$input" = "y" ]
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater then
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater /bin/rm -fR $has_files
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater rc=$?
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater if [ $rc = 0 ]; then
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater echo "Removed..."
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater else
19b3dc94bce93fa76bd7e066f9298630dbc9dcb4Automatic Updater echo "Error removing files..."
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater fi
19b3dc94bce93fa76bd7e066f9298630dbc9dcb4Automatic Updater else
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater echo "Not removed..."
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater fi
19b3dc94bce93fa76bd7e066f9298630dbc9dcb4Automatic Updater echo ""
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updaterelse
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updater echo "\nUser $LOGNAME does not have any GNOME configuration files.\n"
ce9cad6bb04869c5e94d9dc721032b25117f9210Automatic Updaterfi
ea935c46e8261ea10621e5b038426539fe8a7cc5Mark Andrews