#!/bin/sh
#

PATH=/bin:/usr/bin:/usr/ucb:/usr/sbin:/etc:/usr/etc
export PATH
umask 022

DotFiles=".Xdefaults .Xstartup .cshrc .login .logout .mh_profile \
    .mycshrc .mylogin .mylogout .xsession .gnome .gnome-desktop \
    .gnome_private .gnome2 .gnome2_private .metacity \
    .nautilus .gconf .gconfd .kde .kderc .Xclients .Xclients-default \
    .dmrc .mybashrc .bashrc .bash_profile .bash_logout \
    .cache .config"
PID=$$

cd

for dot in $DotFiles
do
    if [ -e $dot ]; then
	mv $dot $dot.$PID 2>/dev/null
    fi
done

PROTO=/afs/.../common/prototype_user

if [ -d $PROTO ]; then
    cp $PROTO/.cshrc        .cshrc
    cp $PROTO/.login        .login
    cp $PROTO/.bashrc       .bashrc
    cp $PROTO/.bash_logout  .bash_logout
    cp $PROTO/.bash_profile .bash_profile
fi

# Whack Firefox prefs via local wrapper script.
if [ -x /usr/local/bin/firefox ] ; then
    /usr/local/bin/firefox -repair > /dev/null 2>&1
fi

# Deal with Google Chrome
# Find the latest .config/google-chrome directory and rescue it
CHROME=nochrome
for i in `ls -d $HOME/.config*` ; do
    if [ "$CHROME" = "nochrome" ] ; then
        CHROME=$i
    elif [ $i -nt $CHROME ] ; then
        CHROME=$i
    fi
done

if [ "$CHROME" != "nochrome" -a -d $CHROME/google-chrome/Default ] ; then
    mkdir -p $HOME/.config/google-chrome/Default
    cp -f $CHROME/google-chrome/Default/Bookmarks.bak \
        $HOME/.config/google-chrome/Default/Bookmarks
fi

exit 0
