#!/bin/sh
# $FreeBSD: ports/devel/otrs/files/pkg-install.in,v 1.1 2006/07/05 17:15:24 skv Exp $

PATH=/bin:/usr/bin:/usr/sbin

WWWOWN="www"
WWWGRP="www"
OTRS_USER="otrs"
OTRS_GROUP="otrs"

case $2 in
PRE-INSTALL)

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

	if ! id -u ${OTRS_USER} >/dev/null 2>&1; then
		if pw useradd -n ${OTRS_USER} -g ${OTRS_GROUP} \
		-G ${WWWGRP} -h - -s /bin/csh \
		-d ${PKG_PREFIX}/otrs -c "OTRS Administrator" ; then
			echo "Added user \"${OTRS_USER}\"."
		else
			echo "Adding user \"${OTRS_USER}\" failed..."
			exit 1
		fi
	fi
;;

POST-INSTALL)
	${PKG_PREFIX}/otrs/bin/SetPermissions.sh ${PKG_PREFIX}/otrs \
		${OTRS_USER} ${WWWOWN} ${OTRS_GROUP} ${WWWGRP}
;;

esac
