#!/bin/sh -e

if [ "$1" = remove ]; then
	# We should do some checking to prevent removal of ecryptfs if in use
	# Check active mounts
	if out=`mount | grep "\Wtype\Wecryptfs\W"`; then
		echo "WARNING: Should not remove ecryptfs-utils, as it appears to be in use:" 1>&2
		echo "$out" 1>&2
	fi
	if out=`grep "\Wecryptfs\W" /proc/mounts`; then
		echo "WARNING: Should not remove ecryptfs-utils, as it appears to be in use:" 1>&2
		echo "$out" 1>&2
	fi
	# Check fstab
	if out=`grep "\Wecryptfs\W" /etc/fstab`; then
		echo "WARNING: Should not remove ecryptfs-utils, as it appears to be in use:" 1>&2
		echo "$out" 1>&2
	fi
	# Check home directories
	for i in `ls /home`; do
		if [ -d "/home/$i/.ecryptfs" ]; then
			# If we find a .ecryptfs directory (or link) in a home,
			# directory, then someone is using ecryptfs-utils, and
			# we should not allow package removal
			echo "WARNING: Should not remove ecryptfs-utils, as it appears to be in use:" 1>&2
			echo "       [/home/$i/.ecryptfs]" 1>&2
		fi
	done
	pam-auth-update --package --remove ecryptfs-utils
fi



exit 0
