#!/bin/sh

set -eu

NAME="jam-admin"

HOME="/var/lib/$NAME"
USER="$NAME"
GROUP="$NAME"

# if NIS is used, then errors can occur but be non-fatal
if which ypwhich >/dev/null 2>&1 && ypwhich >/dev/null 2>&1
then
	set +e
fi

if ! getent group "$GROUP" >/dev/null
then
	addgroup --system "$GROUP" >/dev/null
fi

# creating user if it isn't already there
if ! getent passwd "$USER" >/dev/null
then
        adduser \
          --system \
          --home $HOME \
          --shell /bin/false \
          --disabled-login \
          --ingroup "$GROUP" \
          --gecos "$USER"  \
          "$USER"  >/dev/null
fi

# NISno longer a possible problem; stop ignoring errors
set -e
