#!/bin/sh

PATH=/bin:/usr/sbin

USER=sipx
GROUP=sipx

case $2 in
PRE-INSTALL)
	if pw group show "${GROUP}" 2> /dev/null ; then
		echo "You already have a group \"${GROUP}\", so I will use it."
	else
		if pw groupadd ${GROUP} ; then
			echo "Added group \"${GROUP}\"."
		else
			echo "Add of group \"${GROUP}\" failed."
			exit 1
		fi
	fi

	if pw user show "${USER}" 2> /dev/null ; then
		echo "You already have a user \"${USER}\", so I will use it."
	else
		if pw useradd ${USER} -g ${GROUP} -h - \
		    -d %%LOCALSTATEDIR%%/sipxdata/configserver/phone/profile/tftproot -s %%PREFIX%%/bin/bash -c "sipX" ; then
			echo "Added user \"${USER}\"."
		else
			echo "Add of user \"${USER}\" failed."
			exit 1
		fi
	fi
	;;
POST-INSTALL)
	# Create a dummy file in /usr/local/share/sipxpbx to act
	# as a poorman's reference count.  Both sipxcommserverlib
	# and sipxconfig create this directory.  Though sipxcommserverlib
	# does not put any files in it.  When sipxconfig deinstalls
	# there is nothing to prevent it from completely removing
	# the directory.  Then when sipxcommservlib deinstalls, it
	# finds the directory it created is now gone.
	#
	# By creating a dummy file here, we'll prevent sipxconfig
	# from completely removing the directory and this will make
	# tinderbox happy when it deinstalls sipxcommserverlib.
	mkdir -p %%PREFIX%%/share/sipxpbx
	/usr/bin/touch %%PREFIX%%/share/sipxpbx/.sipxcommserverlib_dummy

	chown ${USER}:${GROUP} %%PREFIX%%/etc/sipxpbx
	;;
esac


syntax highlighted by Code2HTML, v. 0.9.1