# 01-adduser
# functions:
# AddUsr: add username in system

#----------------------------------------------------------------------
# Add user to the system
# Entry: DefUsr default username (i.e. "admin") if timeout
#        DefNam default text-name (i.e. "System Admin") if timeout
#        temfile used to capture input
# Exit: U1 / U2 username and text-name
AddUsr() {
   [ -z "$DefUID" ] && DefUID=500
   # add group
   /usr/sbin/groupadd -g $DefUID $U1 >>/tmp/e1 2>>/tmp/e2
   rc=$?
   if [ $rc -ne 0 ] ; then
      log "   Failed to create the group"
      log "   $(cat /tmp/e2)"
      sleep .1
   fi
   # add user
   if [ $rc -eq 0 ] ; then
      /usr/sbin/useradd -g $DefUID -u $DefUID -G wheel -m -c "$U2" $U1 >>/tmp/e1 2>>/tmp/e2
      rc=$?
      if [ $rc -ne 0 ] ; then
        log "   Failed to create the account: $rc"
        log "   $(cat /tmp/e2)"
        sleep .1
      fi
   fi
	rm -f /tmp/{e1,e2}
} # AddUsr

#----------------------------------------------------------------------
