[RFC] BLFS profile group/user creation

Kevin P. Fleming kpfleming at linuxfromscratch.org
Thu Oct 21 12:06:53 PDT 2004


Throughout the profile, we use some common idioms for creating users and 
groups needed for packages. However, the current methods have some 
problems...

-- Users --

Currently, we use

{execute command="grep -q ^username /etc/passwd || useradd"}
   ...
   {param}username{/param}
{/execute}

However, this fails if the system is using any alternative methods of 
providing usernames (NIS, winbind, etc.), and it also doesn't take into 
account that there may be multiple usernames that start with the same 
string.

A better solution is:

{execute command="getent passwd username > /dev/null || useradd"}
   ...
   {param}username{/param}
{/execute}

This will search for the username using whatever means the system is 
configured to do, and won't find a similar (but longer) username.

-- Groups --

Currently, we use

{execute command="groupadd"}
   {param}-f{/param}
   {param}groupname{/param}
{/execute}

This fails if the group already exists, because groupadd returns a 
failure. It also fails if the system is using an alternative source of 
groupnames.

A better solution is:

{execute command="getent group groupname > /dev/null || groupadd"}
   {param}groupname{/param}
{/execute}

If there is agreement that this is the right way to go, anyone want to 
tackle converting the profile over to these methods?



More information about the alfs-discuss mailing list