#!/bin/sh
if test "$1" = "-help"
then
    echo "usage: `basename $0` -help";
    echo "purpose: remove all files and directories not";
    echo "         necessary for UG server version";
	echo "Options are";
    echo " help: this help message";
    exit 1;
fi

if test "x$UGROOT" = "x"
then
	echo "$0: to use $0 set shell environment variable UGROOT!";
	exit 1;
fi

# remove all .doc files
find ${UGROOT}/.. \( -name '*.doc' \) -exec rm {} \; -print
echo "`basename $0`: all *.doc files removed!";

# remove all files and dirs in $UGROOT/doc not needed any more 
cd ${UGROOT}/doc
for i in * 
do
	if test -d $i
	then
		rm -r $i;
	else
		if test "$i" = "progmanual.ps" -o "$i" = "refmanualI.ps" -o \
				"$i" = "applmanual.ps" -o "$i" = "refmanualII.ps"
		then 
			echo "`basename $0`: $i not removed!";
		else
			rm $i;
		fi
	fi
done

echo "`basename $0`: in UGROOT/doc all files and dirs removed!";

# remove texput.log generated by latex in UGROOT/bin
if test -f ${UGROOT}/bin/texput.log
then
	rm ${UGROOT}/bin/texput.log;
fi

cd ${UGROOT}/bin;
rm -f ugmakeref ugrm4serv ugmaketrees ugmakelatex ugtex ugmakelatexrefs;
rm -f ugprep4serv ugmakeman ugrecurse ugsetcvsaccess ugmakealiases;

if test $# -ge 1 -o "$1" != "-help"
then
	rm -r -f  ${UGROOT}/include
	rm -r -f  $UGROOT/parallel/chaco
	cd ${UGROOT}/doc
	gzip applmanual.ps
	gzip progmanual.ps
	gzip refmanualI.ps
	gzip refmanualII.ps
	cd ${UGROOT}
	cd ..
	cd ..
	mkdir $1
	cd $1
	mv ${UGROOT}/gm/gm.h .
	mv ${UGROOT}/gm/gg3/netgen/meshing/ruler3.cc .
	cp ${UGROOT}/../license.ps .
	cp ${UGROOT}/doc/applmanual.ps.gz .
	cp ${UGROOT}/doc/progmanual.ps.gz .
	cp ${UGROOT}/doc/refmanualI.ps.gz .
	cp ${UGROOT}/doc/refmanualII.ps.gz .
	mv ../UG $1
	if test $# -ge 2 
	then
		if test "$2" = "CVS"
		then
			find  $1 -name "CVS" -exec rm -r {} \;
		fi
	fi
	tar cvf $1.tar $1
	gzip $1.tar
	mv $1 ../UG
	cp gm.h ${UGROOT}/gm 
	cp ruler3.cc ${UGROOT}/gm/gg3/netgen/meshing
    cd ..
fi

