#! /bin/sh
# postrm script for shfs

set -e

AMD_CONF_DIR=""
for d in /etc/am-utils/ /etc/ /etc/amd/; do
	if [ -f "$d/amd.conf" ]; then
		AMD_CONF_DIR="$d"; break
	fi
done

AMD_SERVICE=""
for d in /etc/init.d/am-utils /etc/init.d/amd /etc/rc.d/init.d/am-utils /etc/rc.d/init.d/amd; do
	if [ -x "$d" ]; then
		AMD_SERVICE="$d"; break
	fi
done

case "$1" in
       purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
	if [ -n "$AMD_CONF_DIR" -a -n "$AMD_SERVICE" ]; then
		cd $AMD_CONF_DIR
		rm -f mount umount amd.shfs
		awk '/^# SHFS: AUTO ADDED$/ { while (getline == 1) { if ($0 == "# SHFS: END") break; } next; } // { print $0; }' amd.conf >amd.conf.tmp
		mv amd.conf.tmp amd.conf
		if [ -d /shfs ]; then
			rmdir /shfs
		fi
		set +e
		$AMD_SERVICE start
		set -e
	fi

	set +e
	/sbin/depmod -a
	set -e
        ;;

    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 1

esac

#DEBHELPER#

exit 0
