:
rcsid1='$Header: Self-extracting archive and installation program by Ted Lyngmo (ted@lyncon.se). $'
rcsid2='$Header: compfold - Netscape folder background compression utility $'
echo $rcsid1
echo $rcsid2
EOF=+2754
TMP=/tmp/$$.cfd
USER=`whoami`
OWD=`pwd`
DIR=`dirname $0`
cd $DIR
DIR=`pwd`
PROG=`basename $0`
PROG=$DIR/$PROG
NETSCAPE=~/.netscape
ABORT=0
DIRS=""
MAIL_DIR="nsmail mail Mail"
mdir=x
eval NETSCAPE=$NETSCAPE
eval PREFS=$NETSCAPE/preferences

abort() {
   ABORT=1
   echo "Aborting installation."
   exit
}

trap abort INT

cd $HOME

if [ ! -r $PREFS ]
then
    echo
    echo "Couldn't find $PREFS"
else
    MAIL_DIR="$MAIL_DIR `grep "^MAIL_DIR:" $PREFS|awk '{ print $2 }'`"
fi

echo
echo "Press <RETURN> on an empty line when done."
while [ "$mdir" != "" ]
do
    echo "Enter a Netscape folder directory for compfold to scan: \c"
    read mdir
    MAIL_DIR="$MAIL_DIR $mdir"
done

for mdir in $MAIL_DIR
do
    eval mdir=$mdir
    if [ -d "$mdir" ]
    then
	cd $mdir
        res="$res `pwd`"
	cd $HOME
    else
	echo "I couldn't find the Netscape folder directory \"$mdir\"."
    fi
done

MAIL_DIR=`echo $res | awk '{ for(i=1;i<=NF;i++)print $i }' | sort -u | tr '\012' ' '`

for mdir in $MAIL_DIR
do
    echo
    ls $mdir
    echo
    echo "The above listing shows the contents of $mdir."
    echo "Do you want compfold to scan this directory? (y) \c"
    read ans
    if [ "$ans" = "n" -o "$ans" = "N" ]
    then
	echo "compfold will NOT scan $mdir."
    else
	echo "compfold will scan $mdir."
	DIRS="$DIRS $mdir"
    fi
done

if [ "$DIRS" = "" ]
then
    echo
    echo "Since you've not entered any valid Netscape folder directories, compfold will"
    echo "not be installed."
    abort
else
    if [ ! -d bin ]
    then
	echo "Creating the directory ~/bin."
	mkdir bin
	if [ $? != 0 ]
	then
	    echo "Failed to create the directory ~/bin."
	    abort
	fi
    fi

    cd bin

    mv -f compfold compfold- 2>/dev/null
    mv -f uninstall_compfold uninstall_compfold- 2>/dev/null

    echo
    echo "Extracting..."
    tail -c$EOF $PROG | gunzip | tar xvf -
    if [ $? != 0 ]
    then
	mv compfold- compfold 2>/dev/null
	mv uninstall_compfold- uninstall_compfold 2>/dev/null
	echo "Installation failed, the archive was damaged."
    else
	if [ -r compfold ]
	then
	    chmod 755 compfold
	fi
	if [ -r uninstall_compfold ]
	then
	    chmod 755 uninstall_compfold
	fi
	echo
	crontab -l 2>/dev/null | grep -v compfold > $TMP
	for MAIL_DIR in $DIRS
	do
	    echo `date +%S` "23  *  * 0-4 (cd $MAIL_DIR;\$HOME/bin/compfold *) 2>&1 |" 'mailx -s "compfold `date` '$MAIL_DIR'" `whoami`' >> $TMP
	done
	crontab < $TMP > /dev/null 2>&1
	rm $TMP
	echo "Your current crontab file:"
	crontab -l
	echo
	echo "Installation complete."
    fi
fi

exit
