[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Create user during installation

On Thu, 2005-03-31 at 22:18 +0200, Shachar Shemesh wrote:
> Hi all,
> This question is about a package that will likely not make it into 
> Debian (too specific). I even suspect this has some relevance.
> I would like to install a package that creates it's own special user and 
> group during installation. I have utterly and totally failed to find a 
> ready made package that does that, with the sole exception of qmail-src 
> (from non-free) that creates them in the 655xx area. Not exactly what I 
> would like to do.
> How do I create said user and group? How do I tell between useradd or 
> adduser failing due to user already existing, and other unrelated 
> reasons? Do I at all need to care about that?


grep for 'adduser' in /var/lib/dpkg/info/*postinst to see some examples.
You can use getent(1) to check for the existence of a user.

Here is what I do (package gpsd):

|        # create user gpsd
|        getent passwd gpsd > /dev/null || \
|                adduser --system \
|                        --home "/nonexistent" --no-create-home \
|                        --disabled-password --ingroup dialout \
|                        --gecos "GPS daemon user" gpsd

| if [ "x$1" = "xpurge" ] ; then
|         getent passwd gpsd > /dev/null && deluser gpsd
| fi

Cheers, Til

Attachment: signature.asc
Description: This is a digitally signed message part

Reply to: