1#!/bin/sh 2# 3# The systemd-tmpfiles has the ability to grab information 4# from the filesystem (instead from the running system). 5# 6# tmpfs directories (/tmp, /proc, ...) are skipped since they're not 7# relevant for the rootfs image. 8# 9# However there are a few specifiers that *always* will grab 10# information from the running system examples are %a, %b, %m, %H 11# (Architecture, Boot UUID, Machine UUID, Hostname). 12# 13# See [1] for historic information. 14# 15# This script will (conservatively) skip tmpfiles lines that have 16# such an specifier to prevent leaking host information. 17# 18# shell expansion is critical to be POSIX compliant, 19# this script wont work with zsh in its default mode for example. 20# 21# The script takes several measures to handle more complex stuff 22# like passing this correctly: 23# f+ "/var/example" - - - - %B\n%o\n%w\n%W%%\n 24# 25# [1] - https://github.com/systemd/systemd/pull/16187 26 27[ -n "${HOST_SYSTEMD_TMPFILES-}" ] || 28 HOST_SYSTEMD_TMPFILES=systemd-tmpfiles 29 30[ -n "${1-}" -a -d "${1-}"/usr/lib/tmpfiles.d ] || 31 { echo 1>&2 "$0: need ROOTFS argument"; exit 1; } 32 33${HOST_SYSTEMD_TMPFILES} --no-pager --cat-config --root="$1" | 34 sed -e '/^[[:space:]]*#/d' -e 's,^[[:space:]]*,,' -e '/^$/d' | 35 while read -r line; do 36 # it is allowed to use quotes around arguments, 37 # so let the shell pack the arguments 38 eval "set -- $line" 39 40 # dont output warnings for directories we dont process 41 [ "${2#/dev}" = "${2}" ] && [ "${2#/proc}" = "${2}" ] && 42 [ "${2#/run}" = "${2}" ] && [ "${2#/sys}" = "${2}" ] && 43 [ "${2#/tmp}" = "${2}" ] && [ "${2#/mnt}" = "${2}" ] || 44 continue 45 46 # blank out all specs that are ok to use, 47 # test if some remain. (Specs up to date with v250) 48 if echo "$2 ${7-}" | sed -e 's,%[%BCEgGhLMosStTuUVwW],,g' | grep -v -q '%'; then 49 # no "bad" specifiers, pass the line unmodified 50 eval "printf '%s\n' '$line'" 51 else 52 # warn 53 eval "printf 'ignored spec: %s\n' '$line' 1>&2" 54 fi 55 done | 56 TMPDIR= TEMP= TMP= ${HOST_SYSTEMD_TMPFILES} --create --boot --root="$1" \ 57 --exclude-prefix=/dev --exclude-prefix=/proc --exclude-prefix=/run \ 58 --exclude-prefix=/sys --exclude-prefix=/tmp --exclude-prefix=/mnt \ 59 - 60