출처 :https://stackoverflow.com/questions/28397650/bitbake-recipe-to-have-pre-and-post-install-action

 

pkg_postinst_PACKAGENAME() {
 #!/bin/sh -e
 # Commands to carry out
 }
Reference: Section 5.3.16 http://www.yoctoproject.org/docs/1.7.1/mega-manual/mega-manual.html

According to the documentation the examples only runs during image creation time. There is also another function that will only run on the first boot (and never after it). It uses the meta/recipes-devtools/run-postinsts recipe to accomplish this.

 

 

 

I found a solution that involves specifying a post install script that runs when do_rootfs is called. All I added to my recipe which installs my public key on the system is below:

pkg_postinst_${PN}() {
#!/bin/sh

if [ -n "$D" ]; then
    OPT="--homedir $D/home/root/.gnupg"
else
    OPT=""
fi

gpg $OPT --import ${D}${datadir}/mykey.gpg
}

 

 

Quote from Yocto ref-manual 1.1:
When specifying paths as part of the CONFFILES variable, it is good practice to use appropriate path variables.

For example, ${sysconfdir} rather than /etc or ${bindir} rather than /usr/bin.

You can find a list of these variables at the top of the meta/conf/bitbake.conf file in the Source Directory.

 

5.15.2. Post-Installation Scripts

It is very important that you make sure all post-Installation (pkg_postinst) scripts for packages that are installed into the image can be run at the time when the root filesystem is created during the build on the host system. These scripts cannot attempt to run during first-boot on the target device. With the "read-only-rootfs" feature enabled, the build system checks during root filesystem creation to make sure all post-installation scripts succeed. If any of these scripts still need to be run after the root filesystem is created, the build immediately fails. These build-time checks ensure that the build fails rather than the target device fails later during its initial boot operation.

Most of the common post-installation scripts generated by the build system for the out-of-the-box Yocto Project are engineered so that they can run during root filesystem creation (e.g. post-installation scripts for caching fonts). However, if you create and add custom scripts, you need to be sure they can be run during this file system creation.

Here are some common problems that prevent post-installation scripts from running during root filesystem creation:

  • Not using $D in front of absolute paths: The build system defines $D when the root filesystem is created. Furthermore, $D is blank when the script is run on the target device. This implies two purposes for $D: ensuring paths are valid in both the host and target environments, and checking to determine which environment is being used as a method for taking appropriate actions.

  • Attempting to run processes that are specific to or dependent on the target architecture: You can work around these attempts by using native tools to accomplish the same tasks, or by alternatively running the processes under QEMU, which has the qemu_run_binary function. For more information, see the qemu class.

Posted by Real_G