#! /bin/sh
# $FreeBSD: ports/www/openacs/files/pkg-install.in,v 1.6 2007/08/02 13:28:05 mm Exp $

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

OPENACS_GROUP=www
OPENACS_USER=openacs
OPENACSBASE=/usr/local/openacs

CHMOD=/bin/chmod
CHOWN=/usr/sbin/chown
PW=/usr/sbin/pw

if ! ${PW} groupshow "${OPENACS_GROUP}" 2>/dev/null 1>&2; then
	if ${PW} groupadd ${OPENACS_GROUP}; then
		echo "Added group \"${OPENACS_GROUP}\"."
	else
		echo "Adding group \"${OPENACS_GROUP}\" failed..."
		exit 1
	fi
fi

if ! ${PW} usershow "${OPENACS_USER}" 2>/dev/null 1>&2; then
	if ${PW} useradd ${OPENACS_USER} -g ${OPENACS_GROUP} -h - \
		-s "/bin/sh" -d "${OPENACSBASE}" \
		-c "OpenACS instance pseudo-user"; \
	then
		echo "Added user \"${OPENACS_USER}\"."
	else
		echo "Adding user \"${OPENACS_USER}\" failed..."
		exit 1
	fi
fi
	echo "Seting permissions of files"
	${CHMOD} -R 770 ${OPENACSBASE}
	${CHOWN} -R ${OPENACS_USER}:${OPENACS_GROUP} ${OPENACSBASE}
