#!/bin/sh
# arpwatch.postinst: v11 2004/09/15 KELEMEN Peter <fuji@debian.org>

set -e

AWUSER="arpwatch"
AWGROUP="arpwatch"
AWHOME="/var/lib/$AWUSER"
AWGECOS="ARP Watcher"

case "$1" in
	configure)
		# Take care of group.
		if AWGROUP_ENTRY=`getent group $AWGROUP`; then
			# group exists
			:
		else
			# group does not exist yet
			addgroup --quiet --system $AWGROUP
		fi

		# Take care of user.
		if AWUSER_ENTRY=`getent passwd $AWUSER`; then
			# user exists
			adduser --quiet $AWUSER $AWGROUP
		else
			# user does not exist yet
			adduser --quiet --system	\
				--ingroup $AWGROUP	\
				--gecos "$AWGECOS"	\
				--home $AWHOME		\
				--no-create-home	\
				--shell /bin/sh		\
				--disabled-login	\
				--disabled-password	\
				$AWUSER
		fi

		# Set up home directory.
		if [ -d $AWHOME ]; then
			chown -R ${AWUSER}:${AWGROUP} $AWHOME
			chmod -R o-rwX $AWHOME
		fi
		;;

	abort-upgrade|abort-remove|abort-deconfigure)
		;;
	*)
		echo "postinst called with unknown argument \`$1'" >&2
		exit 1
		;;
esac

NAME=arpwatch
DBDIR=/var/lib/$NAME
DBFILE=arp.dat
BACKUPDIR=/var/backups

# Restore backed up ARP databases.
if [ -d $BACKUPDIR -a -d $BACKUPDIR/$NAME ]; then
	cp $BACKUPDIR/$NAME/* $DBDIR 2>/dev/null || true
fi
if [ -d $DBDIR ]; then
	touch $DBDIR/$DBFILE
fi

#DEBHELPER#


exit 0

# End of file.
