#!/bin/ksh
#************* addnisusers.sh ***************
# addnisuser.sh - ksh script for add user to
# NIS+
#********************************************
EUID=`id|awk -F\( '{print substr($1,5)}'`
if [ $EUID = 0 ] ; then
# get the domainname (minus the trailing . if necessary
DNAME=`domainname | xargs -I {} basename {} "\."`
#
# Variables need to be gathered to create a new user.
# Notably the Group (to get the GID), the UID,
# the Comment, the Shell and the Password
#
echo "GROUPS: \c"
niscat group.org_dir|nawk -F: '{print $1" "}'|xargs
echo "GROUP: [sal]\c"
read GROUP
GROUP=${GROUP:-"sal"}
GID=`niscat group.org_dir|grep ^$GROUP:|nawk -F: '{print $3}'`
if [ -z $GID ]
then
echo Group $GROUP does not exist !!!
exit
fi
echo "USERS: \c"
niscat passwd.org_dir|grep :$GID:|nawk -F: '{print $1}'|xargs
USED=1
while [ USED -gt 0 -o -z NAME ] ; do
echo "NAME: \c"
read NAME
USED=`niscat passwd.org_dir|grep -c $NAME:`
if [ USED -gt 0 ] ; then
echo "Name $NAME is already in use"
fi
done
echo "IDS: \c"
niscat passwd.org_dir|grep :$GID:|nawk -F: '{print $3}'|sort -n|xargs
echo "ID: \c"
read ID
echo "REAL NAME: \c"
read COMMENT
echo "SHELL: [/bin/csh] \c"
read SHELL
SHELL=${SHELL:-"/bin/csh"}
echo "PASSWORD: \c"
stty -echo
read PASS
stty echo
#
# All variables should now have been gathered
#
# Encrypt the Password
#
CODE=`perl -e '
srand;
$s1= ($rnd=rand(62)) > 9 ? $rnd > 25 ? $rnd + 49 : $rnd + 17 : $rnd;
$s2= ($rnd=rand(62)) > 9 ? $rnd > 25 ? $rnd + 49 : $rnd + 17 : $rnd;
print crypt($ARGV[0], chr($s1+48) . chr($s2+48));
' $PASS`
#
# HNAME is the host server for the home directory
# EXPHOME is the directory path on the host server for home directories
#
case $GROUP in
sal) EXPHOME=/export/salhome;
HNAME=lims;;
rec) EXPHOME=/export/rechome;
HNAME=lims;;
sai) EXPHOME=/export/saihome;
HNAME=s222;;
esac
echo ""
nistbladm -a key=$NAME value=$HNAME:$EXPHOME/$NAME auto_home.org_dir > /dev/null
nistbladm -a name=$NAME passwd=$CODE uid=$ID gid=$GID gcos="$COMMENT" shell=$SHELL home=/home/$NAME passwd.org_dir > /dev/null
nisaddcred -p $ID -P $NAME.$DNAME. -l $PASS local > /dev/null
nisaddcred -p unix.$ID@$DNAME -P $NAME.$DNAME. -l $PASS des > /dev/null
nischown $NAME [name=$NAME],passwd.org_dir > /dev/null
nischmod n-r,w-r,g+r [name=$NAME],passwd.org_dir > /dev/null
nistbladm -u passwd=n-r,w-r,g+r passwd.org_dir > /dev/null
if [ "x$HNAME" = "x`uname -n`" ] ; then
echo " mkdir -p $EXPHOME/$NAME
cp /etc/skel/.[a-z]* $EXPHOME/$NAME
chown -R $NAME:$GROUP $EXPHOME/$NAME
" ;
else
echo "On Server $HNAME:
mkdir -p $EXPHOME/$NAME
cp /etc/skel/.[a-z]* $EXPHOME/$NAME
chown -R $NAME:$GROUP $EXPHOME/$NAME
"
fi
else
echo "You must be root"
fi
#******** end of addnisuser.sh *********