package_deb: skip pre/postrm scripts on upgrade, write only one shebang
authorAndreas Oberritter <obi@opendreambox.org>
Fri, 10 Oct 2014 23:36:42 +0000 (18:36 -0500)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 11 Oct 2014 07:11:03 +0000 (08:11 +0100)
Trying to upgrade busybox removing symlinks but update-alternatives
need these links (sed, cut, tail, etc) in order to work.

Adding test to avoid this scripts on upgrade fix the problem, same
solution are found in package_rpm class.

[YOCTO #6768]

(From OE-Core rev: 7b9161dd0c475cca6ea7eb507f7c3c51869eb493)

Signed-off-by: Andreas Oberritter <obi@opendreambox.org>
Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes/package_deb.bbclass

index 7bc29df..5b5f7e2 100644 (file)
@@ -239,13 +239,26 @@ python do_package_deb () {
             scriptvar = localdata.getVar('pkg_%s' % script, True)
             if not scriptvar:
                 continue
+            scriptvar = scriptvar.strip()
             try:
                 scriptfile = open(os.path.join(controldir, script), 'w')
             except OSError:
                 bb.utils.unlockfile(lf)
                 raise bb.build.FuncFailed("unable to open %s script file for writing." % script)
-            scriptfile.write("#!/bin/sh\n")
-            scriptfile.write(scriptvar)
+
+            if scriptvar.startswith("#!"):
+                pos = scriptvar.find("\n") + 1
+                scriptfile.write(scriptvar[:pos])
+            else:
+                pos = 0
+                scriptfile.write("#!/bin/sh\n")
+
+            # Prevent the prerm/postrm scripts from being run during an upgrade
+            if script in ('prerm', 'postrm'):
+                scriptfile.write('[ "$1" != "upgrade" ] || exit 0\n')
+
+            scriptfile.write(scriptvar[pos:])
+            scriptfile.write('\n')
             scriptfile.close()
             os.chmod(os.path.join(controldir, script), 0755)