]>
git.ipfire.org Git - thirdparty/systemd.git/blob - test/test-fstab-generator.sh
2 # SPDX-License-Identifier: LGPL-2.1-or-later
9 elif [[ -x /usr
/lib
/systemd
/system-generators
/systemd-fstab-generator
]]; then
10 generator
=/usr
/lib
/systemd
/system-generators
/systemd-fstab-generator
11 elif [[ -x /lib
/systemd
/system-generators
/systemd-fstab-generator
]]; then
12 generator
=/lib
/systemd
/system-generators
/systemd-fstab-generator
17 src
="$(dirname "$0")/testdata/test-fstab-generator"
19 # fsck(8) is located in /usr/sbin on Debian
22 # systemd-pcrfs@.service could be enabled or not, depending on the host state
23 # of the host system. Override the measurement to avoid the issue.
24 export SYSTEMD_FORCE_MEASURE
=0
26 for f
in "$src"/test-
*.input
; do
30 out
=$
(mktemp
--tmpdir --directory "test-fstab-generator.XXXXXXXXXX")
31 # shellcheck disable=SC2064
32 trap "rm -rf '$out'" EXIT INT QUIT PIPE
34 exp
="${f%.input}.expected"
35 if [[ "${f##*/}" =~ swap
]] && systemd-detect-virt
--container >/dev
/null
; then
36 exp
="${exp}.container"
39 if [[ "${f##*/}" =~ \.fstab\.input
]]; then
40 SYSTEMD_LOG_LEVEL
=debug SYSTEMD_IN_INITRD
=yes SYSTEMD_SYSFS_CHECK
=no SYSTEMD_PROC_CMDLINE
="fstab=yes root=fstab" SYSTEMD_FSTAB
="$f" SYSTEMD_SYSROOT_FSTAB
="/dev/null" $generator "$out" "$out" "$out"
42 SYSTEMD_LOG_LEVEL
=debug SYSTEMD_IN_INITRD
=yes SYSTEMD_SYSFS_CHECK
=no SYSTEMD_PROC_CMDLINE
="fstab=no $(cat "$f")" $generator "$out" "$out" "$out"
45 # The option x-systemd.growfs creates symlink to system's systemd-growfs@.service in .mount.wants directory.
46 # The system that the test is currently running on may not have or may have outdated unit file.
47 # Let's replace the symlink with an empty file.
48 for i
in "$out"/*/systemd-growfs@
*.service
; do
49 [[ -L "$i" ]] ||
continue
54 # For split-usr system
55 for i
in "$out"/systemd-
*.service
; do
56 sed -i -e 's:ExecStart=/lib/systemd/:ExecStart=/usr/lib/systemd/:' "$i"
59 if [[ "${f##*/}" =~ \.fstab\.input
]]; then
60 for i
in "$out"/*.
{automount
,mount
,swap
}; do
61 sed -i -e 's:SourcePath=.*$:SourcePath=/etc/fstab:' "$i"
65 # .deb packager seems to dislike files named with backslash. So, as a workaround, we store files
66 # without backslash in .expected.
67 for i
in "$out"/**/*\\*.
{mount
,swap
}; do
69 if [[ "$i" != "$k" ]]; then
70 if [[ -f "$i" ]]; then
72 elif [[ -L "$i" ]]; then
75 ln -s "${dest//\\/}" "$k"
80 # We store empty files rather than dead symlinks, so that they don't get pruned when packaged up, so compare
81 # the list of filenames rather than their content
82 if ! diff -u <(find "$out" -printf '%P\n' |
sort) <(find "$exp" -printf '%P\n' |
sort); then
83 echo "**** Unexpected output for $f"
87 # Check the main units.
88 if ! diff -u "$out" "$exp"; then
89 echo "**** Unexpected output for $f"
93 # Also check drop-ins.
95 [[ -d "$i" ]] ||
continue
101 expf
="$exp/$dir/$fname"
103 if [[ -L "$j" && ! -e "$j" ]]; then
104 # For dead symlink, we store an empty file.
105 if [[ ! -e "$expf" ||
-n "$(cat "$expf")" ]]; then
106 echo "**** Unexpected symlink $j created by $f"
112 if ! diff -u "$j" "$expf"; then
113 echo "**** Unexpected output in $j for $f"