if [ -z "$1" -o -z "$2" ]
then
	echo usage : "$0 appl_user appl_name [ -n user_no ] [ -g group_no ]"
	exit 1
fi
if [ -n "$3" ]
then
	if [ $3 != "-n" -a $3 != "-g" ]
		then
	echo usage : "$0 appl_user appl_name [ -n user_no ] [ -g group_no ]"
		exit 1
	fi
fi
if [ -n "$5" ]
then
	if [ $5 != "-n" -a $5 != "-g" ]
		then
	echo usage : "$0 appl_user appl_name [ -n user_no ] [ -g group_no ]"
		exit 1
	fi
fi

[ "$3" = "-n" ] && usr_no=$4
[ "$3" = "-g" ] && grp_no=$4
[ "$5" = "-n" ] && usr_no=$6
[ "$5" = "-g" ] && grp_no=$6
set  $1 $2 "$usr_no" "$grp_no"

if [ A = A ]
then
awk -F: ' BEGIN {usr="'"$1"'";app="'"$2"'"
usno="'"$3"'"+0; grpn="'"$4"'"+0;x=0}
usr==$1 {x1=1}
"'"$3"'"!="" && usno==$3+0 {x2 =2}
"'"$4"'"!="" && grpn==$4+0 {x4 =4}
END {x=x1+x2+x4;exit x} ' /etc/passwd
flag=$?
echo $flag
[ $flag = 1 -o $flag = 3 -o $flag = 5 -o $flag = 7 ] && echo USUARIO $1 YA EXISTE 
[ $flag = 2 -o $flag = 3 -o $flag = 5 -o $flag = 6 -o $flag = 7 ] && echo NUMERO DE USUARIO $3 YA EXISTE 
[ $flag = 4 -o $flag = 5 -o $flag = 6 -o $flag = 7 ] && echo GRUPO ASOCIADO $4 YA EXISTE 
#[ $flag != 0 ] && exit 2
[ -z "$3" ] && usr_no=`awk -F: ' { x[$3+0]=1 }
END { for (i=200;i<600;i++) if(x[i]+0==0) { print i ; i=600 } } ' /etc/passwd`
[ -z "$4" ] && grp_no=`awk -F: ' { x[$4+0]=1 }
END { for (i=20;i<49;i++) if(x[i]+0==0) { print i ; i=600 } } ' /etc/passwd`
echo   $1 $2 "$usr_no" "$grp_no"
if [ A = A ]
then
echo "GENERA USUARIO $1 EN SISTEMA"
#echo "$1:,..VF:$usr:$grp:Super user:/$1/menu:/bin/sh" >>/etc/passwd
#echo "$1:,..VF:$usr_no:$grp_no:Appl Adm $2:/$1/menu:/bin/ksh" >>/etc/passwd
echo "GENERA GRUPO   $1 EN SISTEMA"
#echo "$1::$grp_no:$1" >>/etc/group
echo User=$usr_no"   -    "$grp_no
for i in /$1 /$1/sour /$1/bin /$1/etc /$1/sh /$1/menu /usr/$1
do
mkdir $i
chmod 0770 $i
chown $1 $i
chgrp $1 $i
	echo PREPARA $i
	sleep 1
done
for z in forms menus reprt calcu
do
	i=/usr/$1/$z
	mkdir $i $i/user
	>$i/HEAD
	>$i/DOC
	echo -n "    0      0">$i/INFO
	chmod 0700 $i $i/*
	chown $1 $i $i/*
	chgrp $1 $i $i/*
	echo PREPARA $i
	sleep 1
done
fi
fi
cp /ihd/etc/profile /$1/menu/.profile
cp /ihd/etc/kshrc /$1/menu/.kshrc
awk ' NR==1 { print $0"'"$2"'" ; next }
 NR==2 { print $0"'"$1"'" ; next }
NR==3 { print $0"'"$1"'" ; next }
{ print } ' /ihd/etc/ihd >/$1/menu/.ihd

for z in .profile .kshrc .ihd
do
i=/$1/menu/$z
chmod 0770 $i
chown $1 $i
chgrp $1 $i
	echo PREPARA $i
	sleep 1
done

echo "GENERA MENU 1  $1 EN SISTEMA"
echo $1 $2 | awk ' {
printf "[ INHEDO 4GT 000000 ]     MENU PRINCIPAL      [ %s ]\n",$2
print "5 4"
printf "FORMS                    :cd /usr/%s/forms;forms /IHD/forms/forms\n",$1
printf "MENUES                   :cd /usr/%s/menus;menus /IHD/menus/menus\n",$1,$1
printf "REPORTS                  :cd /usr/%s/reprt;reprt /IHD/reprt/reprt\n",$1,$1
printf "CALCULOS                 :cd /usr/%s/calcu;calcu /IHD/calcu/calcu\n",$1,$1
printf "APPLICATION              :exec meng /%s/menu/00000\n",$1,$1
} ' -  >/$1/menu/$1

