Skip to contentSkip to conversation

Change the way RPM handles pre/post scripts

PATCH Applied Mark Hatle 2 participants 7 messages Nov 10, 2011 – Nov 12, 2011

lore
Share & tools
lore

Mark Hatle

author
#0 lore raw

cover Change the way RPM handles pre/post scripts

We change the way rootfs_rpm handles pre / post scripts in order to enable preinst scripts and better handling of post scripts.

The following changes since commit 379c77d1516fe8fdbd1cd7063f709b5266872b03:

populate_*.bbclass: Correct INSTALL variable name after recent multilib changes (2011-11-10 18:05:06 +0000)

are available in the git repository at:
git://git.pokylinux.org/poky-contrib mhatle/rpm
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=mhatle/rpm

Mark Hatle (5):
rootfs_rpm.bbclass: Enable pre and post install scripts rootfs_rpm.bbclass: Turn off script debugging
wpa-supplicant: Avoid blocking the post install script at cross
rootfs time.
shadow: Generate the shadow files at rootfs construction
sudo: Avoid post install scripts

 meta/classes/package_rpm.bbclass                   |   33 ++++-
 meta/classes/rootfs_rpm.bbclass                    |   27 +---
 .../wpa-supplicant/wpa-supplicant-0.7.inc          |    4 +-
 .../wpa-supplicant/wpa-supplicant_0.7.3.bb         |    2 +-
 .../rpm/rpm/rpm-scriptletexechelper.patch          |  159 ++++++++++++++++++++
 meta/recipes-devtools/rpm/rpm_5.4.0.bb             |    3 +-
 meta/recipes-extended/shadow/shadow_4.1.4.3.bb     |   12 +-
 meta/recipes-extended/sudo/sudo.inc                |    8 -
 meta/recipes-extended/sudo/sudo_1.8.3.bb           |    5 +-
 9 files changed, 214 insertions(+), 39 deletions(-)
 create mode 100644 meta/recipes-devtools/rpm/rpm/rpm-scriptletexechelper.patch
Signature · 1 line
1.7.3.4
author
#1 lore raw

PATCH 1/5 rootfs_rpm.bbclass: Enable pre and post install scripts

