Patchwork base-passwd: Fix the broken preinst/postinstall

login
register
mail settings
Submitter Richard Purdie
Date Nov. 14, 2011, 12:49 p.m.
Message ID <1321274982.26881.55.camel@ted>
Download mbox | patch
Permalink /patch/14933/
State Accepted
Commit fc708d88f97e40a5bf929e4e02ed805fb3684ffe
Headers show

Comments

Richard Purdie - Nov. 14, 2011, 12:49 p.m.
The preinst accesses file which may not yet have been unpacked.
The postinst is too late for the creation of these files
for at least the opkg backend.

This patch therefore encodes the file contents into the preinst,
resolving the various issues once and for all.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
Phil Blundell - Nov. 14, 2011, 12:52 p.m.
On Mon, 2011-11-14 at 12:49 +0000, Richard Purdie wrote:
> The preinst accesses file which may not yet have been unpacked.
> The postinst is too late for the creation of these files
> for at least the opkg backend.
> 
> This patch therefore encodes the file contents into the preinst,
> resolving the various issues once and for all.
> 
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>

If you're going to do that (which does look reasonable) then you might
as well stop the package from shipping passwd.master and group.master at
all.  I don't think anything else uses those files so they're just
wasting space at the moment.

p.
Otavio Salvador - Nov. 14, 2011, 1:03 p.m.
+1 :D

On Mon, Nov 14, 2011 at 10:52, Phil Blundell <philb@gnu.org> wrote:
> On Mon, 2011-11-14 at 12:49 +0000, Richard Purdie wrote:
>> The preinst accesses file which may not yet have been unpacked.
>> The postinst is too late for the creation of these files
>> for at least the opkg backend.
>>
>> This patch therefore encodes the file contents into the preinst,
>> resolving the various issues once and for all.
>>
>> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
>
> If you're going to do that (which does look reasonable) then you might
> as well stop the package from shipping passwd.master and group.master at
> all.  I don't think anything else uses those files so they're just
> wasting space at the moment.
>
> p.
>
>
>
> _______________________________________________
> Openembedded-core mailing list
> Openembedded-core@lists.openembedded.org
> http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-core
>
Koen Kooi - Nov. 14, 2011, 1:37 p.m.
Op 14 nov. 2011, om 13:52 heeft Phil Blundell het volgende geschreven:

> On Mon, 2011-11-14 at 12:49 +0000, Richard Purdie wrote:
>> The preinst accesses file which may not yet have been unpacked.
>> The postinst is too late for the creation of these files
>> for at least the opkg backend.
>> 
>> This patch therefore encodes the file contents into the preinst,
>> resolving the various issues once and for all.
>> 
>> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> 
> If you're going to do that (which does look reasonable) then you might
> as well stop the package from shipping passwd.master and group.master at
> all.  I don't think anything else uses those files so they're just
> wasting space at the moment.

IIRC 'update-passwd' will use those. That's not a criticism on Phils suggestion, I like it very much.

regards,

Koen
Richard Purdie - Nov. 14, 2011, 1:58 p.m.
On Mon, 2011-11-14 at 14:37 +0100, Koen Kooi wrote:
> Op 14 nov. 2011, om 13:52 heeft Phil Blundell het volgende geschreven:
> 
> > On Mon, 2011-11-14 at 12:49 +0000, Richard Purdie wrote:
> >> The preinst accesses file which may not yet have been unpacked.
> >> The postinst is too late for the creation of these files
> >> for at least the opkg backend.
> >> 
> >> This patch therefore encodes the file contents into the preinst,
> >> resolving the various issues once and for all.
> >> 
> >> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
> > 
> > If you're going to do that (which does look reasonable) then you might
> > as well stop the package from shipping passwd.master and group.master at
> > all.  I don't think anything else uses those files so they're just
> > wasting space at the moment.
> 
> IIRC 'update-passwd' will use those. That's not a criticism on Phils
> suggestion, I like it very much.

