2011-06-27 10:59:57 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# ts 2011.06.27
|
|
|
|
# Test the correct handling of hardlinks by xorriso options
|
2011-06-27 12:33:25 +00:00
|
|
|
# -update_r , -hardlinks perform_update , and -extract
|
|
|
|
|
|
|
|
export prog=$(basename "$0")
|
2011-06-27 10:59:57 +00:00
|
|
|
|
|
|
|
export xorriso=xorriso
|
|
|
|
export image_file=/tmp/xorriso_hardlinks.iso
|
|
|
|
export on_disk=/tmp/xorriso_hardlinks_test_dir
|
2011-06-27 14:28:18 +00:00
|
|
|
export in_iso=""
|
2011-06-27 10:59:57 +00:00
|
|
|
export copy_on_disk=/tmp/xorriso_hardlinks_copy_dir
|
|
|
|
export keep=0
|
|
|
|
export failure=0
|
|
|
|
export next_is_xorriso=0
|
2011-06-27 14:28:18 +00:00
|
|
|
export next_is_rc=0
|
2011-06-27 12:33:25 +00:00
|
|
|
export bad=0
|
2011-06-27 10:59:57 +00:00
|
|
|
|
2011-06-27 14:28:18 +00:00
|
|
|
|
|
|
|
config_by_var() {
|
|
|
|
# This is called once before option interpretation, and once for each
|
|
|
|
# option -rc.
|
|
|
|
# Variables get set to empty content to keep them from being applied
|
|
|
|
# more than once and thus overriding settings of higher precedence.
|
|
|
|
|
|
|
|
# >>> The short names are not good.
|
|
|
|
# >>> Environment variables should have a common prefix. Like RELENG_
|
|
|
|
# >>> In general, the names should be a bit more expressive.
|
|
|
|
# >>> Like RELENG_XORRISO
|
|
|
|
|
|
|
|
test -n "$XOR" && xorriso="$XOR" && XOR=
|
|
|
|
test -n "$RELENG_XORRISO" && xorriso="$RELENG_XORRISO" && RELENG_XORRISO=
|
|
|
|
|
|
|
|
test -n "$IMG" && image_file="$IMG" && IMG=
|
|
|
|
test -n "$RELENG_TMPIMAGE" && image_file="$RELENG_TMPIMAGE" \
|
|
|
|
&& RELENG_TMPIMAGE=
|
|
|
|
|
|
|
|
# This is not $DIR, which would exist before and after the test,
|
|
|
|
# but a temporary directory which may not exist before.
|
|
|
|
test -n "$RELENG_TMPDIR" && on_disk="$RELENG_TMPDIR" && RELENG_TMPDIR=
|
|
|
|
|
|
|
|
test -n "$RELENG_ISODIR" && in_iso="$RELENG_ISODIR" && RELENG_ISODIR=
|
|
|
|
|
|
|
|
test -n "$RELENG_TMPCOPYDIR" && copy_on_disk="$RELENG_TMPCOPYDIR" \
|
|
|
|
&& RELENG_TMPCOPYDIR=
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-06-27 10:59:57 +00:00
|
|
|
clean_up() {
|
|
|
|
if test "$keep" = 1
|
|
|
|
then
|
2011-06-27 12:33:25 +00:00
|
|
|
echo "=== Kept test area because of option -keep" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
echo "$on_disk" "$copy_on_disk" "$image_file" >&2
|
|
|
|
else
|
2011-06-27 12:33:25 +00:00
|
|
|
echo "=== Removing test area" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
rm -r "$on_disk" "$copy_on_disk" "$image_file"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2011-06-27 14:28:18 +00:00
|
|
|
|
|
|
|
# Setup
|
|
|
|
|
|
|
|
# Interpret a default configuration file here, if the test has one.
|
|
|
|
# This one has none.
|
|
|
|
|
|
|
|
# >>> Best would be if the configuration file would not override env variables.
|
|
|
|
|
|
|
|
# Process env variables and default configfile variables together
|
|
|
|
config_by_var
|
|
|
|
|
|
|
|
|
|
|
|
# Now interpret program arguments and possibly given config files
|
2011-06-27 10:59:57 +00:00
|
|
|
for i in "$@"
|
|
|
|
do
|
|
|
|
if test "$next_is_xorriso" = 1
|
|
|
|
then
|
|
|
|
xorriso="$i"
|
|
|
|
next_is_xorriso=0
|
2011-06-27 14:28:18 +00:00
|
|
|
elif test "$next_is_rc" = 1
|
2011-06-27 10:59:57 +00:00
|
|
|
then
|
2011-06-27 14:28:18 +00:00
|
|
|
|
|
|
|
# >>> This looks darn dangerous. We need a trustworthy config interpreter.
|
|
|
|
# >>> http://www.netjeff.com/humor/item.cgi?file=ShootInFoot-OS
|
|
|
|
. "$i"
|
|
|
|
|
|
|
|
config_by_var
|
|
|
|
next_is_rc=0
|
2011-06-27 10:59:57 +00:00
|
|
|
elif test x"$i" = x"-rc"
|
|
|
|
then
|
2011-06-27 14:28:18 +00:00
|
|
|
next_is_rc=1
|
2011-06-27 10:59:57 +00:00
|
|
|
elif test x"$i" = x"-keep"
|
|
|
|
then
|
|
|
|
keep=1
|
|
|
|
elif test x"$i" = x"-clean_up"
|
|
|
|
then
|
|
|
|
keep=0
|
|
|
|
clean_up
|
|
|
|
exit 0
|
|
|
|
elif test x"$i" = x"-xorriso"
|
|
|
|
then
|
|
|
|
next_is_xorriso=1
|
|
|
|
else
|
|
|
|
echo "Usage: $0 [-rc FILE] [-keep] [-clean_up] [-xorriso PATH]" >&2
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2011-06-27 14:28:18 +00:00
|
|
|
test -z "$in_iso" && in_iso="$on_disk"
|
|
|
|
|
|
|
|
|
2011-06-27 10:59:57 +00:00
|
|
|
if test -e "$image_file"
|
|
|
|
then
|
2011-06-27 14:28:18 +00:00
|
|
|
echo "=== TEST ENVIRONMENT ERROR: $prog : Existing image_file target:" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
ls -ld "$image_file" >&2
|
2011-06-27 12:33:25 +00:00
|
|
|
bad=1
|
2011-06-27 10:59:57 +00:00
|
|
|
fi
|
|
|
|
if test -e "$on_disk"
|
|
|
|
then
|
2011-06-27 14:28:18 +00:00
|
|
|
echo "=== TEST ENVIRONMENT ERROR: $prog : Existing on_disk target:" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
ls -ld "$on_disk" >&2
|
2011-06-27 12:33:25 +00:00
|
|
|
bad=1
|
2011-06-27 10:59:57 +00:00
|
|
|
fi
|
|
|
|
if test -e "$copy_on_disk"
|
|
|
|
then
|
2011-06-27 14:28:18 +00:00
|
|
|
echo "=== TEST ENVIRONMENT ERROR: $prog : Existing copy_on_disk target:" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
ls -ld "$copy_on_disk" >&2
|
2011-06-27 12:33:25 +00:00
|
|
|
bad=1
|
|
|
|
fi
|
|
|
|
if test "$bad" = 1
|
|
|
|
then
|
2011-06-27 10:59:57 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2011-06-27 12:33:25 +00:00
|
|
|
echo "=== Setting up $on_disk with several hardlinks" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
mkdir "$on_disk" || exit 1
|
|
|
|
echo test_content >"$on_disk"/file_1 || exit 1
|
|
|
|
echo test_content >"$on_disk"/file_2 || exit 1
|
|
|
|
ln "$on_disk"/file_1 "$on_disk"/file_1_link_a || exit 1
|
|
|
|
ln "$on_disk"/file_1 "$on_disk"/file_1_link_b || exit 1
|
|
|
|
ln "$on_disk"/file_2 "$on_disk"/file_2_link_a || exit 1
|
|
|
|
ls -l "$on_disk"/*
|
|
|
|
|
|
|
|
|
2011-06-27 12:33:25 +00:00
|
|
|
echo "=== Producing simple image" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
"$xorriso" \
|
2011-06-27 14:28:18 +00:00
|
|
|
-version \
|
2011-06-27 10:59:57 +00:00
|
|
|
-for_backup \
|
2011-06-27 14:28:18 +00:00
|
|
|
-padding 0 \
|
2011-06-27 10:59:57 +00:00
|
|
|
-outdev "$image_file" \
|
|
|
|
-update_r "$on_disk" "$in_iso" \
|
|
|
|
-hardlinks perform_update
|
|
|
|
|
2011-06-27 12:33:25 +00:00
|
|
|
echo "=== Copying from image to temporary disk tree" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
"$xorriso" \
|
|
|
|
-for_backup \
|
|
|
|
-indev "$image_file" \
|
|
|
|
-osirrox on \
|
|
|
|
-find "$in_iso" -exec lsdl -- \
|
|
|
|
-extract "$in_iso" "$copy_on_disk"
|
|
|
|
|
2011-06-27 12:33:25 +00:00
|
|
|
|
|
|
|
## For testing the test: Let it fail deliberately
|
|
|
|
## rm "$copy_on_disk"/file_1_link_b
|
|
|
|
|
2011-06-27 14:28:18 +00:00
|
|
|
|
2011-06-27 12:33:25 +00:00
|
|
|
echo "=== Comparing original disk tree and temporary one" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
diff -r "$on_disk" "$copy_on_disk"
|
|
|
|
if test "$?" -ne 0
|
|
|
|
then
|
2011-06-27 14:28:18 +00:00
|
|
|
echo "=== WRONG: diff -r $on_disk $copy_on_disk reports differences" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
failure=1
|
2011-06-27 12:33:25 +00:00
|
|
|
else
|
|
|
|
echo "=== OK" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
fi
|
|
|
|
|
2011-06-27 12:33:25 +00:00
|
|
|
echo "=== Checking for hardlinks being siblings" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
ls -l "$copy_on_disk"/*
|
|
|
|
x=$(echo $(ls -l "$copy_on_disk"/* | awk '{print $2}'))
|
|
|
|
expected="3 3 3 2 2"
|
|
|
|
if test x"$x" = x"$expected"
|
|
|
|
then
|
2011-06-27 12:33:25 +00:00
|
|
|
echo "=== OK" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
else
|
2011-06-27 14:28:18 +00:00
|
|
|
echo "=== WRONG: Link count of extracted files is not as expected." >&2
|
|
|
|
echo "=== Expected: $expected" >&2
|
|
|
|
echo "=== Got : $x" >&2
|
2011-06-27 10:59:57 +00:00
|
|
|
failure=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
clean_up
|
|
|
|
|
|
|
|
|
|
|
|
# Report result
|
|
|
|
echo
|
|
|
|
if test "$failure" = 1
|
|
|
|
then
|
2011-06-27 14:28:18 +00:00
|
|
|
echo "======== $prog :" 'FAILED'
|
2011-06-27 10:59:57 +00:00
|
|
|
else
|
2011-06-27 14:28:18 +00:00
|
|
|
echo "======== $prog :" "Passed"
|
2011-06-27 10:59:57 +00:00
|
|
|
fi
|
|
|
|
echo
|
|
|
|
|