Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | SUMMARY = "Packages to exercise postinstall functions" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2 | LICENSE = "MIT" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 3 | |
| 4 | inherit allarch |
| 5 | |
| 6 | PACKAGES = "${PN}-rootfs ${PN}-delayed-a ${PN}-delayed-b ${PN}-rootfs-failing" |
| 7 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 8 | ALLOW_EMPTY:${PN}-rootfs = "1" |
| 9 | ALLOW_EMPTY:${PN}-delayed-a = "1" |
| 10 | ALLOW_EMPTY:${PN}-delayed-b = "1" |
| 11 | ALLOW_EMPTY:${PN}-rootfs-failing = "1" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 12 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 13 | RDEPENDS:${PN}-delayed-a = "${PN}-rootfs" |
| 14 | RDEPENDS:${PN}-delayed-b = "${PN}-delayed-a" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 16 | TESTDIR = "${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 Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 20 | pkg_postinst:${PN}-rootfs () { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 21 | set -e |
| 22 | |
| 23 | if [ -z "$D" ]; then |
| 24 | echo "${PN}-rootfs should have finished at rootfs time" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | exit 1 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 26 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 28 | if [ -e $D${TESTDIR}/rootfs ]; then |
| 29 | echo "$D${TESTDIR}/rootfs exists, but should not" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 30 | exit 1 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 31 | fi |
| 32 | |
| 33 | mkdir -p $D${TESTDIR} |
| 34 | touch $D${TESTDIR}/rootfs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 35 | } |
| 36 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 37 | # Depends on rootfs, delays until first boot, verifies that the rootfs file was |
| 38 | # written. |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 39 | pkg_postinst_ontarget:${PN}-delayed-a () { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 40 | set -e |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 42 | if [ ! -e ${TESTDIR}/rootfs ]; then |
| 43 | echo "${PN}-delayed-a: ${TESTDIR}/rootfs not found" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 44 | exit 1 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 45 | fi |
| 46 | |
| 47 | touch ${TESTDIR}/delayed-a |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 50 | # 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 Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 52 | pkg_postinst_ontarget:${PN}-delayed-b () { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 53 | set -e |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 55 | if [ ! -e ${TESTDIR}/delayed-a ]; then |
| 56 | echo "${PN}-delayed-b: ${TESTDIR}/delayed-a not found" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 57 | exit 1 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 58 | fi |
| 59 | |
| 60 | touch ${TESTDIR}/delayed-b |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 61 | } |
| 62 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 63 | # This scriptlet intentionally includes a bogus command in the middle to test |
| 64 | # that we catch and report such errors properly. |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 65 | pkg_postinst:${PN}-rootfs-failing () { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 66 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 72 | } |