#!/bin/sh
###########################################################################
#
# Easy Uninstall (c) 1994 Hubert Feyrer
#
#--------------------------------------------------------------------------
#
# V1.0 940904 Initial hacking
# V1.1 940924 Change /opt to /usr/local
# V1.2 940925 Fix bug when linking directories
#
#--------------------------------------------------------------------------
#
# ============== Hubert Feyrer =========================================== 
#      Weekdays: Rennerstr. 19, D-93053 Regensburg,  Tel. 0941/701788
#      Weekends: Bachstr. 40,   D-84066 Mallersdorf, Tel. 08772/6084
#      Internet: hubert.feyrer@rz.uni-regensburg.de == IRC: hubertf
# ======================================================================== 
#
###########################################################################

# Verbosity control
exec=""		# set to "echo" to display commands 
v1=true		# Introduction blurb
v2=true		# what's going on
v3=false	# debugging stuff
v4=true		# do "$exec command" ? (more debugging)

###########################################################################
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# No changes should be made below this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
###########################################################################

# Defaults
BASE=/usr/local
BIN=""
ETC=""
LIB=""
MAN1=""
MAN2=""
MAN3=""
MAN4=""
MAN5=""
MAN6=""
MAN7=""
MAN8=""
CAT1=""
CAT2=""
CAT3=""
CAT4=""
CAT5=""
CAT6=""
CAT7=""
CAT8=""
INFO=""
APPDEF=""
INCLUDE=""
SUIDROOT=""
MISCDIRS=""

#
# Read package-information
#
$v3&&echo using configuration from `dirname $0`/package
. `dirname $0`/package


$v1&& echo Removing $PKG from $BASE

#
# Determine directory where application defaults for X go to
#
if [ "$APPDEF" != "" ];
then
	# search some directories
	for d in /usr /usr/local/X11R6 /usr/X11R6 /usr/local/X11R5 /usr/X11R5 \
		 $BASE/X11R6 $BASE/X11R5;
	do
        	if [ -d  $d/lib/X11/app-defaults ];
        	then
			APPDEFDIR=$d/lib/X11/app-defaults
                	break
        	fi
	done
	# nothing found, ask user
	while [ "$APPDEFDIR" = "" -o ! -d "$APPDEFDIR" ];
	do
		echo Couldn\'t figure out directory for X application-defaults.
		echo -n "Please specify: "
		read APPDEFDIR
	done
        $v3&&echo APPDEFDIR: $APPDEFDIR
fi

#
# Link existing files from package to destination
#
doremove()
{
	what=$1 ; shift
	dir=$1  ; shift

	if [ "$*" != "" ];
	then
		$v2&&echo -n removing $what:
		for i in $* ;
		do
			file=$BASE/$dir/$i
			if [ -e $file ];
			then
				$v2&&echo -n " $i"
				$v4&&$exec rm -f $file
			else
				echo ''
				echo ERROR: $file not found!
			fi
		done
		$v2&&echo .

		# mkdir if necessary
		rmdir -p $BASE/$dir 2>/dev/null
	fi
}

doremove "binaries"					bin		$BIN
doremove "etc-files"					etc		$ETC
doremove "libraries"					lib		$LIB
doremove "unformatted man-pages for general commands"	man/man1	$MAN1
doremove "unformatted man-pages for system calls"	man/man2	$MAN2
doremove "unformatted man-pages for C libraries"	man/man3	$MAN3
doremove "unformatted man-pages for device driver"	man/man4	$MAN4
doremove "unformatted man-pages for file formats"	man/man5	$MAN5
doremove "unformatted man-pages for games"		man/man6	$MAN6
doremove "unformatted man-pages for miscellaneous"	man/man7	$MAN7
doremove "unformatted man-pages for system operation"	man/man8	$MAN8
doremove "formatted man-pages for general commands"	man/cat1	$CAT1
doremove "formatted man-pages for system calls"		man/cat2	$CAT2
doremove "formatted man-pages for C libraries"		man/cat3	$CAT3
doremove "formatted man-pages for device driver"	man/cat4	$CAT4
doremove "formatted man-pages for file formats"		man/cat5	$CAT5
doremove "formatted man-pages for games"		man/cat6	$CAT6
doremove "formatted man-pages for miscellaneous"	man/cat7	$CAT7
doremove "formatted man-pages for system operation"	man/cat8	$CAT8
doremove "info-manual"					info		$INFO
doremove "includes"					include		$INCLUDE

#
# application defaults for X
#
if [ "$APPDEF" != "" ];
then
        $v2&&echo -n removing X application defaults:
        for i in $APPDEF ;
        do
		file=`basename $i .ad`
                if [ -e $APPDEFDIR/$file ];
                then
                        $v2&&echo -n " $file"
                        $v4&&$exec rm -f $APPDEFDIR/$file
                else
			echo ''
                        echo ERROR: $APPDEFDIR/$file not found!
                fi
        done
        $v2&&echo .
fi


#
# Create misc directories, if necessary
#
for i in $MISCDIRS ;
do
	rmdir -p $BASE/$i 2>/dev/null
done

$v1&&echo Done.
