#! /bin/sh

# Delete most DCC files.
#   Some logs configuration files with locally chosen parameters in /opt/local/etc/dcc
#   are not deleted.
#   Manual changes such as links to /opt/local/libexec/dcc/rcDCC or the
#   installation of the cron job, /opt/local/libexec/dcc/cron-dccd, are not reversed.


# --S-LICENSE--

# $Revision: 1.4 $
# Generated automatically from uninstalldcc.in by configure.

DCC_HOMEDIR=/opt/local/etc/dcc
DCC_LIBEXEC=/opt/local/libexec/dcc	    # in case dcc_conf has disappeared
. $DCC_HOMEDIR/dcc_conf
BDIR=$DCC_HOMEDIR/build
DCCBDIR=$BDIR/dcc

USAGE=`basename $0`': [-x]'
while getopts "x" c; do
    case $c in
    x) set -x; DEBUG=-x;;
    *) echo "$USAGE" 1>&2; exit 1;;
    esac
done
shift `expr $OPTIND - 1 || true`
if test "$#" -ne 0; then
    echo "$USAGE" 1>&2; exit 1
fi


echo "This script will delete most of a DCC client and server installed"
echo "with the official DCC Makefiles in $DCCBDIR."
echo "Are you sure you want to proceed?  " | tr -d '\012'
read OK
case $OK in
    [yY][eE][sS]) ;;
    *) echo "ok, nothing deleted"; exit;;
esac

if test ! -f $DCCBDIR/Makefile; then
    $DCC_LIBEXEC/updatedcc -U
    if test ! -f $DCCBDIR/Makefile; then
	echo "This script can only be run after $DCC_LIBEXEC/updatedcc has"
	echo "installed the offical Makefiles in $DCCBDIR"
	exit 1
    fi
fi

$DCC_LIBEXEC/rcDCC $DEBUG stop
cd $DCCBDIR
make uninstall purge
rm -f $BDIR/dcc.tar.Z \
    $DCC_HOMEDIR/flod.map $DCC_HOMEDIR/grey_flod.map			    \
    $DCC_HOMEDIR/dcc_db $DCC_HOMEDIR/dcc_db.hash $DCC_HOMEDIR/dcc_db-old    \
    $DCC_HOMEDIR/grey_db $DCC_HOMEDIR/grey_db.hash $DCC_HOMEDIR/grey_db-old \
    $DCC_HOMEDIR/testmsg-whitelist $DCC_HOMEDIR/testmsg-whitelist.log	    \
    $DCC_HOMEDIR/*.dccw $DCC_HOMEDIR/*.dccx
for DIR in `find $DCC_HOMEDIR -depth -type d` $DCC_LIBEXEC $DCC_RUNDIR; do
    if test -d $DIR; then
	find $DIR -depth -type d | /usr/bin/xargs rmdir || true
    fi
done

echo
echo "Some of your configuration and log files remain in $DCC_HOMEDIR"

