#!/bin/sh -e

NAME=cluebringer

case "$1" in
	install)

		# Check that the system user and group exist, if not create them.
		if ! getent group $NAME >/dev/null ; then
			echo "Adding system group $NAME ... "
			addgroup --system --quiet $NAME || {
				
				if ! getent group clubringer >/dev/null ; then
						echo "Could not create system group $NAME." >&2
						exit 1;
				fi
			}
		fi

		if ! getent passwd $NAME >/dev/null ; then
			echo "Adding system user $NAME ... "
			adduser --system --home "/etc/$NAME" --ingroup "$NAME" \
			--no-create-home --disabled-login --shell "/usr/sbin/nologin" \
			--quiet $NAME >/dev/null 2>&1 || {
				
				if ! getent passwd $NAME >/dev/null ; then
						echo "Could not create system user $NAME." >&2
						exit 1;
				fi
			}
		fi

		;;
	configure)
		;;
	upgrade|abort-upgrade)
		;;

	*)
		echo "preinst called with unknown argument $1" >&2
		exit 1
		;;
esac

exit 0



