Subject: Re: vipw done. Now what?
To: James Burton <james@Snark.apana.org.au>
From: Giles Lean <giles@nemeton.com.au>
List: netbsd-help
Date: 01/07/1996 10:09:56
On Sat, 6 Jan 96 22:39:21 AEST  James Burton wrote:

I decided I'd post something. Here is James' script, translated to sh.

Perhaps, James, you could post the missing utilities (make-password,
fix_skeleton_file, setquota) along with your set of skeleton files?

#!/bin/sh
## Script to create a user home dir in /home/users
## From: James :jb Sun 12/3/95

USAGE="usage: adduser username realname password"

if [ $# != 3 ]
then
	echo $USAGE 1>&2
	exit 20
fi

if [ "`whoami`" != "root" ]
then
        echo "error: must be run by root" 1>&2
        echo "su or login to root first" 1>&2
        exit 20
fi

username="$1"
realname="$2"
newpassword="$3"
gid="100"
office="Office"
phone1="office-phone"
phone2="home-phone"
c=":"
z="0"
nothing=""
password="`/root/make-password $newpassword`"
homedir="/home/users/$username"
hostname="`hostname`"
fix_skeleton_file="/root/fix_skeleton_file"
class=""
#change=`date "+%b %d %y"`
change="0"
expire="0"

## Check that the username has not already been used
if id $username > /dev/null 2>&1
then
        echo "error: username $username has already been taken" 1>&2
        exit 20
fi

## Set the UID to the next available UID
uid="200"
quit=0
while [ $quit = 0 ]
do
        uid="`expr $uid + 1`"
        if ! id $uid > /dev/null 2>&1
	then
		quit=1
	fi
done

## Figure out the passwd database entry
line="$username$c$password$c$uid$c$gid$c$class$c$change$c$expire$c$realname,$office,$phone1,$phone2$c$homedir$c/bin/csh"

## Install the new passwd database entry
chpass -a "$line" $username

## Set up quotas for the new account
/root/bin/setquota -p /home -u $uid -b 4000 10000 -i 200 500

## Create a home dir from the 'users' skeleton,
cp -pR /usr/share/skel/users $homedir

## Fix .plan file
if [ -f $homedir/.plan ]
then
        $fix_skeleton_file $homedir/.plan "$username" "$realname" "$hostname"
fi

## Fix .signature file
if [ -f $homedir/.signature ]
then
        $fix_skeleton_file $homedir/.signature "$username" "$realname" "$hostname"
fi

## Fix home page directory
if [ -f $homedir/public_html/index.html ]
then
        $fix_skeleton_file $homedir/public_html/index.html "$username" "$realname" "$hostname"
fi

## and set the group,owner,mode for the complete hierarchy
chgrp -R users $homedir
chown -R $username $homedir
chmod -R 600 $homedir

## Make .plan world readable
if [ -f $homedir/.plan ]
then
        chmod 644 $homedir/.plan
fi

## Make home dir world searchable
chmod 711 $homedir

## Make public_html world searchable
if [ -d $homedir/public_html ]
then
        chmod 711 $homedir/public_html
fi

## Make home page world readable
if [ -f $homedir/public_html/index.html] 
then
        chmod 644 $homedir/public_html/index.html
fi

## Mail them the welcome message
if [ -f /root/new-account.msg ]
then
        if [ -f /tmp/new-account.msg ]
	then
                rm -f /tmp/new-account.msg
        fi
        cp /root/new-account.msg /tmp/new-account.msg
        $fix_skeleton_file /tmp/new-account.msg "$username" "$realname" "$hostname"
        /usr/bin/mail -s "Welcome to ArtWorks" $username < /tmp/new-account.msg
        rm /tmp/new-account.msg
fi