#! /bin/sh

# You'll have to change this script to suit your system.
# 
# ACUA v3.01 - Updated to use useradd instead of adduser.
#
# NOTE: acua addRec *must* be called *after* adduser (or its equivalent)

DEFAULT_EXPIRY=0
DEFAULT_TLIMIT=30
DEFAULT_SLIMIT=30
DEFAULT_PRIORITY=4

function err () {
  echo An error occurred -- operation aborted.
  /usr/bin/acua delRec "$LOGIN" >& /dev/null
  # this one is up to you.
  #/usr/sbin/userdel "$LOGIN" >& /dev/null
  exit 1
}

if [ "$#" == "0" ]; then
  echo "usage: acua_adduser <login> [ph_no] [useradd options]"
  exit 1
fi

# Parse command-line options.
if [ -z "$1" ]; then
    usage
    exit 1
else
    LOGIN="$1"
    shift
fi

if [ -z "$1" ]; then
    PH_NO="-1"
else
    PH_NO="$1"
    shift
fi

echo ""
echo "ACUA v3.04 - Adding a user."
if [ "$#" == "0" ]; then
    /usr/sbin/useradd -m -s /bin/false "$LOGIN" || err
else
    /usr/sbin/useradd $@ "$LOGIN" || err
fi
/usr/bin/acua addRec "$LOGIN" $DEFAULT_EXPIRY $DEFAULT_TLIMIT $DEFAULT_SLIMIT $DEFAULT_PRIORITY "$PH_NO" || err
echo ""
/usr/bin/passwd "$LOGIN" || err
echo ""
/usr/bin/chfn "$LOGIN" || err
exit 0
