4

I'm writing am openembedded/bitbake recipe for openembedded-classic. My recipe RDEPENDS on keyutils, and everything seems to work, except one thing: I want to append a single line to the /etc/request-key.conf file installed by the keyutils package. So I added the following to my recipe:

pkg_postinst_${PN} () {
  echo 'create ... more stuff ..' >> ${sysconfdir}/request-key.conf
}

However, the intended added line is missing in my resulting image. My recipe inherits update-rc.d if that makes any difference.

My main question is: How do i debug this? Currently I am constructing an entire rootfs image, and then poke-around in that to see, if the changes show up. Surely there is a better way?

UPDATE: Changed recipe to:

pkg_postinst_${PN} () {
  echo 'create ... more stuff ...' >> ${D}${sysconfdir}/request-key.conf
}

But still no luck.

S.C. Madsen
  • 5,100
  • 5
  • 32
  • 50
  • I was hoping for answers indicating how people debug this sort of problem. I simply cannot believe my "poking around" is the best method for this. Many thanks to suggestions for solving the problem, but none really answer my original question. – S.C. Madsen Aug 04 '15 at 17:54

4 Answers4

6

As far as I know, postinst runs at rootfs creation, and only at first boot if rootfs fails.

So there is a easy way to execute something only first boot. Just check for $D, like this:

pkg_postinst_stuff() {
#!/bin/sh -e
if [ x"$D" = "x" ]; then
    # do something at first boot here
else
    exit 1
fi
}
zwerch
  • 73
  • 1
  • 7
  • Could you explain the "else exit 1" – fabatera Nov 29 '17 at 19:02
  • 1
    Sorry @fabatera I don't really remember. I guess it had something to do with how OE handles these kinds of scripts. I think I may have had this example from some documentation. – zwerch Jan 16 '18 at 12:25
5

postinst scripts are ran at roots time, so ${sysconfdir} is /etc on your host. Use $D${sysconfdir} to write to the file inside the rootfs being generated.

Ross Burton
  • 3,516
  • 13
  • 12
  • That right. I had actually discovered that on my own last night. It doesn't seem to solve my problem however. – S.C. Madsen Jun 24 '15 at 11:28
  • 2
    I'm guessing you need $D instead of ${D}. ${D} will be expanded by bitbake when the recipe is parsed and expand to the value of the temporary destination directory at recipe build time. $D won't be expanded by bitbake but will be expanded by the shell and at rootfs time, D is in the environment. – Ross Burton Jun 25 '15 at 11:55
  • You are right, which causes problems run-time when using the resulting image. However, my problem is that the pkg_postinst seems non-functional at image creation time. – S.C. Madsen Jul 01 '15 at 09:20
  • Have you looked at what the complete generated `pkg_postinst` script looks like? Does it do what you expect, or does it error out before running your stuff? (Though, if you're completely defining the `pkg_postinst_{$PN}`, like your question indicates, this should likely not be a problem. Note however, that the `update-rc.d` class likes to add it's own part to the `pkg_postinst`, so unless you know what you're doing, you might want to use `pkg_postinst_${PN}_append`. – Anders Jul 03 '15 at 06:45
0

OE-Classic is pretty ancient so you really should update to oe-core.

That said, Do postinst's run at first boot? I'm not sure. Also look in the recipes work directory in the temp directory and read the log and run files to see if there are any clues there.

balister
  • 341
  • 2
  • 4
  • If I understand correctly, postinst's should both run during image creation, AND during first boot. Hence the method of checking if ${D} is empty to seperate actions during the two runs..... Or have I misunderstood? – S.C. Madsen Jun 25 '15 at 11:54
  • 1
    Yeah, that sounds correct. Read Ross' reply and check the logs. – balister Jun 25 '15 at 11:56
0

One more thing. If foo RDEPENDS on bar that just means "when foo is installed, bar is also installed". I'm not sure it makes assertions about what is installed during the install phase, when your postinst is running.

If using $D doesn't fix the problem try editing your postinst to copy the existing file you're trying to edit somewhere else, so you can verify that it exists in the first place. Its possible that you're appending to a file that doesn't exist yet, and the the package that installs the file replaces it.

Ross Burton
  • 3,516
  • 13
  • 12