I've posted a second patch which moves these pieces into a separate
package and actually uses update-passwd.

Cheers,

Richard

Patch

diff --git a/meta/recipes-core/base-passwd/base-passwd_3.5.22.bb b/meta/recipes-core/base-passwd/base-passwd_3.5.22.bb
index aa90a6d..05be23f 100644
--- a/meta/recipes-core/base-passwd/base-passwd_3.5.22.bb
+++ b/meta/recipes-core/base-passwd/base-passwd_3.5.22.bb
@@ -1,7 +1,7 @@ 
 SUMMARY = "Base system master password/group files."
 DESCRIPTION = "The master copies of the user database files (/etc/passwd and /etc/group).  The update-passwd tool is also provided to keep the system databases synchronized with these master files."
 SECTION = "base"
-PR = "r4"
+PR = "r5"
 LICENSE = "GPLv2+"
 LIC_FILES_CHKSUM = "file://COPYING;md5=eb723b61539feef013de476e68b5c50a"
 
@@ -37,36 +37,6 @@  do_install () {
 	install -p -m 644 debian/copyright ${D}${docdir}/${BPN}/
 }
 
-pkg_preinst_${PN} () {
-	set -e
-
-	# Used for rootfs generation. On in-target install this will be run
-        # before the unpack so the files won't be available
-
-	if [ ! -e $D${sysconfdir}/passwd ] && [ -e $D${datadir}/base-passwd/passwd.master ]; then
-		cp $D${datadir}/base-passwd/passwd.master $D${sysconfdir}/passwd
-	fi
-
-	if [ ! -e $D${sysconfdir}/group ] && [ -e $D${datadir}/base-passwd/group.master ]; then
-		cp $D${datadir}/base-passwd/group.master $D${sysconfdir}/group
-	fi
-
-	exit 0
-}
-
-pkg_postinst_${PN} () {
-	set -e
-
-	if [ ! -e $D${sysconfdir}/passwd ] ; then
-		cp $D${datadir}/base-passwd/passwd.master $D${sysconfdir}/passwd
-	fi
-
-	if [ ! -e $D${sysconfdir}/group ] ; then
-		cp $D${datadir}/base-passwd/group.master $D${sysconfdir}/group
-	fi
-	exit 0
-}
-
 base_passwd_sstate_postinst() {
 	if [ "${BB_CURRENTTASK}" = "populate_sysroot" -o "${BB_CURRENTTASK}" = "populate_sysroot_setscene" ]
 	then
@@ -80,3 +50,31 @@  base_passwd_sstate_postinst() {
 		install -p -m 644 ${STAGING_DIR_TARGET}${datadir}/base-passwd/group.master ${STAGING_DIR_TARGET}${sysconfdir}/group
 	fi
 }
+
+python populate_packages_prepend() {
+	# Add in the preinst function for ${PN}
+	# We have to do this here as prior to this, passwd/group.master
+	# would be unavailable. We need to create these files at preinst
+	# time before the files from the package may be available, hence
+	# storing the data from the files in the preinst directly.
+
+	f = open(bb.data.expand("${STAGING_DATADIR}/base-passwd/passwd.master", d), 'r')
+	passwd = "".join(f.readlines())
+	f.close()
+	f = open(bb.data.expand("${STAGING_DATADIR}/base-passwd/group.master", d), 'r')
+	group = "".join(f.readlines())
+	f.close()
+
+	preinst = """#!/bin/sh
+if [ ! -e $D${sysconfdir}/passwd ]; then
+	cat << EOF > $D${sysconfdir}/passwd
+""" + passwd + """EOF
+fi
+if [ ! -e $D${sysconfdir}/group ]; then
+	cat << EOF > $D${sysconfdir}/group
+""" + group + """EOF
+fi
+"""
+	d.setVar('pkg_preinst_${PN}', preinst)
+}
+