#!/bin/bash
#
# Turboprint deinstallation script
# uninstall-pre remove non-static files
#
# must have root permissions
#

eval $(cat /etc/turboprint/system.cfg)

# calls tpsetup to remove spooldirs

if [ -e bin/tpsetup ] ; then
	bin/tpsetup --uninstall
else
	tpsetup --uninstall
fi

# remove dump files

if [ -e "$TPPATH_SHARE/dump/dj970aligncontrol.prn" ] ; then
	rm -r "$TPPATH_SHARE/dump/dj970aligncontrol.prn"
fi

# remove /etc/turboprint/turboprint.cfg

## rm /etc/turboprint/system.cfg
if [ -e "$TPPATH_CONFIG/turboprint.cfg" ] ; then
	rm "$TPPATH_CONFIG/turboprint.cfg"
fi

# remove cups ppd files

rm -r "$TPPATH_SHARE/ppd"

if [ -e "$TPPATH_CUPSDRIVER/turboprint" ] ; then
	rm -r "$TPPATH_CUPSDRIVER/turboprint"
fi

# remove doc link

rm $TPPATH_DOC/html_fr

# remove entry from KDE menu

if [ $KDEDIRS ] ; then
	LOOP=1
	while [ $LOOP -gt 0 -a $LOOP -lt 20 ] ; do
		KDEPATH=$(echo "$KDEDIRS" | cut -d":" -f$LOOP)
		if [ $KDEPATH ] ; then
		    LOOP=$[LOOP+1]
		    if [ -e $KDEPATH/share/applnk/Utilities ] ; then
			KDEPATH="$KDEPATH/share/applnk/Utilities"
			LOOP=0
		    fi
		else
			LOOP=0
		fi
	done
fi

if [ -e /etc/opt/kde2/share/applnk/SuSE/Utilities ] ; then
	KDEPATH="/etc/opt/kde2/share/applnk/SuSE/Utilities"
fi
if [ -e /etc/opt/kde3/share/applnk/SuSE/Settings ] ; then
	KDEPATH="/etc/opt/kde3/share/applnk/SuSE/Settings"
fi

if [ -e "$KDEPATH/xtpconfig.desktop" ] ; then
	rm "$KDEPATH/xtpconfig.desktop"
fi
if [ -e "$KDEPATH/xtpsetup.desktop" ] ; then
	rm "$KDEPATH/xtpsetup.desktop"
fi

if [ -e ~/KDesktop/xtpconfig.desktop ] ; then
	rm ~/KDesktop/xtpconfig.desktop
fi
if [ -e ~/KDesktop/xtpsetup.desktop ] ; then
	rm ~/KDesktop/xtpsetup.desktop
fi
if [ -e ~/Desktop/xtpconfig.desktop ] ; then
	rm ~/Desktop/xtpconfig.desktop
fi
if [ -e ~/Desktop/xtpsetup.desktop ] ; then
	rm ~/Desktop/xtpsetup.desktop
fi

# remove from all user's desktops

# add to all users' desktops
for i in /home/*; do
	if [ -e $i/KDesktop/xtpconfig.desktop ] ; then
		rm $i/KDesktop/xtpconfig.desktop
	fi
	if [ -e $i/KDesktop/xtpsetup.desktop ] ; then
		rm $i/KDesktop/xtpsetup.desktop
	fi
	if [ -e $i/Desktop/xtpconfig.desktop ] ; then
		rm $i/Desktop/xtpconfig.desktop
	fi
	if [ -e $i/Desktop/xtpsetup.desktop ] ; then
		rm $i/Desktop/xtpsetup.desktop
	fi
done

# finished

exit 0
