All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* Correct way for multiple recipes to install files in the same directory
@ 2024-04-11  7:52 linusnilsson
  2024-04-11  8:02 ` [yocto] " Markus Volk
  2024-04-11  8:45 ` Marko, Peter
  0 siblings, 2 replies; 10+ messages in thread
From: linusnilsson @ 2024-04-11  7:52 UTC (permalink / raw
  To: yocto

[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]

Hi!
How/can I let multiple recipes install files in the same directory without getting a conflict during bitbake process?

Recipe 1 creates a user and its homedir:
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM:${PN} = "-u 1000 -d /home/user1 -m -s /bin/bash -p 'XXX' user1"
do_install(){
install -d ${D}/home/user1
chown -R user1:user1 ${D}/home/user1
}

Recipe 2 wants to install some config-files inside /home/user1/.config/.
DEPENDS = "recipe1"
RDEPENDS:${PN} = "recipe1"
do_install(){
install -d ${D}/home/user1/.config/
install -m 0644 sourcefile ${D}/home/user1/.config/
chown -R user1:user1 ${D}/home/user1/.config/
}

There is also FILES directives at the end of each recipe for the corresponding files. For better readability I've removed everything that I deemed was irrelevant.
The problem I get when trying to bitbake the image is during the do_rootfs stage:
file /home/user1 conflicts between attempted installs of <recipe2> and <recipe1>

If I comment out the "chown" line from both recipes it seems to work but then I guess those directories will be owned by root during runtime, which will be a problem for user1.

Is there a proper way to do this?

Kind regards, Linus

[-- Attachment #2: Type: text/html, Size: 1436 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-11  7:52 Correct way for multiple recipes to install files in the same directory linusnilsson
@ 2024-04-11  8:02 ` Markus Volk
  2024-04-11  8:45 ` Marko, Peter
  1 sibling, 0 replies; 10+ messages in thread
From: Markus Volk @ 2024-04-11  8:02 UTC (permalink / raw
  To: yocto, linusnilsson

[-- Attachment #1: Type: text/plain, Size: 634 bytes --]

On Thu, Apr 11 2024 at 12:52:49 AM -07:00:00, linusnilsson@hotmail.com 
wrote:
> Is there a proper way to do this?
> 
> Kind regards, Linus

Hi,
can't tell if this would be a proper way, but this is how I do it and 
what works for me:

Create a main user:
<https://codeberg.org/flk/meta-image/src/branch/master/recipes-extended/system-config/main-user.bb>

Inherit a main-user class for every recipe that wants to write stuff to 
/home/user
<https://codeberg.org/flk/meta-image/src/branch/master/classes/main-user.bbclass>

You can override the values set in main-user.bbclass to fit your needs 
in e.g. local.conf

Regards,
Markus



[-- Attachment #2: Type: text/html, Size: 1099 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-11  7:52 Correct way for multiple recipes to install files in the same directory linusnilsson
  2024-04-11  8:02 ` [yocto] " Markus Volk
@ 2024-04-11  8:45 ` Marko, Peter
  2024-04-11 12:37   ` linusnilsson
  1 sibling, 1 reply; 10+ messages in thread
From: Marko, Peter @ 2024-04-11  8:45 UTC (permalink / raw
  To: yocto@lists.yoctoproject.org, linusnilsson@hotmail.com

[-- Attachment #1: Type: text/plain, Size: 1751 bytes --]

From: yocto@lists.yoctoproject.org <yocto@lists.yoctoproject.org> On Behalf Of linusnilsson via lists.yoctoproject.org
Sent: Thursday, April 11, 2024 9:53
To: yocto@lists.yoctoproject.org
Subject: [yocto] Correct way for multiple recipes to install files in the same directory


> Hi!
> How/can I let multiple recipes install files in the same directory without getting a conflict during bitbake process?
>
> Recipe 1 creates a user and its homedir:
> inherit useradd
> USERADD_PACKAGES = "${PN}"
> USERADD_PARAM:${PN} = "-u 1000 -d /home/user1 -m -s /bin/bash -p 'XXX' user1"
> do_install(){
>  install -d ${D}/home/user1
>  chown -R user1:user1 ${D}/home/user1
> }
>
> Recipe 2 wants to install some config-files inside /home/user1/.config/.
> DEPENDS = "recipe1"
> RDEPENDS:${PN} = "recipe1"
> do_install(){
>  install -d ${D}/home/user1/.config/
>  install -m 0644 sourcefile ${D}/home/user1/.config/
>  chown -R user1:user1 ${D}/home/user1/.config/

Have you tried to change this line to

chown -R user1:user1 ${D}/home/user1

The error may come from fact that directory /home/user1 has different ownership in both recipes
> }
>
> There is also FILES directives at the end of each recipe for the corresponding files. For better readability I've removed everything that I deemed was irrelevant.
> The problem I get when trying to bitbake the image is during the do_rootfs stage:
> file /home/user1 conflicts between attempted installs of <recipe2> and <recipe1>
>
> If I comment out the "chown" line from both recipes it seems to work but then I guess those directories will be owned by root during runtime, which will be a problem for user1.
>
> Is there a proper way to do this?
>
> Kind regards, Linus

[-- Attachment #2: Type: text/html, Size: 5539 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-11  8:45 ` Marko, Peter
@ 2024-04-11 12:37   ` linusnilsson
  2024-04-11 14:36     ` linusnilsson
  2024-04-11 19:30     ` Marko, Peter
  0 siblings, 2 replies; 10+ messages in thread
From: linusnilsson @ 2024-04-11 12:37 UTC (permalink / raw
  To: Peter Marko, yocto

[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]

Changing in recipe 2 from
chown -R user1:user1 ${D}/home/user1/.config/
to
chown -R user1:user1 ${D}/home/user1
actually seems to solve the problem with those particular recipes.

After getting a bit further in the bitbake process I now have the same problem with another recipe that wants to add custom files to /etc/polkit-1/rules.d/ but this recipe doesn't contain any 'chown' statement so I can't apply the same solution here.
file /etc/polkit-1/rules.d conflicts between attempted installs of disk-automount-0.1-r0.core2_64 and polkit-124-r0.core2_64

disk-automount-0.1 recipe contains:
do_install(){
install -d ${D}/${sysconfdir}/polkit-1/rules.d
install -m 0644 ${S}/00-mount-internal.rules ${D}/${sysconfdir}/polkit-1/rules.d
}

polkit-124 recipe contains:
do_install:append() {
#Fix up permissions on polkit rules.d to work with rpm4 constraints
chmod 700 ${D}/${datadir}/polkit-1/rules.d
chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d
chown polkitd:root ${D}/${datadir}/polkit-1/rules.d
chown polkitd:root ${D}/${sysconfdir}/polkit-1/rules.d
}

Since polkit is maintained by yocto I want to avoid making changes to it but rather adapt my disk-automount recipe somehow since the problem probably is on my end.
IIRC install -d will set the permissions to 0755 unless otherwise specified which might conflict with polkit's chmod 700 so I might try copying chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d to my disk-automount recipe.

[-- Attachment #2: Type: text/html, Size: 1978 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-11 12:37   ` linusnilsson
@ 2024-04-11 14:36     ` linusnilsson
  2024-04-11 19:30     ` Marko, Peter
  1 sibling, 0 replies; 10+ messages in thread
From: linusnilsson @ 2024-04-11 14:36 UTC (permalink / raw
  To: linusnilsson, yocto

[-- Attachment #1: Type: text/plain, Size: 365 bytes --]

After adding
chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d
chown polkit:root ${D}/${sysconfdir}/polkit-1/rules.d
to the disk-automount recipe I get error with chown not knowing about the polkit user, even though I've added polkit to both DEPENDS and RDEPENDS of disk-automount recipe so now I've got figure out how to make it aware that the user polkit exists.

[-- Attachment #2: Type: text/html, Size: 390 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-11 12:37   ` linusnilsson
  2024-04-11 14:36     ` linusnilsson
@ 2024-04-11 19:30     ` Marko, Peter
  2024-04-12  6:07       ` linusnilsson
  1 sibling, 1 reply; 10+ messages in thread
From: Marko, Peter @ 2024-04-11 19:30 UTC (permalink / raw
  To: linusnilsson@hotmail.com, yocto@lists.yoctoproject.org

[-- Attachment #1: Type: text/plain, Size: 1911 bytes --]

Obvious solution is to copy chmod command to your recipe.
Peter

From: linusnilsson via Lists.Yoctoproject.Org <linusnilsson=hotmail.com@lists.yoctoproject.org>
Sent: Thursday, April 11, 2024 14:38
To: Marko, Peter (ADV D EU SK BFS1) <Peter.Marko@siemens.com>; yocto@lists.yoctoproject.org
Subject: Re: [yocto] Correct way for multiple recipes to install files in the same directory

> Changing in recipe 2 from
> chown -R user1:user1 ${D}/home/user1/.config/
> to
> chown -R user1:user1 ${D}/home/user1
> actually seems to solve the problem with those particular recipes.
>
> After getting a bit further in the bitbake process I now have the same problem with another recipe that wants to add custom files to /etc/polkit-1/rules.d/ but this recipe doesn't contain any 'chown' statement so I can't apply the same solution here.
> file /etc/polkit-1/rules.d conflicts between attempted installs of disk-automount-0.1-r0.core2_64 and polkit-124-r0.core2_64
>
> disk-automount-0.1 recipe contains:
> do_install(){
>  install -d ${D}/${sysconfdir}/polkit-1/rules.d
>  install -m 0644 ${S}/00-mount-internal.rules ${D}/${sysconfdir}/polkit-1/rules.d
> }
>
> polkit-124 recipe contains:
> do_install:append() {
>  #Fix up permissions on polkit rules.d to work with rpm4 constraints
>  chmod 700 ${D}/${datadir}/polkit-1/rules.d
>  chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d
>  chown polkitd:root ${D}/${datadir}/polkit-1/rules.d
>  chown polkitd:root ${D}/${sysconfdir}/polkit-1/rules.d
> }
>
> Since polkit is maintained by yocto I want to avoid making changes to it but rather adapt my disk-automount recipe somehow since the problem probably is on my end.
> IIRC install -d will set the permissions to 0755 unless otherwise specified which might conflict with polkit's chmod 700 so I might try copying chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d to my disk-automount recipe.

[-- Attachment #2: Type: text/html, Size: 5568 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-11 19:30     ` Marko, Peter
@ 2024-04-12  6:07       ` linusnilsson
  2024-04-12 16:14         ` Linus Nilsson
  0 siblings, 1 reply; 10+ messages in thread
From: linusnilsson @ 2024-04-12  6:07 UTC (permalink / raw
  To: Peter Marko, yocto

[-- Attachment #1: Type: text/plain, Size: 306 bytes --]

> 
> Obvious solution is to copy chmod command to your recipe.

Yes and I did that but that line alone didn't suffice. I also had to copy the 'chown'-line but since the polkit user was created in another recipe it is not recognized in this recipe and so I have to somehow figure out a way to fix that.

[-- Attachment #2: Type: text/html, Size: 323 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-12  6:07       ` linusnilsson
@ 2024-04-12 16:14         ` Linus Nilsson
  2024-04-12 22:48           ` Markus Volk
  0 siblings, 1 reply; 10+ messages in thread
From: Linus Nilsson @ 2024-04-12 16:14 UTC (permalink / raw
  To: Linus Nilsson, yocto

[-- Attachment #1: Type: text/plain, Size: 2005 bytes --]

I found a solution and I'll try to break it down. There was the original problem with the conflict between the recipes and then there were the problem with the recipe not being aware of the existence of the user polkitd.

The solution for the first problem was to make sure that the permissions and ownership set by my recipe 2 matches the one in recipe 1 exactly, hence:
> 
> 
> Changing in recipe 2 from
> chown -R user1:user1 ${D}/home/user1/.config/
> to
> chown -R user1:user1 ${D}/home/user1/
> actually seems to solve the problem with those particular recipes.

The solution to the second problem (disk-automount recipe bitbake error because user polkitd is invalid) was to copy the creation of the user polkitd from the original polkit recipe into my recipe:
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM:${PN} = "--system --no-create-home --user-group --home-dir ${sysconfdir}/${BPN}-1 --shell /bin/nologin polkitd"

and then make sure that my disk-automount recipe matches the permissions and ownerships set up by the polkit recipe as well:
do_install:append() {
#Fix up permissions on polkit rules.d to work with rpm4 constraints
chmod 700 ${D}/${datadir}/polkit-1/rules.d
chmod 700 ${D}/${sysconfdir}/polkit-1/rules.d
chown polkitd:root ${D}/${datadir}/polkit-1/rules.d
chown polkitd:root ${D}/${sysconfdir}/polkit-1/rules.d
}

This is working but I can see some issues with copying code from one recipe to another. If the original recipe changes, I will need to manually update every one of my own recipes with the corresponding changes, which doesn't scale very well. Having this in mind I think that Markus Volk's post might be a nicer way to do things so I think I will consider his way of doing it in the future. I haven't worked with the classes yet but I can see how they can be used to make things a lot easier in my case.

Big thanks and great appreciation to everyone who came up with suggestions, they eventually led me towards a solution! :)

[-- Attachment #2: Type: text/html, Size: 2478 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-12 16:14         ` Linus Nilsson
@ 2024-04-12 22:48           ` Markus Volk
  2024-04-13 10:16             ` Sv: " Linus Nilsson
  0 siblings, 1 reply; 10+ messages in thread
From: Markus Volk @ 2024-04-12 22:48 UTC (permalink / raw
  To: yocto, linusnilsson

[-- Attachment #1: Type: text/plain, Size: 354 bytes --]

On Fri, Apr 12 2024 at 09:14:45 AM -07:00:00, Linus Nilsson 
<linusnilsson@hotmail.com> wrote:
> I haven't worked with the classes yet but I can see how they can be 
> used to make things a lot easier in my case.

But don't use classen too invasively. They can be problematic, e.g. an 
:append may be ignored depending on the BBFILE_PRIORITY of a layer


[-- Attachment #2: Type: text/html, Size: 454 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Sv: [yocto] Correct way for multiple recipes to install files in the same directory
  2024-04-12 22:48           ` Markus Volk
@ 2024-04-13 10:16             ` Linus Nilsson
  0 siblings, 0 replies; 10+ messages in thread
From: Linus Nilsson @ 2024-04-13 10:16 UTC (permalink / raw
  To: Markus Volk, yocto@lists.yoctoproject.org

[-- Attachment #1: Type: text/plain, Size: 803 bytes --]

As I have no prior experience with classes I'll have to read through the manual to learn and I'll have that in mind, cheers. 🙂
________________________________
Från: Markus Volk <f_l_k@t-online.de>
Skickat: den 13 april 2024 00:48
Till: yocto@lists.yoctoproject.org <yocto@lists.yoctoproject.org>; linusnilsson@hotmail.com <linusnilsson@hotmail.com>
Ämne: Re: [yocto] Correct way for multiple recipes to install files in the same directory

On Fri, Apr 12 2024 at 09:14:45 AM -07:00:00, Linus Nilsson <linusnilsson@hotmail.com> wrote:
I haven't worked with the classes yet but I can see how they can be used to make things a lot easier in my case.

But don't use classen too invasively. They can be problematic, e.g. an :append may be ignored depending on the BBFILE_PRIORITY of a layer

[-- Attachment #2: Type: text/html, Size: 1534 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-04-13 10:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-11  7:52 Correct way for multiple recipes to install files in the same directory linusnilsson
2024-04-11  8:02 ` [yocto] " Markus Volk
2024-04-11  8:45 ` Marko, Peter
2024-04-11 12:37   ` linusnilsson
2024-04-11 14:36     ` linusnilsson
2024-04-11 19:30     ` Marko, Peter
2024-04-12  6:07       ` linusnilsson
2024-04-12 16:14         ` Linus Nilsson
2024-04-12 22:48           ` Markus Volk
2024-04-13 10:16             ` Sv: " Linus Nilsson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.