rootfs_*.bbclass: add some helper functions
authorLaurentiu Palcu <laurentiu.palcu@intel.com>
Tue, 21 May 2013 11:17:19 +0000 (14:17 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 11 Jun 2013 14:38:04 +0000 (15:38 +0100)
This patch adds the following helper functions:
 * delayed_postinsts - outputs the list of delayed postinstalls;
 * save_postinsts - this will save the delayed postinstalls for ipk/deb
   in /etc/(ipk|deb)_postinsts;
 * rootfs_remove_packages - removes packages from an image;

Additionaly, this patch will remove a piece of code in
rootfs_ipk_do_rootfs which will be moved to image.bbclass and used for
all backends;

[YOCTO #4484]

(From OE-Core rev: 928df79cd3964f775c4c6e4283ef84b8882f9328)

Signed-off-by: Laurentiu Palcu <laurentiu.palcu@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/rootfs_deb.bbclass
meta/classes/rootfs_ipk.bbclass
meta/classes/rootfs_rpm.bbclass

index e642cf3..edd1037 100644 (file)
@@ -85,7 +85,7 @@ fakeroot rootfs_deb_do_rootfs () {
        ${ROOTFS_POSTPROCESS_COMMAND}
 
        if ${@base_contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false" ,d)}; then
-               if grep Status:.install.ok.unpacked ${IMAGE_ROOTFS}/var/lib/dpkg/status; then
+               if [ -n "$(delayed_postinsts)" ]; then
                        bberror "Some packages could not be configured offline and rootfs is read-only."
                        exit 1
                fi
@@ -94,9 +94,22 @@ fakeroot rootfs_deb_do_rootfs () {
        log_check rootfs
 }
 
+rootfs_deb_do_rootfs[vardeps] += "delayed_postinsts"
+
+delayed_postinsts () {
+       cat ${IMAGE_ROOTFS}/var/lib/dpkg/status|grep -e "^Package:" -e "^Status:"|sed -ne 'N;s/Package: \(.*\)\nStatus:.*unpacked/\1/p'
+}
+
+save_postinsts () {
+       for p in $(delayed_postinsts); do
+               install -d ${IMAGE_ROOTFS}${sysconfdir}/deb-postinsts
+               cp ${IMAGE_ROOTFS}/var/lib/dpkg/info/$p.postinst ${IMAGE_ROOTFS}${sysconfdir}/deb-postinsts/$p
+       done
+}
+
 remove_packaging_data_files() {
        rm -rf ${IMAGE_ROOTFS}${opkglibdir}
-       rm -rf ${IMAGE_ROOTFS}/usr/dpkg/
+       rm -rf ${IMAGE_ROOTFS}/var/lib/dpkg/
 }
 
 rootfs_install_packages() {
@@ -105,3 +118,9 @@ rootfs_install_packages() {
        # Mark all packages installed
        sed -i -e "s/Status: install ok unpacked/Status: install ok installed/;" $INSTALL_ROOTFS_DEB/var/lib/dpkg/status
 }
+
+rootfs_remove_packages() {
+       # for some reason, --root doesn't really work here... We use --admindir&--instdir instead.
+       ${STAGING_BINDIR_NATIVE}/dpkg --admindir=${IMAGE_ROOTFS}/var/lib/dpkg --instdir=${IMAGE_ROOTFS} -r --force-depends $@
+}
+
index 3e1f959..1403422 100644 (file)
@@ -91,36 +91,29 @@ fakeroot rootfs_ipk_do_rootfs () {
        ${ROOTFS_POSTPROCESS_COMMAND}
 
        if ${@base_contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false" ,d)}; then
-               if grep Status:.install.ok.unpacked ${STATUS}; then
+               if [ -n "$(delayed_postinsts)" ]; then
                        bberror "Some packages could not be configured offline and rootfs is read-only."
                        exit 1
                fi
        fi
 
        rm -f ${IMAGE_ROOTFS}${OPKGLIBDIR}/opkg/lists/*
-       if ${@base_contains("IMAGE_FEATURES", "package-management", "false", "true", d)}; then
-               if ! grep Status:.install.ok.unpacked ${STATUS}; then
-                       # All packages were successfully configured.
-                       # update-rc.d, base-passwd, run-postinsts are no further use, remove them now
-                       remove_run_postinsts=false
-                       if [ -e ${IMAGE_ROOTFS}${sysconfdir}/init.d/run-postinsts ]; then
-                               remove_run_postinsts=true
-                       fi
-                       opkg-cl ${OPKG_ARGS} --force-depends remove update-rc.d base-passwd ${ROOTFS_BOOTSTRAP_INSTALL} || true
-
-                       # Need to remove rc.d files for run-postinsts by hand since opkg won't
-                       # call postrm scripts in offline root mode.
-                       if $remove_run_postinsts; then
-                               update-rc.d -f -r ${IMAGE_ROOTFS} run-postinsts remove
-                       fi
-
-                       # Also delete the status files
-                       remove_packaging_data_files
-               fi
-       fi
        log_check rootfs
 }
 
+rootfs_ipk_do_rootfs[vardeps] += "delayed_postinsts"
+
+delayed_postinsts () {
+       cat ${STATUS}|grep -e "^Package:" -e "^Status:"|sed -ne 'N;s/Package: \(.*\)\nStatus:.*unpacked/\1/p'
+}
+
+save_postinsts () {
+       for p in $(delayed_postinsts); do
+               install -d ${IMAGE_ROOTFS}${sysconfdir}/ipk-postinsts
+               cp ${IMAGE_ROOTFS}${OPKGLIBDIR}/opkg/info/$p.postinst ${IMAGE_ROOTFS}${sysconfdir}/ipk-postinsts/$p
+       done
+}
+
 rootfs_ipk_write_manifest() {
        manifest=${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.manifest
        cp ${IMAGE_ROOTFS}${OPKGLIBDIR}/opkg/status $manifest
@@ -145,6 +138,10 @@ rootfs_install_packages() {
        opkg-cl ${OPKG_ARGS} install `cat $1`
 }
 
+rootfs_remove_packages() {
+       opkg-cl ${OPKG_ARGS} --force-depends remove $@
+}
+
 ipk_insert_feed_uris () {
 
        echo "Building from feeds activated!"
index d373dab..4194c56 100644 (file)
@@ -114,8 +114,8 @@ fakeroot rootfs_rpm_do_rootfs () {
        ${ROOTFS_POSTPROCESS_COMMAND}
 
        if ${@base_contains("IMAGE_FEATURES", "read-only-rootfs", "true", "false" ,d)}; then
-               if [ -d ${IMAGE_ROOTFS}/etc/rpm-postinsts ] ; then
-                       if [ "`ls -A ${IMAGE_ROOTFS}/etc/rpm-postinsts`" != "" ] ; then
+               if [ -d ${IMAGE_ROOTFS}${sysconfdir}/rpm-postinsts ] ; then
+                       if [ "`ls -A ${IMAGE_ROOTFS}${sysconfdir}/rpm-postinsts`" != "" ] ; then
                                bberror "Some packages could not be configured offline and rootfs is read-only."
                                exit 1
                        fi
@@ -135,6 +135,20 @@ fakeroot rootfs_rpm_do_rootfs () {
        log_check rootfs
 }
 
+rootfs_rpm_do_rootfs[vardeps] += "delayed_postinsts"
+
+delayed_postinsts() {
+       if [ -d ${IMAGE_ROOTFS}${sysconfdir}/rpm-postinsts ]; then
+               ls ${IMAGE_ROOTFS}${sysconfdir}/rpm-postinsts
+       fi
+}
+
+save_postinsts() {
+       # this is just a stub. For RPM, the failed postinstalls are already saved in
+       # /etc/rpm-postinsts
+       true
+}
+
 remove_packaging_data_files() {
        # Save the rpmlib for increment rpm image generation
        t="${T}/saved_rpmlib/var/lib"
@@ -165,6 +179,15 @@ rootfs_install_packages() {
        package_install_internal_rpm
 }
 
+rootfs_remove_packages() {
+       rpm -e --nodeps --root=${IMAGE_ROOTFS} --dbpath=/var/lib/rpm\
+               --define='_cross_scriptlet_wrapper ${WORKDIR}/scriptlet_wrapper'\
+               --define='_tmppath /install/tmp' $@
+
+       # remove temp directory
+       rm -rf ${IMAGE_ROOTFS}/install
+}
+
 python () {
     if d.getVar('BUILD_IMAGES_FROM_FEEDS', True):
         flags = d.getVarFlag('do_rootfs', 'recrdeptask')