#!/bin/sh
# $MidnightBSD: mports/net-im/jabberd/files/pkg-install.in,v 1.2 2007/12/28 20:39:48 laffer1 Exp $
# $FreeBSD: ports/net-im/jabberd/files/pkg-install.in,v 1.1 2007/07/26 20:00:52 mm Exp $

if [ "$2" != "POST-INSTALL" ]; then
    exit 0
fi

USER=jabber
GROUP=jabber
UID=93
GID=93
ETCDIR=/usr/local/etc/jabberd
RUNDIR=/var/jabberd

if ! pw groupshow "${GROUP}" 2>/dev/null 1>&2; then
	if pw groupadd ${GROUP} -g ${GID}; then
		echo "Added group \"${GROUP}\"."
	else
		echo "Adding group \"${GROUP}\" failed..."
		exit 1
	fi
fi

if ! pw usershow "${USER}" 2>/dev/null 1>&2; then
	if pw useradd ${USER} -u ${UID} -g ${GROUP} -h - \
		-s "/sbin/nologin" -d "/nonexistent" \
		-c "Jabber Daemon"; \
	then
		echo "Added user \"${USER}\"."
	else
		echo "Adding user \"${USER}\" failed..."
		exit 1
	fi
fi

if [ ! -d ${RUNDIR} ]; then
	echo "Creating \"${RUNDIR}\"."
	mkdir -p ${RUNDIR}/pid ${RUNDIR}/db ${RUNDIR}/logs
fi

echo "Fixing ownerships and modes in \"${ETCDIR}\"."
chown -R ${USER}:${GROUP} ${ETCDIR}
chmod -R go= ${ETCDIR}

echo "Fixing ownerships and modes in \"${RUNDIR}\"."
chown -R ${USER}:${GROUP} ${RUNDIR}
chmod -R go= ${RUNDIR}
