All of lore.kernel.org
 help / color / mirror / Atom feed
* Mechanism behind pkg_postinst_ontarget_${PN} #yocto
@ 2020-03-27  8:14 stefan.wenninger
  2020-03-27  8:52 ` [yocto] " Alexander Kanavin
  0 siblings, 1 reply; 10+ messages in thread
From: stefan.wenninger @ 2020-03-27  8:14 UTC (permalink / raw)
  To: yocto

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

Hi,
I am trying to execute a few shell commands the first time a new image boots. The Yocto built-in mechanism for that should be pkg_postinst_ontarget_${PN}.
However I can not get the commands I put within that function to execute. I am having a hard time trying to figure out what the problem is.
I am installing the new image to my board via SWUpdate. My suspicion is that the mechanism behind the pkg_postinst_ontarget_${PN} is somehow hindered by the SWUpdate utility.
I could imagine that whatever mechanism is used might me surpressed/ignored by the SWUpdate process.

That is why im asking about the exact mechanism within Linux that is used to execute the contents of the pkg_postinst_ontarget_${PN} function on first boot.

As a reference:
Yocto version: sumo
pkg_postinst_ontarget_${PN} () {
#!/bin/sh
file=$D/home/root/test.txt
printf "hello world\n" > $file
}

Thanks in advance
Stefan Wenninger

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

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

* Re: [yocto] Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27  8:14 Mechanism behind pkg_postinst_ontarget_${PN} #yocto stefan.wenninger
@ 2020-03-27  8:52 ` Alexander Kanavin
  2020-03-27  9:06   ` stefan.wenninger
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Kanavin @ 2020-03-27  8:52 UTC (permalink / raw)
  To: stefan.wenninger; +Cc: yocto

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

You can start by inspecting your image's rootfs, the scripts to run on
first boot should be in /etc/ somewhere. Are they?

Alex

On Fri, 27 Mar 2020 at 09:14, <stefan.wenninger@evopro-ag.de> wrote:

> Hi,
> I am trying to execute a few shell commands the first time a new image
> boots. The Yocto built-in mechanism for that should be
> *pkg_postinst_ontarget_${PN}.*However I can not get the commands I put
> within that function to execute. I am having a hard time trying to figure
> out what the problem is.
> I am installing the new image to my board via SWUpdate. My suspicion is
> that the mechanism behind the *pkg_postinst_ontarget_${PN}* is somehow
> hindered by the SWUpdate utility.
> I could imagine that whatever mechanism is used might me
> surpressed/ignored by the SWUpdate process.
>
> That is why im asking about the exact mechanism within Linux that is used
> to execute the contents of the *pkg_postinst_ontarget_${PN}* function on
> first boot.
>
> As a reference:
> Yocto version: sumo
> pkg_postinst_ontarget_${PN} () {
> #!/bin/sh
> file=$D/home/root/test.txt
> printf "hello world\n" > $file
> }
>
> Thanks in advance
> Stefan Wenninger 
>

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

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

* Re: Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27  8:52 ` [yocto] " Alexander Kanavin
@ 2020-03-27  9:06   ` stefan.wenninger
  2020-03-27  9:09     ` [yocto] " Alexander Kanavin
  0 siblings, 1 reply; 10+ messages in thread
From: stefan.wenninger @ 2020-03-27  9:06 UTC (permalink / raw)
  To: yocto

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

Hi Alex,
Im not sure if my previous reply got sent/reached you. I apologise in case you receive this message twice.

Should there be a script in /etc created from my pkg_postinst_ontarget_${PN} function? If yes, what would its name be?

Stefan

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

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

* Re: [yocto] Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27  9:06   ` stefan.wenninger
@ 2020-03-27  9:09     ` Alexander Kanavin
  2020-03-27  9:26       ` stefan.wenninger
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Kanavin @ 2020-03-27  9:09 UTC (permalink / raw)
  To: stefan.wenninger; +Cc: yocto

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

Actually, that depends on which package format you use. The script that
executes the postinsts on target can be found in
meta/recipes-devtools/run-postinsts/run-postinsts/run-postinsts.

Alex

On Fri, 27 Mar 2020 at 10:06, <stefan.wenninger@evopro-ag.de> wrote:

> Hi Alex,
> Im not sure if my previous reply got sent/reached you. I apologise in case
> you receive this message twice.
>
> Should there be a script in /etc created from my
> *pkg_postinst_ontarget_${PN}* function? If yes, what would its name be?
>
> Stefan 
>

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

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

* Re: Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27  9:09     ` [yocto] " Alexander Kanavin
@ 2020-03-27  9:26       ` stefan.wenninger
  2020-03-27  9:30         ` [yocto] " Alexander Kanavin
  0 siblings, 1 reply; 10+ messages in thread
