bitbakeopkg

Executing opkg post install script after image installation


We are creating a filesystem image in BitBake and one of the packages requires that its post install script be executed on the device, after the image itself has been installed on the device, and not while the rootfs image is being generated by the build server.

Looking at the package with "opkg status ", it says that the package has been successfully installed -- "install ok installed". However, none of the side effects have been performed, and simply running the .postinst file from /var/lib/opkg/info/.postinst works and reports no errors.

How do I get this to work? It seems that the package is being "installed" in the rootfs image with the incorrect status.


Solution

  • Please see Dev manual section Post-Installation Scripts: With recent Yocto (>=2.7) you can use pkg_postinst_ontarget_${PN}() when you know your script should always run on target during first boot, and never during rootfs generation.

    On older Yocto version you can just do what pkg_postinst_ontarget_${PN} does manually in your function pkg_postinst_${PN}():

    if [ -n "$D" ]; then
        echo "Delaying until first boot"
        exit 1
    fi
    
    # actual post install script here
    

    $D will be defined during rootfs generation so the postinstall script will fail. This means the script will be run again during first boot on target.

    The best option is still fixing the postinstall script so that it works during rootfs generation -- sometimes this isn't possible of course.