xref: /OK3568_Linux_fs/yocto/poky/meta/recipes-core/volatile-binds/volatile-binds.bb (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1SUMMARY = "Volatile bind mount setup and configuration for read-only-rootfs"
2DESCRIPTION = "${SUMMARY}"
3LICENSE = "MIT"
4LIC_FILES_CHKSUM = "file://COPYING.MIT;md5=5750f3aa4ea2b00c2bf21b2b2a7b714d"
5
6SRC_URI = "\
7    file://mount-copybind \
8    file://COPYING.MIT \
9    file://volatile-binds.service.in \
10"
11
12S = "${WORKDIR}"
13
14inherit allarch systemd features_check
15
16REQUIRED_DISTRO_FEATURES = "systemd"
17
18VOLATILE_BINDS ?= "\
19    /var/volatile/lib /var/lib\n\
20    /var/volatile/cache /var/cache\n\
21    /var/volatile/spool /var/spool\n\
22    /var/volatile/srv /srv\n\
23"
24VOLATILE_BINDS[type] = "list"
25VOLATILE_BINDS[separator] = "\n"
26
27def volatile_systemd_services(d):
28    services = []
29    for line in oe.data.typed_value("VOLATILE_BINDS", d):
30        if not line:
31            continue
32        what, where = line.split(None, 1)
33        services.append("%s.service" % what[1:].replace("/", "-"))
34    return " ".join(services)
35
36SYSTEMD_SERVICE:${PN} = "${@volatile_systemd_services(d)}"
37
38FILES:${PN} += "${systemd_system_unitdir}/*.service ${servicedir}"
39
40# Set to 1 to forcibly skip OverlayFS, and default to copy+bind
41AVOID_OVERLAYFS = "0"
42
43do_compile () {
44    while read spec mountpoint; do
45        if [ -z "$spec" ]; then
46            continue
47        fi
48
49        servicefile="${spec#/}"
50        servicefile="$(echo "$servicefile" | tr / -).service"
51        sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \
52            -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \
53            -e "s#@avoid_overlayfs@#${@d.getVar('AVOID_OVERLAYFS')}#g" \
54            volatile-binds.service.in >$servicefile
55    done <<END
56${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")}
57END
58
59    if [ -e var-volatile-lib.service ]; then
60        # As the seed is stored under /var/lib, ensure that this service runs
61        # after the volatile /var/lib is mounted.
62        sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \
63               -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \
64               var-volatile-lib.service
65    fi
66}
67do_compile[dirs] = "${WORKDIR}"
68
69do_install () {
70    install -d ${D}${base_sbindir}
71    install -d ${D}${servicedir}
72    install -m 0755 mount-copybind ${D}${base_sbindir}/
73
74    install -d ${D}${systemd_system_unitdir}
75    for service in ${SYSTEMD_SERVICE:${PN}}; do
76        install -m 0644 $service ${D}${systemd_system_unitdir}/
77    done
78
79    # Suppress attempts to process some tmpfiles that are not temporary.
80    #
81    install -d ${D}${sysconfdir}/tmpfiles.d ${D}/var/cache
82    ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf
83    ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf
84}
85do_install[dirs] = "${WORKDIR}"
86