#!/bin/sh
set -e

if [ "$1" = configure -a -e /etc/suid.conf ]; then
	# suidexec was removed from this package
	if grep -q '^suidmanager /usr/bin/suidexec ' /etc/suid.conf; then
	    suidunregister /usr/bin/suidexec
	elif grep -q '^suidmanager /usr/sbin/suidexec ' /etc/suid.conf; then
	    suidunregister /usr/sbin/suidexec
	fi
	
	# clean up for version 0.38, which inserted patterns from
	# suidunregister into the registry
	if grep -q '^\[a-z0-9+-\\\.\]+' /etc/suid.conf; then
	    perl -pe '
		unless (/^#|^\s*$/) {
		    s/^\[a-z0-9\+-\\\.\]\+(\s)/user$1/;
		    s/\\(.)/$1/g;
		}
	    ' /etc/suid.conf > /etc/suid.conf.new
	    mv /etc/suid.conf.new /etc/suid.conf
	fi
	
	/usr/share/suidmanager/suid2stat /etc/suid.conf
	rm -f /etc/suid.conf
fi

# Dummy file to smooth transition
touch /etc/suid.conf

# Now it's debhelper's turn.
#DEBHELPER#

if [ "$1" = configure ] && expr match "$2" '0.1[0-8]' >/dev/null; then
echo
echo "*** The suidexec program has been removed from this package due to ***"
echo "*** a security problem.  If you used it in any of your scripts, I  ***"
echo "*** suggest you switch to something more secure, such as perl.     ***"
echo
echo -n "Press <ENTER> to continue."
read nothing
fi