[YOCTO #1755]

We change the want the RPM rootfs install works to install pre and post install scripts. The new method uses a script helper that is invoked by RPM outside of the normal chroot.

The wrapper is dynamically generated prior to the install starting. It will check the return code of the script. If the script fails, it will store a copy to be executed on the first system boot. This is similar to the previous mechanism.

In addition, a line of debug was added to the scripts as written by package_rpm to list which package and which script for later debugging, if necessary.

---
 meta/classes/package_rpm.bbclass                   |   33 ++++-
 meta/classes/rootfs_rpm.bbclass                    |   25 +---
 .../rpm/rpm/rpm-scriptletexechelper.patch          |  159 ++++++++++++++++++++
 meta/recipes-devtools/rpm/rpm_5.4.0.bb             |    3 +-
 4 files changed, 199 insertions(+), 21 deletions(-)
 create mode 100644 meta/recipes-devtools/rpm/rpm/rpm-scriptletexechelper.patch
meta/classes/package_rpm.bbclass +32 -1
index 2c5545c..2ace053 100644
@@ -382,13 +382,39 @@ package_install_internal_rpm () {
 	cat ${target_rootfs}/install/install_solution.manifest > ${target_rootfs}/install/total_solution.manifest
 	cat ${target_rootfs}/install/install_multilib_solution.manifest >> ${target_rootfs}/install/total_solution.manifest
 
+	# Construct install scriptlet wrapper
+	cat << EOF > ${WORKDIR}/scriptlet_wrapper
+#!/bin/bash
+
+export PATH="${PATH}"
+export D="${target_rootfs}"
+export OFFLINE_ROOT="\$D"
+export IPKG_OFFLINE_ROOT="\$D"
+export OPKG_OFFLINE_ROOT="\$D"
+
+\$2 \$1/\$3 \$4
+if [ \$? -ne 0 ]; then
+  mkdir -p \$1/etc/rpm-postinsts
+  num=100
+  while [ -e \$1/etc/rpm-postinsts/\${num} ]; do num=\$((num + 1)); done
+  echo "#!\$2" > \$1/etc/rpm-postinsts/\${num}
+  echo "# Arg: \$4" >> \$1/etc/rpm-postinsts/\${num}
+  cat \$1/\$3 >> \$1/etc/rpm-postinsts/\${num}
+  chmod +x \$1/etc/rpm-postinsts/\${num}
+fi
+EOF
+
+	chmod 0755 ${WORKDIR}/scriptlet_wrapper
+
 	# Attempt install
 	${RPM} --root ${target_rootfs} \
 		--predefine "_rpmds_sysinfo_path ${target_rootfs}/etc/rpm/sysinfo" \
 		--predefine "_rpmrc_platform_path ${target_rootfs}/etc/rpm/platform" \
+		-D "_var ${localstatedir}" \
 		-D "_dbpath ${rpmlibdir}" \
-		--noscripts --notriggers --noparentdirs --nolinktos --replacepkgs \
+		--noparentdirs --nolinktos --replacepkgs \
 		-D "__dbi_txn create nofsync private" \
+		-D "_cross_scriptlet_wrapper ${WORKDIR}/scriptlet_wrapper" \
 		-Uhv ${target_rootfs}/install/total_solution.manifest
 }
 
@@ -685,6 +711,7 @@ python write_specfile () {
 			elif script == 'postrm':
 				spec_scriptlets_bottom.append('%%postun -n %s' % splitname)
 				scriptvar = wrap_uninstall(scriptvar)
+			spec_scriptlets_bottom.append('# %s - %s' % (splitname, script))
 			spec_scriptlets_bottom.append(scriptvar)
 			spec_scriptlets_bottom.append('')
 
@@ -762,19 +789,23 @@ python write_specfile () {
 
 	if srcpreinst:
 		spec_scriptlets_top.append('%pre')
+		spec_scriptlets_top.append('# %s - preinst' % srcname)
 		spec_scriptlets_top.append(srcpreinst)
 		spec_scriptlets_top.append('')
 	if srcpostinst:
 		spec_scriptlets_top.append('%post')
+		spec_scriptlets_top.append('# %s - postinst' % srcname)
 		spec_scriptlets_top.append(srcpostinst)
 		spec_scriptlets_top.append('')
 	if srcprerm:
 		spec_scriptlets_top.append('%preun')
+		spec_scriptlets_top.append('# %s - prerm' % srcname)
 		scriptvar = wrap_uninstall(srcprerm)
 		spec_scriptlets_top.append(scriptvar)
 		spec_scriptlets_top.append('')
 	if srcpostrm:
 		spec_scriptlets_top.append('%postun')
+		spec_scriptlets_top.append('# %s - postrm' % srcname)
 		scriptvar = wrap_uninstall(srcpostrm)
 		spec_scriptlets_top.append(scriptvar)
 		spec_scriptlets_top.append('')
meta/classes/rootfs_rpm.bbclass +6 -19
index 95e9455..b3875a4 100644
@@ -20,8 +20,6 @@ do_rootfs[depends] += "opkg-native:do_populate_sysroot"
 
 do_rootfs[recrdeptask] += "do_package_write_rpm"
 
-AWKPOSTINSTSCRIPT = "${COREBASE}/scripts/rootfs_rpm-extract-postinst.awk"
-
 RPM_PREPROCESS_COMMANDS = "package_update_index_rpm; package_generate_rpm_conf; "
 RPM_POSTPROCESS_COMMANDS = ""
 
@@ -108,19 +106,9 @@ EOF
 
 	${ROOTFS_POSTINSTALL_COMMAND}
 
-	mkdir -p ${IMAGE_ROOTFS}/etc/rpm-postinsts/
-	${RPM} --root ${IMAGE_ROOTFS} -D '_dbpath ${rpmlibdir}' -qa \
-		-D "__dbi_txn create nofsync private" \
-		--qf 'Name: %{NAME}\n%|POSTIN?{postinstall scriptlet%|POSTINPROG?{ (using %{POSTINPROG})}|:\n%{POSTIN}\n}:{%|POSTINPROG?{postinstall program: %{POSTINPROG}\n}|}|' \
-		> ${IMAGE_ROOTFS}/etc/rpm-postinsts/combined
-	awk -f ${AWKPOSTINSTSCRIPT} < ${IMAGE_ROOTFS}/etc/rpm-postinsts/combined
-	rm ${IMAGE_ROOTFS}/etc/rpm-postinsts/combined	
-
-	for i in ${IMAGE_ROOTFS}/etc/rpm-postinsts/*.sh; do
-		if [ -f $i ] && sh $i; then
-			# rm $i
-			mv $i $i.done
-		fi
+	# Report delayed package scriptlets
+	for i in ${IMAGE_ROOTFS}/etc/rpm-postinsts/*; do
+		echo "Delayed package scriptlet: `head -n 3 $i | tail -n 1`"
 	done
 
 	install -d ${IMAGE_ROOTFS}/${sysconfdir}/rcS.d
@@ -128,11 +116,10 @@ EOF
 	i=\$i
 	cat > ${IMAGE_ROOTFS}${sysconfdir}/rcS.d/S${POSTINSTALL_INITPOSITION}configure << EOF
 #!/bin/sh
-for i in /etc/rpm-postinsts/*.sh; do
+for i in /etc/rpm-postinsts/*; do
 	echo "Running postinst $i..."
-	if [ -f $i ] && sh $i; then
-		# rm $i
-		mv $i $i.done
+	if [ -f $i ] && $i; then
+		rm $i
 	else
 		echo "ERROR: postinst $i failed."
 	fi
meta/recipes-devtools/rpm/rpm/rpm-scriptletexechelper.patch new file +159 -0

159 lines not on this page · raw message

meta/recipes-devtools/rpm/rpm_5.4.0.bb +2 -1
index bbef0be..f8fe836 100644
@@ -45,7 +45,7 @@ LIC_FILES_CHKSUM = "file://COPYING.LIB;md5=2d5025d4aa3495befef8f17206a5b0a1"
 DEPENDS = "bzip2 zlib db openssl elfutils expat libpcre attr acl popt ${extrarpmdeps}"
 extrarpmdeps = "python perl"
 extrarpmdeps_virtclass-native = "file-native"
-PR = "r22"
+PR = "r23"
 
 # rpm2cpio is a shell script, which is part of the rpm src.rpm.  It is needed
 # in order to extract the distribution SRPM into a format we can extract...
@@ -63,6 +63,7 @@ SRC_URI = "http://www.rpm5.org/files/rpm/rpm-5.4/rpm-5.4.0-0.20101229.src.rpm;ex
 	   file://rpm-fileclass.patch \
 	   file://rpm-canonarch.patch \
 	   file://rpm-no-loopmsg.patch \
+	   file://rpm-scriptletexechelper.patch \
 	   file://pythondeps.sh \
 	  "
 
Signature · 1 line
1.7.3.4
author
#2 lore raw

PATCH 2/5 rootfs_rpm.bbclass: Turn off script debugging

In reply to Mark Hatle

Disable script debugging, as the log files become huge and take a long time to process during the log check step. This results in a performance improvement.

---
 meta/classes/rootfs_rpm.bbclass |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
meta/classes/rootfs_rpm.bbclass +1 -1
index b3875a4..6973008 100644
@@ -44,7 +44,7 @@ RPM="rpm ${RPMOPTS}"
 do_rootfs[lockfiles] += "${DEPLOY_DIR_RPM}/rpm.lock"
 
 fakeroot rootfs_rpm_do_rootfs () {
-	#set +x
+	set +x
 
 	${RPM_PREPROCESS_COMMANDS}
 
Signature · 1 line
1.7.3.4
author
#3 lore raw

PATCH 3/5 wpa-supplicant: Avoid blocking the post install script at cross rootfs time.

In reply to Mark Hatle

We only want to reload dbus, if we're install on the target -- not on the host.

---
 .../wpa-supplicant/wpa-supplicant-0.7.inc          |    4 ++--
 .../wpa-supplicant/wpa-supplicant_0.7.3.bb         |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
meta/recipes-connectivity/wpa-supplicant/wpa-supplicant-0.7.inc +2 -2
index cd62d8f..ccdc4c3 100644
@@ -66,9 +66,9 @@ do_install () {
 }
 
 pkg_postinst_wpa-supplicant () {
-	# can't do this offline
+	# If we're offline, we don't need to do this.
 	if [ "x$D" != "x" ]; then
-		exit 1
+		exit 0
 	fi
 
 	DBUSPID=`pidof dbus-daemon`
meta/recipes-connectivity/wpa-supplicant/wpa-supplicant_0.7.3.bb +1 -1
index 03bd937..98eba77 100644
@@ -1,6 +1,6 @@
 require wpa-supplicant-0.7.inc
 
-PR = "r4"
+PR = "r5"
 
 SRC_URI[md5sum] = "f516f191384a9a546e3f5145c08addda"
 SRC_URI[sha256sum] = "d0cd50caa85346ccc376dcda5ed3c258eef19a93b3cade39d25760118ad59443"
Signature · 1 line
1.7.3.4
author
#4 lore raw

PATCH 4/5 shadow: Generate the shadow files at rootfs construction

In reply to Mark Hatle

With the recent changes to the shadow-native package support "--root", we can now convert the passwd/group files to their shadow forms while doing the rootfs install, instead of waiting to run on the target.

---
 meta/recipes-extended/shadow/shadow_4.1.4.3.bb |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
meta/recipes-extended/shadow/shadow_4.1.4.3.bb +7 -5
index 5bc4a61..25330a4 100644
@@ -9,7 +9,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=08c553a87d4e51bbed50b20e0adcaede \
 
 DEPENDS = "${@base_contains('DISTRO_FEATURES', 'pam', 'libpam', '', d)}"
 RDEPENDS_${PN} = "${@base_contains('DISTRO_FEATURES', 'pam', '${PAM_PLUGINS}', '', d)}"
-PR = "r4"
+PR = "r5"
 
 SRC_URI = "http://pkg-shadow.alioth.debian.org/releases/${BPN}-${PV}.tar.bz2 \
            file://login_defs_pam.sed \
@@ -128,11 +128,13 @@ pkg_postinst_${PN} () {
 	update-alternatives --install ${base_sbindir}/vigr vigr vigr.${PN} 200
 
 	if [ "x$D" != "x" ]; then
-		exit 1
-	fi  
+	  rootarg="--root=$D"
+	else
+	  rootarg=""
+	fi
 
-	pwconv
-	grpconv
+	pwconv $rootarg
+	grpconv $rootarg
 }
 
 pkg_prerm_${PN} () {
Signature · 1 line
1.7.3.4
author
#5 lore raw

PATCH 5/5 sudo: Avoid post install scripts

In reply to Mark Hatle

The post install script was removed, and the install_append updated to ensure the permissions are set correctly.

---
 meta/recipes-extended/sudo/sudo.inc      |    8 --------
 meta/recipes-extended/sudo/sudo_1.8.3.bb |    5 ++++-
 2 files changed, 4 insertions(+), 9 deletions(-)
meta/recipes-extended/sudo/sudo.inc +0 -8
index 72a7c16..83dd209 100644
@@ -29,11 +29,3 @@ do_install_prepend (){
 	mkdir -p ${D}/${localstatedir}/lib
 }
 
-pkg_postinst_${PN} () {
-	if [ "x$D" != "x" ]; then
-		exit 1
-	fi
-
-	chmod 4111 /usr/bin/sudo
-	chmod 0440 /etc/sudoers
-}
meta/recipes-extended/sudo/sudo_1.8.3.bb +4 -1
index 0ac0851..99fe5b9 100644
@@ -1,6 +1,6 @@
 require sudo.inc
 
-PR = "r0"
+PR = "r1"
 
 SRC_URI = "http://ftp.sudo.ws/sudo/dist/sudo-${PV}.tar.gz \
            file://libtool.patch \
@@ -23,4 +23,7 @@ do_install_append () {
 			break
 		fi
 	done
+
+	chmod 4111 $D/usr/bin/sudo
+	chmod 0440 $D/etc/sudoers
 }
Signature · 1 line
1.7.3.4
Applied
#6 lore raw
In reply to Mark Hatle
Quoted 29 lines · Mark Hatle

We change the way rootfs_rpm handles pre / post scripts in order to enable preinst scripts and better handling of post scripts.

The following changes since commit 379c77d1516fe8fdbd1cd7063f709b5266872b03:

populate_*.bbclass: Correct INSTALL variable name after recent multilib changes (2011-11-10 18:05:06 +0000)

are available in the git repository at:
git://git.pokylinux.org/poky-contrib mhatle/rpm
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=mhatle/rpm

Mark Hatle (5):
rootfs_rpm.bbclass: Enable pre and post install scripts rootfs_rpm.bbclass: Turn off script debugging
wpa-supplicant: Avoid blocking the post install script at cross
rootfs time.
shadow: Generate the shadow files at rootfs construction
sudo: Avoid post install scripts

  meta/classes/package_rpm.bbclass                   |   33 ++++-
  meta/classes/rootfs_rpm.bbclass                    |   27 +---
  .../wpa-supplicant/wpa-supplicant-0.7.inc          |    4 +-
  .../wpa-supplicant/wpa-supplicant_0.7.3.bb         |    2 +-
  .../rpm/rpm/rpm-scriptletexechelper.patch          |  159 ++++++++++++++++++++
  meta/recipes-devtools/rpm/rpm_5.4.0.bb             |    3 +-
  meta/recipes-extended/shadow/shadow_4.1.4.3.bb     |   12 +-
  meta/recipes-extended/sudo/sudo.inc                |    8 -
  meta/recipes-extended/sudo/sudo_1.8.3.bb           |    5 +-
  9 files changed, 214 insertions(+), 39 deletions(-)
Quoted 2 lines

create mode 100644 meta/recipes-devtools/rpm/rpm/rpm-scriptletexechelper.patch

Merged into OE-Core

Thanks
Sau!