2011-06-27 10:59:57 +00:00
#!/bin/bash
2011-07-11 09:40:23 +00:00
# Copyright 2011 Thomas Schmitt <scdbackup@gmx.net>
# Copyright 2011 George Danchev <danchev@spnet.net>
2011-07-15 06:05:57 +00:00
# Licensed under GNU GPL version 2 or later
2011-07-11 09:40:23 +00:00
2011-06-27 10:59:57 +00:00
# Test the correct handling of hardlinks by xorriso options
2011-06-27 12:33:25 +00:00
# -update_r , -hardlinks perform_update , and -extract
2011-08-18 15:23:32 +00:00
# If there is support for ACLs or xattr in xorriso and on the local system,
# then test recording and restoring of these features.
2011-06-27 12:33:25 +00:00
2011-07-13 11:24:32 +00:00
not_in_releng_exit() {
printf "\nPlease execute the tests from releng directory.\n\n"
exit 1
}
. inc/releng_getopts.inc || not_in_releng_exit
2011-06-27 10:59:57 +00:00
2011-07-20 12:23:40 +00:00
print_specific_help() {
cat << HLP
Specific options:
none yet.
Overview:
Tests ISO image contents by performing various
image generation, extractions and comparisons.
HLP
}
2011-07-18 17:22:59 +00:00
if test "$SPECIFIC_HELP" = 1; then
2011-07-20 12:23:40 +00:00
print_specific_help
2011-07-18 17:22:59 +00:00
exit 0
fi
2011-07-08 12:42:05 +00:00
if [ ! -x $RELENG_XORRISO ]; then
print_help
printf "\n${SELF}: -x absolute or relative path to binary to be run.\n\n"
exit 31
fi
2011-07-08 13:05:21 +00:00
# check data dir, if any and after checking -x xorriso
2011-07-09 15:57:52 +00:00
if [ -d "${GEN_DATA_DIR}" ]; then
printf "\n${SELF}: directory %s exists!" ${GEN_DATA_DIR}
2011-07-15 18:07:02 +00:00
printf "\n${SELF}: use '${SELF} -c' to remove.\n"
2011-07-09 15:57:52 +00:00
exit 8
else
mkdir "${GEN_DATA_DIR}"
fi
2011-07-08 13:05:21 +00:00
2011-07-08 12:42:05 +00:00
export xorriso=${RELENG_XORRISO}
export workdir=${GEN_DATA_DIR}
2011-06-28 06:43:15 +00:00
export image_file="$workdir"/xorriso_hardlinks.iso
export on_disk="$workdir"/xorriso_hardlinks_test_dir
2011-06-27 14:28:18 +00:00
export in_iso=""
2011-06-28 06:43:15 +00:00
export copy_on_disk="$workdir"/xorriso_hardlinks_copy_dir
2011-06-27 10:59:57 +00:00
export failure=0
2011-07-08 12:42:05 +00:00
export simulate_failure=${SIMULATE_FAILURE}
2011-06-27 10:59:57 +00:00
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 16:55:37 +00:00
export report_about="-report_about UPDATE"
2011-06-27 14:28:18 +00:00
test -z "$in_iso" && in_iso="$on_disk"
2011-07-09 15:57:52 +00:00
# mkdir "$workdir" || bad=1
2011-06-28 06:43:15 +00:00
mkdir "$on_disk" || bad=1
if test "$bad" = 1
then
2011-08-05 15:43:58 +00:00
echo -e "\nFAIL : ${SELF} : Test environment error : Cannot make directories"
2011-06-28 06:43:15 +00:00
exit 3
fi
2011-08-18 15:23:32 +00:00
2011-07-09 15:57:52 +00:00
# All must be set at this point
2011-07-10 07:06:30 +00:00
printf "\n${SELF}: Setting up $on_disk with several hardlinks\n" >&2
2011-06-27 10:59:57 +00:00
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
2011-07-09 15:57:52 +00:00
# trivial ISO 9660 image validation routine
2011-07-07 14:11:12 +00:00
is_valid_iso9660() {
ISOfile="$1"
if [ ! -f ${ISOfile} ]; then
failure=1
2011-08-05 15:43:58 +00:00
printf "\nFAIL : ${SELF} : Not found: ${ISOfile}\n"
2011-07-07 14:11:12 +00:00
fi
2011-08-09 11:42:23 +00:00
file ${ISOfile}
if file ${ISOfile} | grep "ISO *9660" >/dev/null 2>&1; then
2011-07-09 15:57:52 +00:00
printf "\n${SELF}: Resulting ${ISOfile} OK. Looks like ISO 9660 filesystem.\n"
2011-07-07 14:11:12 +00:00
else
failure=1
2011-08-05 15:43:58 +00:00
printf "\nFAIL : ${SELF} : ${ISOfile} DOES NOT look like ISO 9660 filesystem data.\n"
2011-07-07 14:11:12 +00:00
fi
}
2011-08-18 15:23:32 +00:00
# Create test file and find out whether ACLs and/or xattr are available.
2011-08-23 10:45:46 +00:00
#
2011-08-18 15:23:32 +00:00
# Users known on GNU/Linux and FreeBSD: root games daemon man
# Groups : daemon games bin sshd sys
2011-08-23 10:45:46 +00:00
# On both systems, ACLs are manipulated by setfacl/getfacl
#
2011-08-18 15:23:32 +00:00
acl_xattr_test_file="$on_disk"/acl_xattr_test_file
2011-08-23 10:45:46 +00:00
acl_xattr_copy_file="$copy_on_disk"/acl_xattr_test_file
acl_xattr_test_dir="$on_disk"/acl_xattr_test_dir
acl_xattr_iso_dir="$in_iso"/acl_xattr_test_dir
acl_xattr_copy_dir="$copy_on_disk"/acl_xattr_test_dir
mkdir "$acl_xattr_test_dir"
2011-08-18 15:23:32 +00:00
echo echo hello world >"$acl_xattr_test_file" || exit 1
sys=$(uname -s)
acls=no
2011-08-23 10:45:46 +00:00
default_acls=no
if ( setfacl -m u::rwx,g::r-x,o::---,u:root:rwx,g::r-x,g:sys:rwx,u:daemon:r--,mask::rwx \
2011-08-18 15:23:32 +00:00
"$acl_xattr_test_file" ) >/dev/null 2>&1
then
if ( getfacl "$acl_xattr_test_file" ) >/dev/null 2>&1
then
2011-08-23 10:45:46 +00:00
if ( setfacl -m u::rwx,g::r-x,o::---,u:root:rwx,g::r-x,g:sys:rwx,u:daemon:r--,mask::rwx \
"$acl_xattr_test_dir" ) >/dev/null 2>&1
then
acls=yes
# Setting of "default" ACLs will fail on FreeBSD. It will nevertheless be
# done in the image by a xorriso command. Restoring is supposed to skip
# "default" ACLs if none could be recorded.
if setfacl -m u::rwx,g::r-x,o::---,u:root:rwx,g:sys:rwx,u:daemon:r--,mask::rwx,d:u::rwx,d:g::r-x,d:o::---,d:u:root:rwx,d:g:sys:rwx,d:u:daemon:r--,d:mask::rwx "$acl_xattr_iso_dir" 2>/dev/null
then
default_acls=yes
fi
fi
2011-08-18 15:23:32 +00:00
fi
fi
2011-08-23 10:45:46 +00:00
# GNU/Linux and FreeBSD have different tools for Extended Attributes
2011-08-18 15:23:32 +00:00
xattrs=no
extattrs=no
2011-08-23 10:45:46 +00:00
# Try GNU/Linux style setattr/getattr
2011-08-18 15:23:32 +00:00
if ( setfattr -n user.test_xattr -v test_value "$acl_xattr_test_file" ) \
>/dev/null 2>&1
then
if ( getfattr "$acl_xattr_test_file" ) >/dev/null 2>&1
then
xattrs=yes
setfattr -n user.long_data -v 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
setfattr -n user.more_data -v 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
fi
fi
if test "$xattrs" = no
then
2011-08-23 10:45:46 +00:00
# Try FreeBSD style setextattr
if ( setextattr user test_xattr test_value "$acl_xattr_test_file" ) \
>/dev/null 2>&1
then
if ( getextattr user test_xattr "$acl_xattr_test_file" ) >/dev/null 2>&1
then
setextattr user long_data 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
setextattr user more_data 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
if ( lsextattr user "$acl_xattr_test_file" ) >/dev/null 2>&1
then
extattrs=yes
fi
fi
fi
2011-08-18 15:23:32 +00:00
fi
echo
2011-08-23 10:45:46 +00:00
echo "${SELF}: Detected sys='$sys' , acls=$acls , d_acls=$default_acls , xattrs=$xattrs , extattrs=$extattrs"
2011-08-18 15:23:32 +00:00
# Examine capabilities of xorriso
xorriso_acls=no
xorriso_xattrs=no
extras=$("$xorriso" -list_extras all 2>/dev/null)
if test "$?" = 0
then
if echo "$extras" | fgrep 'Local ACL : yes' >/dev/null 2>&1
then
xorriso_acls=yes
fi
if echo "$extras" | fgrep 'Local xattr : yes' >/dev/null 2>&1
then
xorriso_xattrs=yes
fi
fi
if test "$xorriso_acls" = no
then
acls=no
fi
if test "$xorriso_xattrs" = no
then
xattrs=no
2011-08-23 10:45:46 +00:00
extattrs=no
2011-08-18 15:23:32 +00:00
fi
echo "${SELF}: Detected xorriso_acls=$xorriso_acls , xorriso_xattrs=$xorriso_xattrs"
echo
ls -l "$on_disk"/*
2011-07-09 15:57:52 +00:00
echo -e "\n${SELF}: Producing simple image via -o" >&2
2011-07-07 14:11:12 +00:00
"$xorriso" -as mkisofs "$on_disk" -o "$workdir"/image_minus_o.iso
is_valid_iso9660 "$workdir"/image_minus_o.iso
2011-07-09 15:57:52 +00:00
echo -e "\n${SELF}: Producing simple image via redirect" >&2
2011-07-07 14:11:12 +00:00
"$xorriso" -as mkisofs "$on_disk" > "$workdir"/image_redirected.iso
is_valid_iso9660 "$workdir"/image_redirected.iso
2011-07-09 15:57:52 +00:00
echo -e "\n${SELF}: Producing simple image via pipe" >&2
2011-07-07 14:11:12 +00:00
"$xorriso" -as mkisofs "$on_disk" | cat > "$workdir"/image_piped.iso
is_valid_iso9660 "$workdir"/image_piped.iso
2011-07-09 15:57:52 +00:00
echo -e "\n${SELF}: Producing simple image with for_backup/update_r/hardlinks" >&2
2011-06-27 10:59:57 +00:00
"$xorriso" \
2011-06-27 16:55:37 +00:00
$report_about \
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" \
2011-08-01 19:23:42 +00:00
-volid TEST_AUTO_ISOCONTENT \
2011-06-27 10:59:57 +00:00
-update_r "$on_disk" "$in_iso" \
2011-08-23 10:45:46 +00:00
-setfacl u::rwx,g::r-x,o::---,u:root:rwx,g:sys:rwx,u:daemon:r--,mask::rwx,d:u::rwx,d:g::r-x,d:o::---,d:u:root:rwx,d:g:sys:rwx,d:u:daemon:r--,d:mask::rwx "$acl_xattr_iso_dir" -- \
2011-06-27 10:59:57 +00:00
-hardlinks perform_update
2011-08-01 19:23:42 +00:00
ret=$?
2011-08-23 10:45:46 +00:00
2011-08-01 19:23:42 +00:00
if test "$ret" -gt 0 -a "$ret" -lt 32
then
2011-08-18 15:23:32 +00:00
printf "\nFAIL : ${SELF} : xorriso write run failed\n\n"
2011-08-01 19:23:42 +00:00
cleanup
exit 1
fi
2011-07-09 09:13:06 +00:00
is_valid_iso9660 "$image_file"
2011-06-27 10:59:57 +00:00
2011-08-01 19:23:42 +00:00
# It must refuse to load and go on with -assert_volid and non-matching pattern.
msg=$(\
"$xorriso" \
-abort_on FATAL \
-return_with FAILURE 32 \
-assert_volid 'NON_MATCHING*' FATAL \
-indev "$image_file" \
2>&1
)
ret=$?
if test "$ret" -gt 0 -a "$ret" -lt 32
then
printf "\n${SELF}: Ok. -assert_volid snapped.\n"
elif test "$ret" -ne 0
then
failure=1
echo >&2
echo "$msg" >&2
2011-08-18 15:23:32 +00:00
printf "\nFAIL : ${SELF} : -assert_volid test not properly performed\n\n"
2011-08-01 19:23:42 +00:00
else
failure=1
2011-08-05 15:43:58 +00:00
printf "\nFAIL : ${SELF} : -assert_volid did not snap\n\n" >&2
2011-08-01 19:23:42 +00:00
fi
2011-07-09 15:57:52 +00:00
echo -e "\n${SELF}: Copying from image to temporary disk tree" >&2
2011-06-27 10:59:57 +00:00
"$xorriso" \
2011-06-27 16:55:37 +00:00
$report_about \
2011-06-27 10:59:57 +00:00
-for_backup \
2011-08-01 19:23:42 +00:00
-assert_volid 'TEST_AUTO_ISOCONT*' FATAL \
2011-06-27 10:59:57 +00:00
-indev "$image_file" \
-osirrox on \
-find "$in_iso" -exec lsdl -- \
-extract "$in_iso" "$copy_on_disk"
2011-08-01 19:23:42 +00:00
ret=$?
if test "$ret" -gt 0 -a "$ret" -lt 32
then
2011-08-18 15:23:32 +00:00
printf "\nFAIL : ${SELF} : xorriso file extraction run failed\n\n"
2011-08-01 19:23:42 +00:00
cleanup
exit 1
fi
2011-06-27 12:33:25 +00:00
2011-06-28 07:12:35 +00:00
if test "$simulate_failure" = 1
then
2011-07-09 15:57:52 +00:00
echo -e "\n${SELF}: SIMULATING FAILURE BY REMOVING AN EXTRACTED FILE" >&2
2011-08-05 15:43:58 +00:00
echo -e "\nFAIL : ${SELF} : Simulated failure caused by option -fail"
2011-06-28 07:12:35 +00:00
rm "$copy_on_disk"/file_1_link_b
fi
2011-06-27 12:33:25 +00:00
2011-06-27 14:28:18 +00:00
2011-07-09 15:57:52 +00:00
printf "\n${SELF}: 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-08-05 15:43:58 +00:00
echo -e "\nFAIL : ${SELF} : diff -r $on_disk $copy_on_disk reports differences" >&2
echo -e "\nFAIL : ${SELF} : diff -r reports differences"
2011-06-27 10:59:57 +00:00
failure=1
2011-06-27 12:33:25 +00:00
else
2011-07-09 15:57:52 +00:00
printf "OK" >&2
2011-06-27 10:59:57 +00:00
fi
2011-07-09 15:57:52 +00:00
printf "\n${SELF}: Checking for hardlinks being siblings...\n"
2011-06-27 10:59:57 +00:00
ls -l "$copy_on_disk"/*
2011-08-23 10:45:46 +00:00
x=$(echo $(ls -ld "$copy_on_disk"/*file* | awk '{print $2}'))
2011-08-18 15:23:32 +00:00
expected="1 3 3 3 2 2"
2011-06-27 10:59:57 +00:00
if test x"$x" = x"$expected"
then
2011-08-18 15:23:32 +00:00
printf "${SELF}: Checking for hardlinks being siblings done: ok.\n" >&2
2011-06-27 10:59:57 +00:00
else
2011-08-05 15:43:58 +00:00
printf "\nFAIL : ${SELF} : Link count of extracted files is not as expected." >&2
2011-07-09 15:57:52 +00:00
printf "\n${SELF}: Expected: $expected" >&2
printf "\n${SELF}: Got : $x\n" >&2
2011-06-27 10:59:57 +00:00
failure=1
fi
2011-08-18 15:23:32 +00:00
if test "$acls" = yes
then
printf "\n${SELF}: Checking ACLs ...\n" >&2
acl_on_disk=$(getfacl "$acl_xattr_test_file" | grep -v '^# file:' | sort)
2011-08-23 10:45:46 +00:00
acl_in_copy=$(getfacl "$acl_xattr_copy_file" | grep -v '^# file:' | sort)
2011-08-18 15:23:32 +00:00
if test "$acl_on_disk" = "$acl_in_copy"
then
printf "${SELF}: Checking ACLs done: ok.\n" >&2
else
printf "\nFAIL : ${SELF} : ACL mismatch between original and extracted copy\n"
printf "\nOriginal:\n${acl_on_disk}\n"
printf "\nCopy:\n${acl_in_copy}\n"
failure=1
fi
fi
if test "$xattrs" = yes
then
printf "\n${SELF}: Checking xattr via getfattr ...\n" >&2
xattr_on_disk=$(getfattr "$acl_xattr_test_file" | \
grep -v '^# file:' | grep -v '^$' | \sort)
2011-08-23 10:45:46 +00:00
xattr_in_copy=$(getfattr "$acl_xattr_copy_file" |
2011-08-18 15:23:32 +00:00
grep -v '^# file:' | grep -v '^$' | sort)
if test "$xattr_on_disk" = "$xattr_in_copy"
then
num_xattr=$(echo "$xattr_on_disk" | wc -l)
printf "${SELF}: Checking xattr done: $num_xattr attributes, ok.\n" >&2
else
printf "\nFAIL : ${SELF} : xattr mismatch between original and extracted copy\n"
printf "\nOriginal:\n${xattr_on_disk}\n"
printf "\nCopy:\n${xattr_in_copy}\n"
failure=1
fi
2011-08-23 10:45:46 +00:00
elif test "$extattrs" = yes
2011-08-18 15:23:32 +00:00
then
2011-08-23 10:45:46 +00:00
printf "\n${SELF}: Checking xattr via lsextattr and getextattr ...\n" >&2
lsext_on_disk=$(lsextattr -q user "$acl_xattr_test_file")
xattr_on_disk=$(for i in $lsext_on_disk ; do echo $i $(getextattr -q user $i "$acl_xattr_test_file"); done | sort)
lsext_in_copy=$(lsextattr -q user "$acl_xattr_copy_file")
xattr_in_copy=$(for i in $lsext_in_copy ; do echo $i $(getextattr -q user $i "$acl_xattr_copy_file"); done | sort)
if test "$xattr_on_disk" = "$xattr_in_copy"
then
num_xattr=$(echo "$xattr_on_disk" | wc -l)
printf "${SELF}: Checking xattr done: $num_xattr attributes, ok.\n" >&2
else
printf "\nFAIL : ${SELF} : xattr mismatch between original and extracted copy\n"
printf "\nOriginal:\n${xattr_on_disk}\n"
printf "\nCopy:\n${xattr_in_copy}\n"
failure=1
fi
2011-08-18 15:23:32 +00:00
fi
2011-07-09 15:57:52 +00:00
#
2011-08-18 15:23:32 +00:00
echo
2011-07-08 12:42:05 +00:00
cleanup
2011-06-27 10:59:57 +00:00
# Report result
echo
if test "$failure" = 1
then
2011-07-09 15:57:52 +00:00
printf "${SELF}: FAILED"
2011-06-28 07:12:35 +00:00
echo
2011-06-27 15:21:14 +00:00
exit 1
2011-06-27 10:59:57 +00:00
else
2011-07-09 15:57:52 +00:00
printf "${SELF}: Passed"
2011-06-27 15:21:14 +00:00
echo
2011-06-27 10:59:57 +00:00
fi
2011-06-27 15:21:14 +00:00
exit 0