#!/bin/bash
#
# ::copy::
# ::maintainer::
#
set -e
set -u

CMD=`basename $0`

usage()
{
	echo "usage: $CMD hostname$" >&2
	exit 1
}

# (MAIN)

[ $# != 1 ] && usage

host="$1"

# normalize name (must end with '$' char)
case $host in
  *$)	;;
  *)	host="$host$" ;;
esac

# search for first free uid
#
uid=`kusa-conf samba.first_comp_uid`
uid=`ku-smbldap-nextfreeuid $uid`

# first calls useradd (supposed with -w flag) to create the entry
#
/usr/sbin/smbldap-useradd -w -u $uid "$host"

# then calls usermod to make it a samba account (missed on useradd call)
#
/usr/sbin/smbldap-usermod -a -H "[W]" "$host"

exit 0
