Post-installation scripts run immediately after installing
a package on the target or during image creation when a
package is included in an image.
To add a post-installation script to a package, add a
pkg_postinst_
PACKAGENAME
()
function to
the recipe file (.bb
) and replace
PACKAGENAME
with the name of the package
you want to attach to the postinst
script.
To apply the post-installation script to the main package
for the recipe, which is usually what is required, specify
${
PN
}
in place of PACKAGENAME
.
A post-installation function has the following structure:
pkg_postinst_PACKAGENAME
() {
# Commands to carry out
}
The script defined in the post-installation function is called when the root filesystem is created. If the script succeeds, the package is marked as installed. If the script fails, the package is marked as unpacked and the script is executed when the image boots again.
Sometimes it is necessary for the execution of a post-installation script to be delayed until the first boot. For example, the script might need to be executed on the device itself. To delay script execution until boot time, use the following structure in the post-installation script:
pkg_postinst_PACKAGENAME
() {
if [ x"$D" = "x" ]; then
# Actions to carry out on the device go here
else
exit 1
fi
}
The previous example delays execution until the image boots
again because the environment variable D
points to the directory containing the image when
the root filesystem is created at build time but is unset
when executed on the first boot.
If you have recipes that use pkg_postinst
scripts and they require the use of non-standard native
tools that have dependencies during rootfs construction, you
need to use the
PACKAGE_WRITE_DEPS
variable in your recipe to list these tools.
If you do not use this variable, the tools might be missing and
execution of the post-installation script is deferred until
first boot.
Deferring the script to first boot is undesirable and for
read-only rootfs impossible.
pkg_preinst
,
pkg_prerm
, and
pkg_postrm
, respectively.
These scrips work in exactly the same way as does
pkg_postinst
with the exception that they
run at different times.
Also, because of when they run, they are not applicable to
being run at image creation time like
pkg_postinst
.