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