From: stefan.wenninger @ 2020-03-27  9:26 UTC (permalink / raw)
  To: yocto

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

I am using deb as my package class. What I am gathering from that run-postinsts directory is that there is a systemd service that starts and executes the run-postinsts script.
That script looks for a directory /etc/deb-postinsts and executes all scripts in there. Does that mean, that the mechanism used in the end is the post-install scripts of deb packages?
So basically the pkg_postinst_ontarget_${PN} function adds a postinstall script to the .deb package of the recipe it is in, correct?
That should mean that I can expect to see a script in /etc/deb-postinsts that contains my commands. I will verify that right away.

If these assumptions are correct, you have already greatly improved my understanding of this process. Thank you for that.

Stefan

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

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

* Re: [yocto] Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27  9:26       ` stefan.wenninger
@ 2020-03-27  9:30         ` Alexander Kanavin
  2020-03-27 12:26           ` stefan.wenninger
  0 siblings, 1 reply; 10+ messages in thread
From: Alexander Kanavin @ 2020-03-27  9:30 UTC (permalink / raw)
  To: stefan.wenninger; +Cc: yocto

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

I am not sure about deb-postinsts. What I see the script doing is:

eval dpkg --configure -a $append_log

Alex

On Fri, 27 Mar 2020 at 10:26, <stefan.wenninger@evopro-ag.de> wrote:

> I am using deb as my package class. What I am gathering from that
> run-postinsts directory is that there is a systemd service that starts and
> executes the run-postinsts script.
> That script looks for a directory /etc/deb-postinsts and executes all
> scripts in there. Does that mean, that the mechanism used in the end is the
> post-install scripts of deb packages?
> So basically the *pkg_postinst_ontarget_${PN}* function adds a
> postinstall script to the .deb package of the recipe it is in, correct?
> That should mean that I can expect to see a script in /etc/deb-postinsts
> that contains my commands. I will verify that right away.
>
> If these assumptions are correct, you have already greatly improved my
> understanding of this process. Thank you for that.
>
> Stefan 
>

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

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

* Re: Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27  9:30         ` [yocto] " Alexander Kanavin
@ 2020-03-27 12:26           ` stefan.wenninger
  2020-03-27 13:09             ` [yocto] " Quentin Schulz
  0 siblings, 1 reply; 10+ messages in thread
From: stefan.wenninger @ 2020-03-27 12:26 UTC (permalink / raw)
  To: yocto

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

I think the relevant part for me in that script is the func exec_postinst_scriplets(). It looks to me as if this function iterates through all scripts in the /etc/deb-postinsts directory in my case and executes them with "sh".
My problem seems to have stemmed from confusion on my part about what package the postinst attaches to.
The postinst belongs to the package with the same name as my recipe because of the _${PN}. However I specified that my recipe produces another package with the PROVIDES ="" variable.
In my IMAGE_INSTALL I only added the package I specifically provide. Therefore the recipe package with the postinst did not end up in my rootfs.

When changing the IMAGE_INSTALL I get my commands to be executed on the system on first boot.
I realize now that my current method of having every recipe create an extra package with PROVIDES is not really necessary.

Your hint about the run-postinsts directory was what lead me to understand the mechanism further.
And on the way I recognized a bad or at least confusing practice on my behalf.

I consider this question/problem solved, thank you very much.

Stefan

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

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

* Re: [yocto] Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27 12:26           ` stefan.wenninger
@ 2020-03-27 13:09             ` Quentin Schulz
  2020-03-27 13:41               ` stefan.wenninger
  0 siblings, 1 reply; 10+ messages in thread
From: Quentin Schulz @ 2020-03-27 13:09 UTC (permalink / raw)
  To: stefan.wenninger; +Cc: yocto

Hi Stefan,

On Fri, Mar 27, 2020 at 05:26:23AM -0700, stefan.wenninger@evopro-ag.de wrote:
> I think the relevant part for me in that script is the func exec_postinst_scriplets(). It looks to me as if this function iterates through all scripts in the /etc/deb-postinsts directory in my case and executes them with "sh".
> My problem seems to have stemmed from confusion on my part about what package the postinst attaches to.
> The postinst belongs to the package with the same name as my recipe because of the _${PN}. However I specified that my recipe produces another package with the PROVIDES ="" variable.

I think you meant PACKAGES and not PROVIDES here. If that is the case,
then yes, congrats, you found the root cause :)

Otherwise, I think there might be something worth debugging and maybe
reporting.

Quentin

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

* Re: Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27 13:09             ` [yocto] " Quentin Schulz
@ 2020-03-27 13:41               ` stefan.wenninger
  2020-03-27 13:55                 ` [yocto] " Quentin Schulz
  0 siblings, 1 reply; 10+ messages in thread
