#!/bin/bash
#Description:
#Date: 2010-12-25 13:33:09
#Author:
#Version:0.01

NUID=$[`cut -d: -f3 /etc/passwd | grep -v "65534" | sort -n | tail -1`+1]
NGID=$[`cut -d: -f3 /etc/passwd | grep -v "65534" | sort -n | tail -1`+1]
DATY=$[`date +%s`/24/60/60]


dialog --title "User Infomation" --form "Please input user info:" 12 36 5 "username:" 1 1 "" 1 13 13 0 "UID" 2 1 "" 2 13 13 0 "Name:" 3 1 "" 3 13 13 0 "Home:" 4 1 "/home/" 4 13 13 12 "shell:" 5 1 "" 5 13 13 12 2> /tmp/form.out

US=`head -1 /tmp/msgbox.out`
NEID= `head -2 /tmp/msgbox.out | tail -1`
USNA= `head -3 /tmp/msgbox.out | tail -1`
HO= `head -4 /tmp/msgbox.out | tail -1`
SH= `head -5 /tmp/msgbox.out | tail -1`

if [ -z $US ];then

if ! cut -d: -f1 /etc/passwd | grep "^$US$" &> /dev/null; then

dialog --insecure --passwordbox "Your password:" 7 30 2> /tmp/password.out
RH=`head -1 /tmp/password.out`

echo "$US:x:${NEID:=$NUID}:$NGID::/home/${HO:=$US}:/bin/${SH:=bash}" >> /etc/passwd
echo "$US:${RH:=!!}:$DATE:0:99999:7:::" >> /etc/shadow
else
echo "$US exists."
exit 3
fi

if ! cut -d: -f1 /etc/group | grep "^$US$" &> /dev/null; then
echo "$US:x:$NGID:" >> /etc/group
else
echo "$US exists"
exit 3
fi
else exit 2
fi
cp -r /etc/skel /home/$US
chown -R $US:$US /home/$US
chmod -R go=--- /home/$US