blob: b936c4f44be0a4d61ef401aa9e17acef4aab16ed [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001SUMMARY = "Packages to exercise postinstall functions"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002LICENSE = "MIT"
Brad Bishop316dfdd2018-06-25 12:45:53 -04003
4inherit allarch
5
6PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-rootfs-failing"
7
Patrick Williams213cb262021-08-07 19:21:33 -05008ALLOW_EMPTY:${PN}-rootfs = "1"
9ALLOW_EMPTY:${PN}-delayed-a = "1"
10ALLOW_EMPTY:${PN}-delayed-b = "1"
11ALLOW_EMPTY:${PN}-rootfs-failing = "1"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012
Patrick Williams213cb262021-08-07 19:21:33 -050013RDEPENDS:${PN}-delayed-a = "${PN}-rootfs"
14RDEPENDS:${PN}-delayed-b = "${PN}-delayed-a"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015
Brad Bishop316dfdd2018-06-25 12:45:53 -040016TESTDIR = "${sysconfdir}/postinst-test"
17
18# At rootfs time touch $TESTDIR/rootfs. Errors if the file already exists, or
19# if the function runs on first boot.
Patrick Williams213cb262021-08-07 19:21:33 -050020pkg_postinst:${PN}-rootfs () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040021 set -e
22
23 if [ -z "$D" ]; then
24 echo "${PN}-rootfs should have finished at rootfs time"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025 exit 1
Brad Bishop6e60e8b2018-02-01 10:27:11 -050026 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027
Brad Bishop316dfdd2018-06-25 12:45:53 -040028 if [ -e $D${TESTDIR}/rootfs ]; then
29 echo "$D${TESTDIR}/rootfs exists, but should not"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 exit 1
Brad Bishop316dfdd2018-06-25 12:45:53 -040031 fi
32
33 mkdir -p $D${TESTDIR}
34 touch $D${TESTDIR}/rootfs
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035}
36
Brad Bishop316dfdd2018-06-25 12:45:53 -040037# Depends on rootfs, delays until first boot, verifies that the rootfs file was
38# written.
Patrick Williams213cb262021-08-07 19:21:33 -050039pkg_postinst_ontarget:${PN}-delayed-a () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040040 set -e
Brad Bishop6e60e8b2018-02-01 10:27:11 -050041
Brad Bishop316dfdd2018-06-25 12:45:53 -040042 if [ ! -e ${TESTDIR}/rootfs ]; then
43 echo "${PN}-delayed-a: ${TESTDIR}/rootfs not found"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 exit 1
Brad Bishop316dfdd2018-06-25 12:45:53 -040045 fi
46
47 touch ${TESTDIR}/delayed-a
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048}
49
Brad Bishop316dfdd2018-06-25 12:45:53 -040050# Depends on delayed-a, delays until first boot, verifies that the delayed-a file was
51# written. This verifies the ordering between delayed postinsts.
Patrick Williams213cb262021-08-07 19:21:33 -050052pkg_postinst_ontarget:${PN}-delayed-b () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040053 set -e
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054
Brad Bishop316dfdd2018-06-25 12:45:53 -040055 if [ ! -e ${TESTDIR}/delayed-a ]; then
56 echo "${PN}-delayed-b: ${TESTDIR}/delayed-a not found"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057 exit 1
Brad Bishop316dfdd2018-06-25 12:45:53 -040058 fi
59
60 touch ${TESTDIR}/delayed-b
Brad Bishop6e60e8b2018-02-01 10:27:11 -050061}
62
Brad Bishop316dfdd2018-06-25 12:45:53 -040063# This scriptlet intentionally includes a bogus command in the middle to test
64# that we catch and report such errors properly.
Patrick Williams213cb262021-08-07 19:21:33 -050065pkg_postinst:${PN}-rootfs-failing () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040066 mkdir -p $D${TESTDIR}
67 touch $D${TESTDIR}/rootfs-before-failure
68 run_a_really_broken_command
69 # Scriptlet execution should stop here; the following commands are NOT supposed to run.
70 # (oe-selftest checks for it).
71 touch $D${TESTDIR}/rootfs-after-failure
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072}