From: stefan.wenninger @ 2020-03-27 13:41 UTC (permalink / raw)
  To: yocto

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

Hi Quentin,
I have now read up on the exact meaning of PROVIDES and PACKAGES and I do understand your response.
It does sound like I am talking about PACKAGES since I did suspect PROVIDES to work like that.
Well at least if PROVIDES would work like that, it would explain why my postinstall did not work previously.

But I did use PROVIDES, which I now know is basically just a alias.

Here is the situation I had before and how I solved it:

Previous attempt:
*my_recipe.bb:*
...
PROVIDES += "my_recipes_package"
RPROVIDES_${PN} += "my_recipes_package"

pkg_postinst_ontarget_${PN} () {
#!/bin/sh
file=$D/home/root/test/test.txt
printf "hello world\n" > $file
}

*my_image.bb:*
IMAGE_INSTALL += " my_recipes_package "

current solution:
*my_recipe.bb:*
...
pkg_postinst_ontarget_${PN} () {
#!/bin/sh
file=$D/home/root/test/test.txt
printf "hello world\n" > $file
}

*my_image.bb:*
IMAGE_INSTALL += " my_recipe "

I can only guess that the postinst was only attached to the package called "my_recipe" and not to its alias "my_recipes_package"?

Stefan

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

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

* Re: [yocto] Mechanism behind pkg_postinst_ontarget_${PN} #yocto
  2020-03-27 13:41               ` stefan.wenninger
@ 2020-03-27 13:55                 ` Quentin Schulz
  0 siblings, 0 replies; 10+ messages in thread
From: Quentin Schulz @ 2020-03-27 13:55 UTC (permalink / raw)
  To: stefan.wenninger; +Cc: yocto

Hi Stefan,

On Fri, Mar 27, 2020 at 06:41:57AM -0700, stefan.wenninger@evopro-ag.de wrote:
> Hi Quentin,
> I have now read up on the exact meaning of PROVIDES and PACKAGES and I do understand your response.
> It does sound like I am talking about PACKAGES since I did suspect PROVIDES to work like that.
> Well at least if PROVIDES would work like that, it would explain why my postinstall did not work previously.
> 
> But I did use PROVIDES, which I now know is basically just a alias.
> 
> Here is the situation I had before and how I solved it:
> 
> Previous attempt:
> *my_recipe.bb:*
> ...
> PROVIDES += "my_recipes_package"

Your recipe can now be used in DEPENDS of other recipes with both "my-recipe"
and "my-recipe-package". N.B.: please do not use underscore in recipe
names, it can have weird consequences (been there, trust me). I assume
it's only for the sake of an example so it's fine.

> RPROVIDES_${PN} += "my_recipes_package"
> 

Here, you mean, ${PN} (packaged named my-recipe which is the main
package usually) can also be known as my-recipes-package, it's another
alias, for different thing but still nothing crazy.

> pkg_postinst_ontarget_${PN} () {
> #!/bin/sh
> file=$D/home/root/test/test.txt
> printf "hello world\n" > $file
> }
> 
> *my_image.bb:*
> IMAGE_INSTALL += " my_recipes_package "
> 

"Please install my-recipes-package which is an alias to my-recipe
package."

This actually seems okay to me. So if no typo and no underscore, I'm
clueless.

Can you try that exact same recipe but with:
pkg_postinst_ontarget_my-recipes-package instead of
pkg_postinst_ontarget_${PN} ()?

And another try, with the exact same recipe (so not the modification
asked above), with IMAGE_INSTALL += "my-recipe"?

In any case, this seems to me to be bug that should be reported.

Quentin

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

end of thread, other threads:[~2020-03-27 13:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-27  8:14 Mechanism behind pkg_postinst_ontarget_${PN} #yocto stefan.wenninger
2020-03-27  8:52 ` [yocto] " Alexander Kanavin
2020-03-27  9:06   ` stefan.wenninger
2020-03-27  9:09     ` [yocto] " Alexander Kanavin
2020-03-27  9:26       ` stefan.wenninger
2020-03-27  9:30         ` [yocto] " Alexander Kanavin
2020-03-27 12:26           ` stefan.wenninger
2020-03-27 13:09             ` [yocto] " Quentin Schulz
2020-03-27 13:41               ` stefan.wenninger
2020-03-27 13:55                 ` [yocto] " Quentin Schulz

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.