blob: d5c5538cd7e731864fa59c42090ae3464b5a5baa [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SUMMARY = "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
Brad Bishop6dbb3162019-11-25 09:41:34 -050014inherit allarch systemd features_check
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015
16REQUIRED_DISTRO_FEATURES = "systemd"
17
18VOLATILE_BINDS ?= "\
19 /var/volatile/lib /var/lib\n\
Brad Bishop37a0e4d2017-12-04 01:01:44 -050020 /var/volatile/cache /var/cache\n\
21 /var/volatile/spool /var/spool\n\
22 /var/volatile/srv /srv\n\
Patrick Williamsc124f4f2015-09-15 14:41:29 -050023"
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
Patrick Williams213cb262021-08-07 19:21:33 -050036SYSTEMD_SERVICE:${PN} = "${@volatile_systemd_services(d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037
Andrew Geissler5199d832021-09-24 16:47:35 -050038FILES:${PN} += "${systemd_system_unitdir}/*.service ${servicedir}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
40do_compile () {
41 while read spec mountpoint; do
42 if [ -z "$spec" ]; then
43 continue
44 fi
45
46 servicefile="${spec#/}"
47 servicefile="$(echo "$servicefile" | tr / -).service"
48 sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \
49 -e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \
50 volatile-binds.service.in >$servicefile
51 done <<END
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053END
54
55 if [ -e var-volatile-lib.service ]; then
56 # As the seed is stored under /var/lib, ensure that this service runs
57 # after the volatile /var/lib is mounted.
58 sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \
59 -e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \
60 var-volatile-lib.service
61 fi
62}
63do_compile[dirs] = "${WORKDIR}"
64
65do_install () {
66 install -d ${D}${base_sbindir}
Andrew Geissler6ce62a22020-11-30 19:58:47 -060067 install -d ${D}${servicedir}
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068 install -m 0755 mount-copybind ${D}${base_sbindir}/
69
Andrew Geissler5199d832021-09-24 16:47:35 -050070 install -d ${D}${systemd_system_unitdir}
Patrick Williams213cb262021-08-07 19:21:33 -050071 for service in ${SYSTEMD_SERVICE:${PN}}; do
Andrew Geissler5199d832021-09-24 16:47:35 -050072 install -m 0644 $service ${D}${systemd_system_unitdir}/
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 done
Brad Bishop37a0e4d2017-12-04 01:01:44 -050074
75 # Suppress attempts to process some tmpfiles that are not temporary.
76 #
77 install -d ${D}${sysconfdir}/tmpfiles.d ${D}/var/cache
78 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf
79 ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080}
81do_install[dirs] = "${WORKDIR}"