Skip to content

Instantly share code, notes, and snippets.

@kergoth
Created May 28, 2021 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kergoth/bb4b92228b383c681d8abed93a0d4166 to your computer and use it in GitHub Desktop.
Save kergoth/bb4b92228b383c681d8abed93a0d4166 to your computer and use it in GitHub Desktop.
SUMMARY = "Volatile bind mount setup and configuration for read-only-rootfs"
DESCRIPTION = "${SUMMARY}"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://COPYING.MIT;md5=5750f3aa4ea2b00c2bf21b2b2a7b714d"
SRC_URI = "\
file://mount-copybind \
file://COPYING.MIT \
file://volatile-binds.service.in \
"
S = "${WORKDIR}"
inherit allarch systemd distro_features_check
REQUIRED_DISTRO_FEATURES = "systemd"
VOLATILE_BINDS ?= "\
/var/volatile/lib /var/lib\n\
/var/volatile/cache /var/cache\n\
/var/volatile/spool /var/spool\n\
/var/volatile/srv /srv\n\
"
VOLATILE_BINDS[type] = "list"
VOLATILE_BINDS[separator] = "\n"
def volatile_systemd_services(d):
services = []
for line in oe.data.typed_value("VOLATILE_BINDS", d):
if not line:
continue
what, where = line.split(None, 1)
services.append("%s.service" % what[1:].replace("/", "-"))
return " ".join(services)
SYSTEMD_SERVICE_${PN} = "${@volatile_systemd_services(d)}"
FILES_${PN} += "${systemd_unitdir}/system/*.service"
starts_with() {
test -n "$(awk -v field=0 -v "prefix=$1" '{ if (index($field, prefix) == 1) { printf("%s\n", $0) } }')"
}
do_compile () {
while read spec mountpoint; do
if [ -z "$spec" ]; then
continue
fi
servicefile="${spec#/}"
servicefile="$(echo "$servicefile" | tr / -).service"
sed -e "s#@what@#$spec#g; s#@where@#$mountpoint#g" \
-e "s#@whatparent@#${spec%/*}#g; s#@whereparent@#${mountpoint%/*}#g" \
volatile-binds.service.in >$servicefile
if echo "${localstatedir}/lib/systemd/random-seed" | starts_with "$mountpoint"; then
sed -i -e "/^Before=/s/\$/ systemd-random-seed.service/" \
-e "/^WantedBy=/s/\$/ systemd-random-seed.service/" \
$servicefile
fi
done <<END
${@d.getVar('VOLATILE_BINDS').replace("\\n", "\n")}
END
}
do_compile[dirs] = "${WORKDIR}"
do_install () {
install -d ${D}${base_sbindir}
install -m 0755 mount-copybind ${D}${base_sbindir}/
install -d ${D}${systemd_unitdir}/system
for service in ${SYSTEMD_SERVICE_${PN}}; do
install -m 0644 $service ${D}${systemd_unitdir}/system/
done
# Suppress attempts to process some tmpfiles that are not temporary.
#
install -d ${D}${sysconfdir}/tmpfiles.d ${D}/var/cache
ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/etc.conf
ln -s /dev/null ${D}${sysconfdir}/tmpfiles.d/home.conf
}
do_install[dirs] = "${WORKDIR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment