run-postinst: Ensure that the postinsts are ordered

Submitted by Mark Hatle on Oct. 4, 2013, 3:48 p.m.

Details

Message ID 1380901699-18760-1-git-send-email-mark.hatle@windriver.com
State Accepted
Commit b5bafccb89f45d7cdd515b4ba45e0152ca7922de
Headers show

Commit Message

Mark Hatle Oct. 4, 2013, 3:48 p.m.
The postinst files were being generated using purely the name of the package,
this unfortunately meant the run order would be based on the name of the
package and not the order in which it was installed on the filesystem.

If package A requires package Z to be fully installed, this causes a problem.

Note:

rpm - as the rpm based install proceeds the order is defined and captured.
      so the problem is resolved there.

ipk - this unfortunately does not appear to solve the problem for ipk, as
      the status file is not ordered in any appreciable way.  This does not
      cause any regressions however and sets the stage for a proper fix.

deb - this -may- fix the deb install.  Early testing indicates at least some
      ordering to the status file.  But it's unclear if it completely resolves
      the issue.

Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
---
 meta/classes/package_rpm.bbclass | 14 ++++++++++----
 meta/classes/rootfs_deb.bbclass  |  7 ++++++-
 meta/classes/rootfs_ipk.bbclass  |  7 ++++++-
 3 files changed, 22 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/classes/package_rpm.bbclass b/meta/classes/package_rpm.bbclass
index 98aa98b..36bad09 100644
--- a/meta/classes/package_rpm.bbclass
+++ b/meta/classes/package_rpm.bbclass
@@ -391,6 +391,10 @@  EOF
 	fi
 
 	# Construct install scriptlet wrapper
+	# Scripts need to be ordered when executed, this ensures numeric order
+	# If we ever run into needing more the 899 scripts, we'll have to
+	# change num to start with 1000.
+	#
 	cat << EOF > ${WORKDIR}/scriptlet_wrapper
 #!/bin/bash
 
@@ -406,11 +410,13 @@  export NATIVE_ROOT=${STAGING_DIR_NATIVE}
 if [ \$? -ne 0 ]; then
   if [ \$4 -eq 1 ]; then
     mkdir -p \$1/etc/rpm-postinsts
+    num=100
+    while [ -e \$1/etc/rpm-postinsts/\${num}-* ]; do num=\$((num + 1)); done
     name=\`head -1 \$1/\$3 | cut -d' ' -f 2\`
-    echo "#!\$2" > \$1/etc/rpm-postinsts/\${name}
-    echo "# Arg: \$4" >> \$1/etc/rpm-postinsts/\${name}
-    cat \$1/\$3 >> \$1/etc/rpm-postinsts/\${name}
-    chmod +x \$1/etc/rpm-postinsts/\${name}
+    echo "#!\$2" > \$1/etc/rpm-postinsts/\${num}-\${name}
+    echo "# Arg: \$4" >> \$1/etc/rpm-postinsts/\${num}-\${name}
+    cat \$1/\$3 >> \$1/etc/rpm-postinsts/\${num}-\${name}
+    chmod +x \$1/etc/rpm-postinsts/\${num}-\${name}
   else
     echo "Error: pre/post remove scriptlet failed"
   fi
diff --git a/meta/classes/rootfs_deb.bbclass b/meta/classes/rootfs_deb.bbclass
index 0161f7a..b1c52f9 100644
--- a/meta/classes/rootfs_deb.bbclass
+++ b/meta/classes/rootfs_deb.bbclass
@@ -107,9 +107,14 @@  delayed_postinsts () {
 }
 
 save_postinsts () {
+	# Scripts need to be ordered when executed, this ensures numeric order
+	# If we ever run into needing more the 899 scripts, we'll have to
+	# change num to start with 1000.
+	num=100
 	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
+		cp ${IMAGE_ROOTFS}/var/lib/dpkg/info/$p.postinst ${IMAGE_ROOTFS}${sysconfdir}/deb-postinsts/$num-$p
+		num=`echo \$((num+1))`
 	done
 }
 
diff --git a/meta/classes/rootfs_ipk.bbclass b/meta/classes/rootfs_ipk.bbclass
index a37ab14..b0805dc 100644
--- a/meta/classes/rootfs_ipk.bbclass
+++ b/meta/classes/rootfs_ipk.bbclass
@@ -106,9 +106,14 @@  delayed_postinsts () {
 }
 
 save_postinsts () {
+	# Scripts need to be ordered when executed, this ensures numeric order
+	# If we ever run into needing more the 899 scripts, we'll have to
+	# change num to start with 1000.
+	num=100
 	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
+		cp ${IMAGE_ROOTFS}${OPKGLIBDIR}/opkg/info/$p.postinst ${IMAGE_ROOTFS}${sysconfdir}/ipk-postinsts/$num-$p
+		num=`echo \$((num+1))`
 	done
 }
 

Comments

Bruce Ashfield Oct. 4, 2013, 5:21 p.m.
On Fri, Oct 4, 2013 at 11:48 AM, Mark Hatle <mark.hatle@windriver.com> wrote:
> The postinst files were being generated using purely the name of the package,
> this unfortunately meant the run order would be based on the name of the
> package and not the order in which it was installed on the filesystem.
>
> If package A requires package Z to be fully installed, this causes a problem.
>
> Note:
>
> rpm - as the rpm based install proceeds the order is defined and captured.
>       so the problem is resolved there.
>
> ipk - this unfortunately does not appear to solve the problem for ipk, as
>       the status file is not ordered in any appreciable way.  This does not
>       cause any regressions however and sets the stage for a proper fix.

I can confirm that it does solve rpm, and ipk it makes things
"better". No matter
what, I prefer the bit of ordering over the alphabetical ordering.

Tested-by: Bruce Ashfield <bruce.ashfield@windriver.com>

>
> deb - this -may- fix the deb install.  Early testing indicates at least some
>       ordering to the status file.  But it's unclear if it completely resolves
>       the issue.
>
> Signed-off-by: Mark Hatle <mark.hatle@windriver.com>
> ---
>  meta/classes/package_rpm.bbclass | 14 ++++++++++----
>  meta/classes/rootfs_deb.bbclass  |  7 ++++++-
>  meta/classes/rootfs_ipk.bbclass  |  7 ++++++-
>  3 files changed, 22 insertions(+), 6 deletions(-)
>
> diff --git a/meta/classes/package_rpm.bbclass b/meta/classes/package_rpm.bbclass
> index 98aa98b..36bad09 100644
> --- a/meta/classes/package_rpm.bbclass
> +++ b/meta/classes/package_rpm.bbclass
> @@ -391,6 +391,10 @@ EOF
>         fi
>
>         # Construct install scriptlet wrapper
> +       # Scripts need to be ordered when executed, this ensures numeric order
> +       # If we ever run into needing more the 899 scripts, we'll have to
> +       # change num to start with 1000.
> +       #
>         cat << EOF > ${WORKDIR}/scriptlet_wrapper
>  #!/bin/bash
>
> @@ -406,11 +410,13 @@ export NATIVE_ROOT=${STAGING_DIR_NATIVE}
>  if [ \$? -ne 0 ]; then
>    if [ \$4 -eq 1 ]; then
>      mkdir -p \$1/etc/rpm-postinsts
> +    num=100
> +    while [ -e \$1/etc/rpm-postinsts/\${num}-* ]; do num=\$((num + 1)); done
>      name=\`head -1 \$1/\$3 | cut -d' ' -f 2\`
> -    echo "#!\$2" > \$1/etc/rpm-postinsts/\${name}
> -    echo "# Arg: \$4" >> \$1/etc/rpm-postinsts/\${name}
> -    cat \$1/\$3 >> \$1/etc/rpm-postinsts/\${name}
> -    chmod +x \$1/etc/rpm-postinsts/\${name}
> +    echo "#!\$2" > \$1/etc/rpm-postinsts/\${num}-\${name}
> +    echo "# Arg: \$4" >> \$1/etc/rpm-postinsts/\${num}-\${name}
> +    cat \$1/\$3 >> \$1/etc/rpm-postinsts/\${num}-\${name}
> +    chmod +x \$1/etc/rpm-postinsts/\${num}-\${name}
>    else
>      echo "Error: pre/post remove scriptlet failed"
>    fi
> diff --git a/meta/classes/rootfs_deb.bbclass b/meta/classes/rootfs_deb.bbclass
> index 0161f7a..b1c52f9 100644
> --- a/meta/classes/rootfs_deb.bbclass
> +++ b/meta/classes/rootfs_deb.bbclass
> @@ -107,9 +107,14 @@ delayed_postinsts () {
>  }
>
>  save_postinsts () {
> +       # Scripts need to be ordered when executed, this ensures numeric order
> +       # If we ever run into needing more the 899 scripts, we'll have to
> +       # change num to start with 1000.
> +       num=100
>         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
> +               cp ${IMAGE_ROOTFS}/var/lib/dpkg/info/$p.postinst ${IMAGE_ROOTFS}${sysconfdir}/deb-postinsts/$num-$p
> +               num=`echo \$((num+1))`
>         done
>  }
>
> diff --git a/meta/classes/rootfs_ipk.bbclass b/meta/classes/rootfs_ipk.bbclass
> index a37ab14..b0805dc 100644
> --- a/meta/classes/rootfs_ipk.bbclass
> +++ b/meta/classes/rootfs_ipk.bbclass
> @@ -106,9 +106,14 @@ delayed_postinsts () {
>  }
>
>  save_postinsts () {
> +       # Scripts need to be ordered when executed, this ensures numeric order
> +       # If we ever run into needing more the 899 scripts, we'll have to
> +       # change num to start with 1000.
> +       num=100
>         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
> +               cp ${IMAGE_ROOTFS}${OPKGLIBDIR}/opkg/info/$p.postinst ${IMAGE_ROOTFS}${sysconfdir}/ipk-postinsts/$num-$p
> +               num=`echo \$((num+1))`
>         done
>  }
>
> --
> 1.8.1.2.545.g2f19ada
>
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.openembedded.org/mailman/listinfo/openembedded-core