Subject: addnerd & friends
To: None <tech-pkg@netbsd.org>
From: Tomasz Luchowski <zuntum@netbsd.org>
List: tech-pkg
Date: 08/12/2001 18:40:31
Hi,
I'm still working on qmail package. My script which adds necessary users & groups
now looks like:
#!/bin/sh
#
# $NetBSD$
#
PASSWDFILE=/etc/passwd
NOSHELL=/sbin/nologin
CHFN=/usr/bin/chfn
AWK=/usr/bin/awk
GREP=/usr/bin/grep
QMAILDIR=/var/qmail
create_group()
{
GROUP=$1
$GREP "^$GROUP" $GROUPFILE > /dev/null || (
FREEGID=`$AWK -F: '{gids[$3]++}END{for (i=81;;i++) if (gids[i] == 0) {print i;exit 0}}' < ${GROUPFILE}`
echo "$GROUP:*:$FREEGID:" >> /etc/group
)
return
}
create_user()
{
NAME=$1
if [ "$NAME" = alias ]; then
HOME="$QMAILDIR/alias"
else
HOME="$QMAILDIR"
fi
( id $NAME 2> /dev/null > /dev/null ) || (
FREEUID=`$AWK -F: '{uids[$3]++}END{for (i=81;;i++) if (uids[i] == 0) {print i;exit 0}}' < ${PASSWDFILE}`
GROUP=`$GREP $2 $GROUPFILE | $AWK -F: '{ print $4 }'`
$CHFN -a $NAME:*:$FREEUID:$GROUP::0:0:$NAME:$HOME:/sbin/nologin
) && echo "user $NAME already exists, skipping addition"
return
}
create_group qmail
create_group nofiles
create_user alias nofiles
create_user qmaill nofiles
create_user qmaild nofiles
create_user qmailp nofiles
create_user qmailq qmail
create_user qmailr qmail
create_user qmails qmail
Yes, it looks very dirty. I could use groupinfo instead of greping /etc/group,
but groupinfo does not exist on pre-1.5 systems. I was said that grep won't work in all cases,
for example when one uses NIS etc. For now, I see no good way to do it.
useradd appeared in NetBSD 1.5, too, thus I decided to use "chfn -a". But this forces me to find a free uid,
so I have to use awk.
Thoughts how to implement this better?
--
/* Tomasz Luchowski <zuntum@netbsd.org> */