#!/bin/sh
#This script is used to calculate total number of Mail users for a 
#TCIL. Following groups are included XPS, TCIL, APNA.


#-------Commands Used---------#
wc=/usr/bin/wc
cat=/bin/cat
grep=/bin/grep
cut=/usr/bin/cut
#-----------------------------#

TCIL_NUM=`cat /etc/passwd | grep ^tcil- | wc -l`
XPS_NUM=`cat /etc/passwd | grep ^xps- | wc -l`
APNA_NUM=`cat /etc/passwd | grep ^apna- |wc -l`
TOTAL_NUM=`expr $TCIL_NUM + $XPS_NUM + $APNA_NUM`

echo
echo "Total mail accounts configured for TCIL prepend :- $TCIL_NUM"
echo "Total mail accounts configured for XPS  prepend :- $XPS_NUM"
echo "Total mail accounts configured for APNA prepend :- $APNA_NUM"
echo
echo "TOTAL MAIL A/C for TCIL Customer :-                 `expr $TCIL_NUM + $XPS_NUM + $APNA_NUM`"
echo

#!/bin/sh
#This script is used to add users for TCIL to tcilmail group. This
#script does following things.
# 1.    Adds a user with prepend tcil-
# 2.    Changes the group of user to tcilmail and shell to /bin/false
# 3.    Make Maildir directory and set appropriate permissions
# 4.    Sets passwd for user default 'pas123'

if [ $TOTAL_NUM -ge 12 ]
echo Entered
fi

#
ctr=0
for i in $*
do
ctr=`expr $ctr + 1`
#cp -f .qmail /home/$i/
/usr/sbin/adduser tcil-$i -g tcilmail -s /bin/false
cd /home/tcil-$i/
maildirmake Maildir
chgrp -R tcilmail Maildir
owner=`tail -1 /etc/passwd | sed -e 's/:/ : /g' | awk '{ print $5 }'`
chown -R "$owner" Maildir
echo pass123 |passwd --stdin tcil-$i
done


clear
echo "Please copy .qmail file to respective user's home directory. 
Thanks!..."
echo
sleep 2
