Debian Codegraph @

scripts/debuerreotype-fixup

raw
1 #!/usr/bin/env bash
2 set -Eeuo pipefail
3
4 thisDir="$(dirname "$(readlink -vf "$BASH_SOURCE")")"
5 source "$thisDir/.constants.sh" \
6 '<target-dir>' \
7 'rootfs'
8
9 eval "$dgetopt"
10 while true; do
11 flag="$1"; shift
12 dgetopt-case "$flag"
13 case "$flag" in
14 --) break ;;
15 *) eusage "unknown flag '$flag'" ;;
16 esac
17 done
18
19 targetDir="${1:-}"; shift || eusage 'missing target-dir'
20 [ -n "$targetDir" ]
21 epoch="$(< "$targetDir/debuerreotype-epoch")"
22 [ -n "$epoch" ]
23
24 if [ -s "$targetDir/etc/machine-id" ]; then
25 # https://www.freedesktop.org/software/systemd/man/machine-id.html
26 # > For operating system images which are created once and used on multiple machines, for example for containers or in the cloud, /etc/machine-id should be either missing or an empty file in the generic file system image ...
27 echo -n > "$targetDir/etc/machine-id"
28 chmod 0644 "$targetDir/etc/machine-id"
29 fi
30
31 # https://github.com/lamby/debootstrap/commit/66b15380814aa62ca4b5807270ac57a3c8a0558d#diff-de4eef4ab836e5c6c9c1f820a2f624baR709
32 rm -f \
33 "$targetDir/var/log/dpkg.log" \
34 "$targetDir/var/log/bootstrap.log" \
35 "$targetDir/var/log/alternatives.log" \
36 "$targetDir/var/cache/ldconfig/aux-cache"
37
38 # https://github.com/debuerreotype/debuerreotype/pull/32
39 rm -f "$targetDir/run/mount/utab"
40 # (also remove the directory, but only if it's empty)
41 rmdir "$targetDir/run/mount" 2>/dev/null || :
42
43 find "$targetDir" \
44 -newermt "@$epoch" \
45 -exec touch --no-dereference --date="@$epoch" '{}' +