| 1 |
#!/bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
SUPPORTED_FLAVOURS='alpha-smp amd64 arm64 armmp parisc loong64 m68k powerpc64 powerpc64le riscv64 s390x sparc64-smp generic' |
| 5 |
. debian/tests/test-common |
| 6 |
|
| 7 |
SOURCEDIR=/usr/lib/initramfs-test-copy-file |
| 8 |
|
| 9 |
mkdir -p "${SOURCEDIR}/dir1" |
| 10 |
printf "1" >"${SOURCEDIR}/dir1/file1" |
| 11 |
ln -s dir1 "${SOURCEDIR}/dir2" |
| 12 |
printf "22" >"${SOURCEDIR}/file2" |
| 13 |
printf "333" >"${SOURCEDIR}/file3" |
| 14 |
|
| 15 |
cat >>"${CONFDIR}/initramfs.conf" <<EOF |
| 16 |
MODULES=list |
| 17 |
BUSYBOX=n |
| 18 |
EOF |
| 19 |
|
| 20 |
cat >"${CONFDIR}/hooks/initramfs-test-copy-file" <<EOF |
| 21 |
#!/bin/sh |
| 22 |
set -e |
| 23 |
|
| 24 |
test "\$1" = prereqs && exit |
| 25 |
|
| 26 |
. /usr/share/initramfs-tools/hook-functions |
| 27 |
|
| 28 |
set -x |
| 29 |
|
| 30 |
# Source named via directory symlink should be symlinked (#1076539) |
| 31 |
copy_file test "${SOURCEDIR}/dir1/file1" |
| 32 |
copy_file test "${SOURCEDIR}/dir2/file1" |
| 33 |
|
| 34 |
# Usr-merged target must be recognised with or without leading slash |
| 35 |
# (#1079276) |
| 36 |
copy_file test "${SOURCEDIR#/usr}/file3" "${SOURCEDIR#/usr/}/file3" |
| 37 |
|
| 38 |
# Target that exists as directory must be treated as directory |
| 39 |
mkdir "\${DESTDIR}/${SOURCEDIR}/dir3" |
| 40 |
copy_file test "${SOURCEDIR}/file2" "${SOURCEDIR}/dir3" |
| 41 |
|
| 42 |
# Target with trailing slash must be treated as directory (#1082647) |
| 43 |
copy_file test "${SOURCEDIR}/file2" "${SOURCEDIR}/dir4/" |
| 44 |
|
| 45 |
# Check combination of #1079276 and #1082647 cases |
| 46 |
copy_file test "${SOURCEDIR#/usr}/file3" "${SOURCEDIR#/usr/}/dir5/" |
| 47 |
EOF |
| 48 |
chmod +x "${CONFDIR}/hooks/initramfs-test-copy-file" |
| 49 |
|
| 50 |
build_initramfs |
| 51 |
lsinitramfs -l "${INITRAMFS}" >"${AUTOPKGTEST_TMP}/listing" |
| 52 |
|
| 53 |
rc=0 |
| 54 |
|
| 55 |
check_file() { |
| 56 |
local ftype="$1" |
| 57 |
local name="$2" |
| 58 |
local extra="$3" |
| 59 |
local size_re='[0-9]*' |
| 60 |
local tail_re='' |
| 61 |
|
| 62 |
case "$ftype" in |
| 63 |
-) |
| 64 |
# Regular file: extra is size |
| 65 |
size_re="${extra}" |
| 66 |
;; |
| 67 |
l) |
| 68 |
# Symbolic link: extra is link text |
| 69 |
size_re="${#extra}" |
| 70 |
tail_re=" -> $(printf %s "$extra" | sed 's/\./\\./g')" |
| 71 |
;; |
| 72 |
esac |
| 73 |
|
| 74 |
if ! grep -q "^${ftype}......... *[0-9]* root *root *${size_re} ............ ${name#/}${tail_re}$" "${AUTOPKGTEST_TMP}/listing"; then |
| 75 |
echo >&2 "E: $name did not get copied correctly" |
| 76 |
rc=1 |
| 77 |
fi |
| 78 |
} |
| 79 |
|
| 80 |
# Check that files, directories, and symlinks were created as expected |
| 81 |
check_file d ${SOURCEDIR}/dir1 - |
| 82 |
check_file - ${SOURCEDIR}/dir1/file1 1 |
| 83 |
check_file d ${SOURCEDIR}/dir2 - |
| 84 |
check_file l ${SOURCEDIR}/dir2/file1 ../dir1/file1 |
| 85 |
check_file - ${SOURCEDIR}/file3 3 |
| 86 |
check_file d ${SOURCEDIR}/dir3 - |
| 87 |
check_file - ${SOURCEDIR}/dir3/file2 2 |
| 88 |
check_file d ${SOURCEDIR}/dir4 - |
| 89 |
check_file - ${SOURCEDIR}/dir4/file2 2 |
| 90 |
check_file - ${SOURCEDIR}/dir5/file3 3 |
| 91 |
|
| 92 |
if [ $rc -ne 0 ]; then |
| 93 |
echo "I: Initramfs contents:" |
| 94 |
cat "$AUTOPKGTEST_TMP/listing" |
| 95 |
fi |
| 96 |
|
| 97 |
exit $rc |