#! /bin/sh #---------------------------------------------------------------------------- # add-user - add user # # Copyright (c) 2001-2003 Frank Meyer # # usage: add-user # or: add-user user encrypted-password uid gid name home shell # # if password is empty, user will be prompted # if uid or gid is empty, values will be evaluated # # Creation: 04.11.2001 fm # Last Update: 13.08.2003 fm # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- case $# in 0) interactive='true' user="" password="" uid="" gid="" name="" home="" shell="" ;; 7) interactive='false' user="$1" password="$2" uid="$3" gid="$4" name="$5" home="$6" shell="$7" ;; *) echo "usage: `basename $0`" >&2 echo " or: `basename $0` user encrypted-password uid gid name home shell" >&2 exit 1 ;; esac if [ "$interactive" = "true" ] then clrhome colecho "Add user" gn echo fi if [ "$uid" = "" ] then IFS=':' uid=2000 while read line do set -- $line if [ $3 -gt $uid -a $3 -lt 3000 ] then uid=$3 fi done /dev/null if [ $? = 0 ] then echo colecho "user-id $user already exists" br x br else if [ "$name" = "" ] then echo -e "Name of user: \c" read name fi if [ "$gid" = "" ] then gid=100 fi if [ "$home" = "" ] then home=/home/$user fi if [ "$shell" = "" ] then shell=/bin/sh fi echo "$user:x:$uid:$gid:$name:$home:$shell" >>/etc/passwd echo "$user:$password:11622:0:99999:7:::" >>/etc/shadow grep "^users:" /etc/group >/dev/null if [ $? != 0 ] then echo "users:x:100:" >>/etc/group fi if [ "$password" = "" ] then passwd $user fi if [ ! -d $home ] then mkdir $home chown $user $home chgrp $gid $home chmod 755 $home fi fi ;; esac if [ "$interactive" = "true" ] then echo /var/install/bin/anykey fi