#!/bin/bash
# Samba-TNG                                           add_domain_group
# --------------------------------------------------------------------

# --------------------------------------------------------------------
# config here

. ./prefs

# --------------------------------------------------------------------
# print usage

if [ "$1" = "" ]; then
	echo "Usage: $(basename $0) <groupname>"
	exit 0
fi

# --------------------------------------------------------------------
# begin

groupexist=`$ldapsearch -D $binddn -w $bindpassword -b $smbsuffix cn="$1" -LLL |grep sambaGroup`

if [ "$groupexist" = "" ]; then
	$rpcclient -S . -U $rpcuser%$rpcpassword -c "creategroup \"$1\" \"$1\"" -d0
	exit 0
else
	echo "Group already exists!"
	exit 1
fi

exit 0

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