#! /bin/sh PASSWDFILE=./passwd GROUPFILE=./group # function to show usage usage () { echo Usage: `basename $0` [-l login] [-c crypt] [-u uid] [-g gid] [-n gecos] [-h homedir] [-s shell] [-f] } # Parse the command-line arguments first while getopts l:c:u:g:n:h:s:f arg do case $arg in l) login=$OPTARG ;; c) crypt=$OPTARG ;; u) uid=$OPTARG ;; g) gid=$OPTARG ;; n) gecos=$OPTARG ;; h) home=$OPTARG ;; s) shell=$OPTARG ;; f) force="true" ;; *) usage; exit 1 ;; esac done # Login name has no default---must be specified if [ -z $login ] then if [ $force ] then echo "Login name must be specified" exit 2 fi echo -n "Login: " read login fi if [ -z $crypt ] then crypt=x if [ ! $force ] then echo -n "Crypt (default=$crypt): " read tmp_crypt test "$tmp_crypt" != "" && crypt=$tmp_crypt fi fi if [ -z $uid ] then uid=`cut -d: -f3 $PASSWDFILE | sort -n | uniq | awk '$1 >= 10000' | \ awk 'BEGIN { last = 9999 } $1 != ++last { print last; exit }'` if [ ! $force ] then echo -n "UID (default=$uid): " read tmp_uid test "$tmp_uid" != "" && uid=$tmp_uid fi fi if [ -z $gid ] then gid=`grep users $GROUPFILE | cut -d: -f3` if [ ! $force ] then echo -n "GID (default=$gid): " read tmp_gid test "$tmp_gid" != "" && gid=$tmp_gid fi fi if [ -z $gecos ] then gecos="No Name" if [ ! $force ] then echo -n "Gecos (default=$gecos): " read tmp_gecos test "$tmp_gecos" != "" && gecos=$tmp_gecos fi fi if [ -z $home ] then home="/home/$login" if [ ! $force ] then echo -n "Home (default=$home): " read tmp_home test "$tmp_home" != "" && home=$tmp_home fi fi if [ -z $shell ] then shell="/bin/sh" if [ ! $force ] then echo -n "Shell (default=$shell): " read tmp_shell test "$tmp_shell" != "" && shell=$tmp_shell fi fi if [ ! $force ] then echo "-> $login:$crypt:$uid:$gid:$gecos:$home:$shell <-" echo -n "Add this line to $PASSWDFILE? (y/n): " read ans else echo "Adding: $login:$crypt:$uid:$gid:$gecos:$home:$shell" ans=y fi if test "$ans" = "y" then echo "$login:$crypt:$uid:$gid:$gecos:$home:$shell" >>$PASSWDFILE else echo "$PASSWDFILE unchanged" fi