#! /bin/sh

#	$Id: filtersetup,v 1.2 1998/05/17 21:06:16 andreas Exp $

# filtersetup	- look for installed filters supported by apsfilter
#		- and write supported filter into the filters_found
#		  database: APS_BASEDIR/global/filters_found

# This script runs normally during first-installation
# If you add more filters to your system (pbmplus utilities, etc...)
# then you must again run this utility to ensure that apsfilter
# knows about the new filters by updating the filters_found file

# printer filter programs supported by apsfilter 3.0
# if you want to add an additional filter, then you have to add the
# name here, too !!!

SUPPORTED_FILTERS="\
	gs \
	dvips \
	a2ps \
	ras2ps \
	giftopnm \
	pnmtops \
	ppmtopgm \
	fig2dev \
	rasttopnm \
	tifftopnm \
	gzip \
	compress \
	pack \
	djpeg \
	melt \
	html2ps \
	"

# are we called by SETUP or are we standalone ?
# if standalone, then grab APS_BASEDIR from /etc/printcap file
	APS_BASEDIR=/usr/lib/apsfilter

. $APS_BASEDIR/global/GLOBAL.sh


echo "cleaning global config file..."
if [ -f $FILTERS_FOUND ]; then
	: > $FILTERS_FOUND
	chmod 0644 $FILTERS_FOUND
fi

# extract searchpatch for find from PATH
SEARCHPATH=`echo $PATH | sed -e "s/:/\ /g"`

echo "looking for available filter programs on this system..."
for filter in $SUPPORTED_FILTERS
do
	FILTER=`echo $filter | tr 'a-z' 'A-Z'`
	for dir in $SEARCHPATH
	do
		if [ -f $dir/$filter ]
		then
			set HAVE_$FILTER="True" \
				&& echo "found filter $filter" \
				&& echo "HAVE_$FILTER=True" >> $FILTERS_FOUND
			chmod 0644 $FILTERS_FOUND
		fi
	done
done

if [ -f $FILTERS_FOUND ]; then
    TMPFILE=`mktemp /tmp/apsfilterrc.XXXXXX` || exit 1

    sort < $FILTERS_FOUND | uniq > $TMPFILE
    mv $TMPFILE $FILTERS_FOUND
    chmod 0644 $FILTERS_FOUND
else
    # a system without special filter
    echo "# no supported filters found during filtersetup ?!" >> $FILTERS_FOUND
    echo "# if you suppose to add filters like dvips, gs,..." >> $FILTERS_FOUND
    echo "# later, then run $APS_BASEDIR/setup/filtersetup  " >> $FILTERS_FOUND
    echo "# again !					    " >> $FILTERS_FOUND
    # mail the poor result !!!
    cat $FILTERS_FOUND | $MAIL root > /dev/null 2>&1
    chmod 0644 $FILTERS_FOUND
fi
