[Slackbuilds-users] uids/gids

Biff Eros bifferos at gmail.com
Tue Mar 31 07:51:58 UTC 2020

I think there was some reason I couldn't rely on getent being present when
I wrote that code, initially I was using it in the context of a minimal
install but you are right, I will make that change, thanks for letting me

On Tue, Mar 31, 2020, 3:59 AM B Watson <yalhcru at gmail.com> wrote:

> On 3/30/20, Biff Eros <bifferos at gmail.com> wrote:
> > I started off manually creating user/group creation scripts for
> > Afterpkg, looking a bit like this:
> >
> https://github.com/bifferos/afterpkg/blob/master/scripts/system/mongodb/before.sh
> Interesting project... not sure I'd want to mix-and-match pip-installed
> and SBo-installed stuff, but if someone does want to, your script looks
> like it should handle it well.
> The before.sh you linked does something horrible though. Nobody should
> ever grep /etc/passwd and/or group to see if a user exists (what if
> they're using LDAP authentication? NIS? In 15.0 we're going to have PAM,
> what if they're using something we never even heard of before?)
> Instead use getent. Like so:
> ---cut-here---
> #!/bin/bash
> # Create the mongo group
> if getent group mongo >/dev/null ; then
>   echo "mongo group exists, no need to add it"
> else
>   echo "Creating mongo group"
>   groupadd -r -g 285 mongo
> fi
> # Create the mongo user
> if getent passwd mongo >/dev/null ; then
>   echo "mongo user exists, no need to add it"
> else
>   echo "Creating mongo user"
>   useradd -u 285 -d /var/lib/mongodb -s /bin/false -g mongo mongo
> fi
> ---cut-here---
> Notice it's a pretty minor change: only the two "if grep" lines are
> different. getent is is part of glibc, so it's guaranteed to be present
> on any Slack box that's able to compile anything.
> If you're generating the uid/gid creation scripts, I guess you only have
> to change it in one place (the generator script).
> _______________________________________________
> SlackBuilds-users mailing list
> SlackBuilds-users at slackbuilds.org
> https://lists.slackbuilds.org/mailman/listinfo/slackbuilds-users
> Archives - https://lists.slackbuilds.org/pipermail/slackbuilds-users/
> FAQ - https://slackbuilds.org/faq/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.slackbuilds.org/pipermail/slackbuilds-users/attachments/20200331/a942f372/attachment.htm>

More information about the SlackBuilds-users mailing list