You are not logged in.

#1 2019-06-16 20:16:39

josephg
Member
From: Brazil
Registered: 2009-09-28
Posts: 106

[SOLVED] How to chown new directory + creating user in PKGBUILD

TL;DR: In a PKGBUILD, how do I created a system user home folder and set user/group when creating the user without ID ("-") with a sysusers.d config file ?

I'm packaging a service which I want to run a custom user (not root). Let's say the user is foo and its home folder /var/lib/foo.

I created the file foo-sysusers.conf (following sysusers.d(5)):

#Type  Name   ID     GECOS         Home directory
u      foo    -      "FOO user"    /var/lib/foo

(notice how I left ID as "-" which means I prefer to not define UID / GID of the user / group)

Then the PKGBUILD installs it:

install -vDm644 "$srcdir/foo-sysusers.conf" "$pkgdir/usr/lib/sysusers.d/foo.conf"

and, as expected, the user/group are created after the package is installed when the post-installation pacman hook is triggered.

If I create the home folder /var/lib/foo in PKGBUILD, I'm unable to set owner to the foo user as it doesn't exists yet. Can't use post-install() from .install file as well, as .install files runs before pacman hooks, so the foo user still doesn't exist.

I notice a few official packages that set the users's UID in the sysuser.d conf file, therefore installing the home folder using the UID/GID instead of the user name. e.g. gdm

Any idea to set user/group of home folder ("/var/lib/foo") without hardcoding UID/GID if the user ("foo") ?

Last edited by josephg (2019-06-16 21:04:11)

Offline

#2 2019-06-16 21:03:31

josephg
Member
From: Brazil
Registered: 2009-09-28
Posts: 106

Re: [SOLVED] How to chown new directory + creating user in PKGBUILD

It seems that using tmpfiles.d(5) config files is the way to go. I thought it would create a temporary file with lifetime being the active service or something, but it enables to create a directory with the newly created user/group which is not deleted even when the package is removed.

Last edited by josephg (2019-06-16 21:05:03)

Offline

Board footer

Powered by FluxBB