Hi jaromil
Here is something I knocked up using dialog.
Pretty crude hack, but it may be a starting point for someone better
at it.
You've got to run "dialog create-rc <file>" before it will run.
If the GTK toolkit is available it can be translated into xdialog
with a prettier windowed interface.
Hope it helps those with terminal shyness.
Stomfi
#! /bin/sh
# $Id: form1,v 1.6 2004/03/13 16:06:51 tom Exp $
: ${DIALOG=dialog}
#Get next User ID. These normally start at 1000, so
#we'll loop round the /etc/passwd file until we find a spare
USRID=`awk -F":" '{if($3 >= 1000) EUID=$3};END{NUID=EUID+1;print NUID}' /etc/passwd`
USRNAME=""
USRLOGNAME=""
#Use the one from Luther
USRGRP="users"
USRHOME=""
USRSHELL="/bin/sh"
USRPASS=""
backtitle="Add New User"
returncode=0
while test $returncode != 1 && test $returncode != 250
do
exec 3>&1
value="`$DIALOG --ok-label "Submit" \
--backtitle "$backtitle" \
--form "Enter New User Login Name" \
10 50 0 \
"LOGIN NAME:" 1 1 "$USRLOGNAME" 1 15 15 0 2>&1 1>&3`"
returncode=$?
exec 3>&-
show=`echo "$value" |sed -e 's/^/ /'`
case $returncode in
1) "$DIALOG" \
--clear \
--backtitle "$backtitle" \
--yesno "Really quit?" 10 30
case $? in
0) break ;;
1) returncode=99 ;;
esac ;;
0) $DIALOG --title "SAVE?" \
--yesno "$show" 15 40
case $? in
0) #Check that field is filled before writing record,
#or give an error message
UERR=0
USRLOGNAME=`echo "$value"`
if [ ${#USRLOGNAME} -lt 1 ]; then
UERR=1
IMSG="You must fill in the field. This record will not be saved"
fi
if [ $UERR -eq 0 ]; then
ELUSR=`awk -F":" -v ULNAME="$USRLOGNAME" 'BEGIN{ GOTONE=0 };{if( $1 == ULNAME ) GOTONE=1 };END{ print GOTONE }' /etc/passwd`
fi
if [ $ELUSR -eq 1 ]; then
UERR=1
IMSG="User Login Name exists. This user will not be saved"
fi
if [ $UERR -eq 1 ]; then
$DIALOG --title "INPUT ERROR" --clear \
--msgbox "$IMSG" 10 41
case $? in
0) exit ;;
255) exit ;;
esac
else
USRNAME="$USRLOGNAME"
USRHOME="/home/$USRLOGNAME"
#Get the password
tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/test$$
$DIALOG --title "USER PASSWORD" --clear \
--insecure \
--passwordbox "Enter Password:" 16 51 2> $tempfile
retval=$?
PERR=0
case $retval in
0)
USRPASS=`cat $tempfile`
if [ ${#USRPASS} -lt 1 ]; then
USRPASS="stupid"
PMSG="Password set to \"stupid\". Change it as soon as you can"
PERR=1
fi
;;
1)
exit ;;
255)
if test -s $tempfile ; then
USRPASS=`cat $tempfile`
if [ ${#USRPASS} -lt 1 ]; then
USRPASS="stupid"
PMSG="Password set to \"stupid\". Change it as soon as you can"
#need a password changing script as well for
#the terminally shy.
PERR=1
fi
else
exit
fi
;;
esac
if [ $PERR -eq 1 ]; then
$DIALOG --title "INPUT ERROR" --clear \
--msgbox "$PMSG" 10 41
case $? in
0) : ;;
255) : ;;
esac
fi
rm -f $tempfile
useradd -d $USRHOME -m -s $USRSHELL -g $USRGRP -p $USRPASS -c $USRNAME $USRLOGNAME
exit
fi ;;
1) exit ;;
255) exit ;;
esac;;
*) exit ;;
esac
exit
done