Subject: Re: vipw done. Now what?
To: None <netbsd-help@NetBSD.ORG>
From: James Burton <james@Snark.apana.org.au>
List: netbsd-help
Date: 01/06/1996 22:39:21
Hi Hume,

> on many UNIXes (like the UNISYS SYS V i had two systems ago) there -is-
> an adduser command.  i wish someone would write one; while it's not
> hard to add a user, it gets tedious after the first fifty :)
> Hume Smith   <hclsmith@isisnet.com>   NetBSD r00lz :)

I think everybody seems to write their own.

Just out of interest here is mine, although it uses some
other bits&pieces that I had to write to make it do the
right thing.


James


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

if ($#argv != 3) then
        echo "error: incorrect arguments"
        echo "usage: make_user <username> <realname> <password>"
        exit 20
endif

if ("`whoami`" != "root") then
        echo "error: must be run by root"
        echo "su or login to root first"
        exit 20
endif

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

## Check that the username has not already been used
id $username >& /dev/null
if ($status == 0) then
        echo "error: username $username has already been taken"
        exit 20
endif

## Set the UID to the next available UID
## don't know why, but have to store the $status otherwise gets lost...
## I guess the 'end' in the 'while' loop squashes it
set uid="200"
id $uid >& /dev/null
set quit=$status
while ($quit == 0)
        echo "$uid in use"
        set uid="`expr $uid + 1`"
        id $uid >& /dev/null
        set quit=$status
end

## Figure out the passwd database entry
set 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"
endif

## Fix .signature file
if (-f $homedir/.signature) then
        $fix_skeleton_file $homedir/.signature "$username" "$realname" "$hostname"
endif

## Fix home page directory
if (-f $homedir/public_html/index.html) then
        $fix_skeleton_file $homedir/public_html/index.html "$username" "$realname" "$hostname"
endif

## 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
endif

## Make home dir world searchable
chmod 711 $homedir

## Make public_html world searchable
if (-d $homedir/public_html) then
        chmod 711 $homedir/public_html
endif

## Make home page world readable
if (-f $homedir/public_html/index.html) then
        chmod 644 $homedir/public_html/index.html
endif

## Mail them the welcome message
if (-f /root/new-account.msg) then
        if (-f /tmp/new-account.msg) then
                rm /tmp/new-account.msg
        endif
        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
endif


## End of File
-----


-- 
James Burton, Melbourne, Australia.|Every jumbled pile of person has a
James@Snark.apana.org.au           |thinking part that wonders what the 
http://Snark.APANA.org.au/james/   |part that isn't thinking isn't thinking of