#!/bin/sh
#
# $MidnightBSD: mports/net/boinc-client/files/pkg-install.in,v 1.2 2013/07/07 17:23:05 laffer1 Exp $
#

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

user=boinc
group=nobody
home="/var/db/boinc"
shell=/bin/sh

case $2 in
PRE-INSTALL)
	if ! pw usershow ${user} 2>/dev/null 1>&2; then
		if ! pw useradd ${user} -g ${group} -c "BOINC client user" \
		    -d "${home}" -s ${shell}; then
			echo "Failed to create user \"${user}\"." >&2
			exit 1
		else
			echo "User \"${user}\" created successfully:"
		fi
	else
		echo "Using existent user \"${user}\":"
	fi
	pw usershow ${user}
	mkdir -m u=rwx,go= -p "${home}"
	if [ ! -e "${home}/skins" -a ! -L "${home}/skins" ]; then
		ln -s "/usr/local/share/boinc/skins" "${home}/skins"
	fi
	if [ ! -e "${home}/ca-bundle.crt" -a ! -L "${home}/ca-bundle.crt" ]; then
		ln -s "/usr/local/share/certs/ca-root-nss.crt" "${home}/ca-bundle.crt"
	fi
	echo "Adjusting file ownership in \"${home}\" to ${user}:${group}"
	chown -hR ${user}:${group} "${home}"
	;;
esac

exit 0
