"Fossies" - the Fresh Open Source Software Archive

Member "libisoburn-1.5.4/releng/auto_isocontent" (8 Jul 2020, 12570 Bytes) of package /linux/misc/libisoburn-1.5.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

A hint: This file contains one or more very long lines, so maybe it is better readable using the pure text view mode that shows the contents as wrapped lines within the browser window.


    1 #!/bin/bash
    2 
    3 # Copyright 2011 Thomas Schmitt <scdbackup@gmx.net>
    4 # Copyright 2011 George Danchev <danchev@spnet.net>
    5 # Licensed under GNU GPL version 2 or later
    6 
    7 # Test the correct handling of hardlinks by xorriso options
    8 # -update_r , -hardlinks perform_update , and -extract
    9 # If there is support for ACLs or xattr in xorriso and on the local system,
   10 # then test recording and restoring of these features.
   11 
   12 not_in_releng_exit() {
   13   printf "\nPlease execute the tests from releng directory.\n\n"
   14   exit 1
   15 }
   16 
   17 . inc/releng_getopts.inc || not_in_releng_exit
   18 
   19 print_specific_help() {
   20 cat << HLP
   21 Specific options:
   22        none yet.
   23 Overview:
   24        Tests ISO image contents by performing various
   25        image generation, extractions and comparisons.
   26 HLP
   27 }
   28 
   29 if test "$SPECIFIC_HELP" = 1; then
   30   print_specific_help
   31   exit 0
   32 fi
   33 
   34 if [ ! -x $RELENG_XORRISO ]; then
   35  print_help
   36  printf "\n${SELF}: -x  absolute or relative path to binary to be run.\n\n"
   37  exit 31
   38 fi
   39 
   40 # check data dir, if any and after checking -x xorriso
   41 if [ -d "${GEN_DATA_DIR}" ]; then
   42  printf "\n${SELF}: directory %s exists!" ${GEN_DATA_DIR}
   43  printf "\n${SELF}: use '${SELF} -c' to remove.\n"
   44  exit 8
   45 else
   46  mkdir "${GEN_DATA_DIR}"
   47 fi
   48 
   49 export xorriso=${RELENG_XORRISO}
   50 export workdir=${GEN_DATA_DIR}
   51 export image_file="$workdir"/xorriso_hardlinks.iso
   52 export on_disk="$workdir"/xorriso_hardlinks_test_dir
   53 export in_iso=""
   54 export copy_on_disk="$workdir"/xorriso_hardlinks_copy_dir
   55 export failure=0
   56 export simulate_failure=${SIMULATE_FAILURE}
   57 export next_is_xorriso=0
   58 export next_is_rc=0
   59 export bad=0
   60 export report_about="-report_about UPDATE"
   61 
   62 test -z "$in_iso" && in_iso="$on_disk"
   63 
   64 # mkdir "$workdir" || bad=1
   65 mkdir "$on_disk" || bad=1
   66 if test "$bad" = 1
   67 then
   68   echo -e "\nFAIL : ${SELF} : Test environment error : Cannot make directories"
   69   exit 3
   70 fi
   71 
   72 
   73 # All must be set at this point
   74 printf "\n${SELF}: Setting up $on_disk with several hardlinks\n" >&2
   75 echo test_content >"$on_disk"/file_1 || exit 1
   76 echo test_content >"$on_disk"/file_2 || exit 1
   77 ln "$on_disk"/file_1 "$on_disk"/file_1_link_a || exit 1
   78 ln "$on_disk"/file_1 "$on_disk"/file_1_link_b || exit 1
   79 ln "$on_disk"/file_2 "$on_disk"/file_2_link_a || exit 1
   80 
   81 # trivial ISO 9660 image validation routine
   82 is_valid_iso9660() {
   83  ISOfile="$1"
   84  if ! which file >/dev/null 2>&1; then
   85    printf "\nFAIL : ${SELF}: Not found: file. Please install the file(1) utility.\n"
   86    failure=1
   87    return
   88  fi
   89  if [ ! -f ${ISOfile} ]; then
   90    failure=1
   91    printf "\nFAIL : ${SELF} : Not found: ${ISOfile}\n"
   92    return
   93  fi
   94 
   95  file ${ISOfile}
   96  if file ${ISOfile} | grep  "ISO *9660" >/dev/null 2>&1; then
   97    printf "\n${SELF}: Resulting ${ISOfile} OK. Looks like ISO 9660 filesystem.\n"
   98  else
   99    failure=1
  100    printf "\nFAIL : ${SELF} : ${ISOfile} DOES NOT look like ISO 9660 filesystem data.\n"
  101  fi
  102 }
  103 
  104 # Retrieve and evaluate return value of command run under return_wrapper
  105 check_xorriso_return() {
  106  ret=$(cat "$return_value_file")
  107  rm "$return_value_file"
  108  if test "$ret" = 0
  109  then
  110    return 0
  111  fi
  112  failure=1
  113  echo
  114  echo "FAIL : ${SELF} : xorriso run exited with value $ret"
  115  return 1
  116 }
  117 
  118 # Create test file and find out whether ACLs and/or xattr are available.
  119 #
  120 # Users known on GNU/Linux and FreeBSD: root games daemon man
  121 # Groups                              : daemon games bin sshd sys
  122 # On both systems, ACLs are manipulated by setfacl/getfacl
  123 #
  124 acl_xattr_test_file="$on_disk"/acl_xattr_test_file
  125 acl_xattr_copy_file="$copy_on_disk"/acl_xattr_test_file
  126 acl_xattr_test_dir="$on_disk"/acl_xattr_test_dir
  127 acl_xattr_iso_dir="$in_iso"/acl_xattr_test_dir
  128 acl_xattr_copy_dir="$copy_on_disk"/acl_xattr_test_dir
  129 mkdir "$acl_xattr_test_dir"
  130 echo echo hello world >"$acl_xattr_test_file" || exit 1
  131 sys=$(uname -s)
  132 acls=no
  133 default_acls=no
  134 setfacl_opts=""
  135 if ( setfacl -m u::rwx,g::r-x,o::---,u:root:rwx,g:sys:rwx,u:daemon:r--,mask::rwx \
  136              "$acl_xattr_test_file" ) >/dev/null 2>&1
  137 then
  138   if ( getfacl "$acl_xattr_test_file" ) >/dev/null 2>&1
  139   then
  140     if ( setfacl -m u::rwx,g::r-x,o::---,u:root:rwx,g:sys:rwx,u:daemon:r--,mask::rwx \
  141                  "$acl_xattr_test_dir" ) >/dev/null 2>&1
  142     then
  143       acls=yes
  144       # Setting of "default" ACLs will fail on FreeBSD. It will nevertheless be
  145       # done in the image by a xorriso command. Restoring is supposed to skip
  146       # "default" ACLs if none could be recorded. 
  147       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
  148       then
  149         default_acls=yes
  150       fi
  151       setfacl_opts="-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 --"
  152     fi
  153   fi
  154 fi
  155 
  156 # GNU/Linux and FreeBSD have different tools for Extended Attributes
  157 xattrs=no
  158 extattrs=no
  159 # Try GNU/Linux style setattr/getattr
  160 if ( setfattr -n user.test_xattr -v test_value "$acl_xattr_test_file" ) \
  161    >/dev/null 2>&1
  162 then
  163   if ( getfattr -d "$acl_xattr_test_file" ) >/dev/null 2>&1
  164   then
  165     xattrs=yes
  166     setfattr -n user.long_data -v 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
  167     setfattr -n user.more_data -v 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
  168   fi
  169 fi
  170 if test "$xattrs" = no
  171 then
  172   # Try FreeBSD style setextattr
  173   if ( setextattr user test_xattr test_value "$acl_xattr_test_file" ) \
  174      >/dev/null 2>&1
  175   then
  176     if ( getextattr user test_xattr "$acl_xattr_test_file" ) >/dev/null 2>&1
  177     then
  178       setextattr user long_data 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
  179       setextattr user more_data 01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 "$acl_xattr_test_file"
  180       if ( lsextattr user "$acl_xattr_test_file" ) >/dev/null 2>&1
  181       then
  182         extattrs=yes
  183       fi
  184     fi
  185   fi
  186 fi
  187 
  188 echo
  189 echo "${SELF}: Detected sys='$sys' , acls=$acls , d_acls=$default_acls , xattrs=$xattrs , extattrs=$extattrs"
  190 
  191 # Examine capabilities of xorriso 
  192 xorriso_acls=no
  193 xorriso_xattrs=no
  194 extras=$("$xorriso" -list_extras all 2>/dev/null)
  195 if test "$?" = 0
  196 then
  197   if echo "$extras" | fgrep 'Local ACL    : yes' >/dev/null 2>&1
  198   then
  199     xorriso_acls=yes
  200   fi
  201   if echo "$extras" | fgrep 'Local xattr  : yes' >/dev/null 2>&1
  202   then
  203     xorriso_xattrs=yes
  204   fi
  205 fi
  206 if test "$xorriso_acls" = no
  207 then
  208   acls=no
  209   setfacl_opts=
  210 fi
  211 if test "$xorriso_xattrs" = no
  212 then
  213   xattrs=no
  214   extattrs=no
  215 fi
  216   
  217 echo "${SELF}: Detected xorriso_acls=$xorriso_acls , xorriso_xattrs=$xorriso_xattrs"
  218 echo
  219 ls -l "$on_disk"/*
  220 
  221 echo -e "\n${SELF}: Producing simple image via -o" >&2
  222 "$xorriso" -as mkisofs "$on_disk" -o "$workdir"/image_minus_o.iso
  223 is_valid_iso9660                          "$workdir"/image_minus_o.iso
  224 
  225 echo -e "\n${SELF}: Producing simple image via redirect" >&2
  226 "$xorriso" -as mkisofs "$on_disk" >       "$workdir"/image_redirected.iso
  227 is_valid_iso9660                          "$workdir"/image_redirected.iso
  228 
  229 echo -e "\n${SELF}: Producing simple image via pipe" >&2
  230 return_wrapper "$xorriso" -as mkisofs "$on_disk" | \
  231                cat > "$workdir"/image_piped.iso
  232 check_xorriso_return
  233 is_valid_iso9660                          "$workdir"/image_piped.iso
  234 
  235 echo -e "\n${SELF}: Producing simple image with for_backup/update_r/hardlinks" >&2
  236 "$xorriso" \
  237   $report_about \
  238   -version \
  239   -for_backup \
  240   -padding 0 \
  241   -outdev "$image_file" \
  242   -volid TEST_AUTO_ISOCONTENT \
  243   -update_r "$on_disk" "$in_iso" \
  244   $setfacl_opts \
  245   -hardlinks perform_update
  246 ret=$?
  247 
  248 if test "$ret" -gt 0 -a "$ret" -lt 32
  249 then
  250   printf "\nFAIL : ${SELF} : xorriso write run failed\n\n"
  251   cleanup
  252   exit 1
  253 fi
  254 is_valid_iso9660                         "$image_file"
  255 
  256 
  257 # It must refuse to load and go on with -assert_volid and non-matching pattern.
  258 msg=$(\
  259 "$xorriso" \
  260  -abort_on FATAL \
  261  -return_with FAILURE 32 \
  262  -assert_volid 'NON_MATCHING*' FATAL \
  263  -indev "$image_file" \
  264  2>&1
  265 )
  266 ret=$?
  267 if test "$ret" -gt 0 -a "$ret" -lt 32
  268 then
  269   printf "\n${SELF}: Ok. -assert_volid snapped.\n"
  270 elif test "$ret" -ne 0
  271 then
  272   failure=1
  273   echo >&2
  274   echo "$msg" >&2
  275   printf "\nFAIL : ${SELF} : -assert_volid test not properly performed\n\n"
  276 else
  277   failure=1
  278   printf "\nFAIL : ${SELF} : -assert_volid did not snap\n\n" >&2
  279 fi
  280 
  281 echo -e "\n${SELF}: Copying from image to temporary disk tree" >&2
  282 "$xorriso" \
  283   $report_about \
  284   -for_backup \
  285   -assert_volid 'TEST_AUTO_ISOCONT*' FATAL \
  286   -indev "$image_file" \
  287   -osirrox on \
  288   -find "$in_iso" -exec lsdl -- \
  289   -extract "$in_iso" "$copy_on_disk"
  290 ret=$?
  291 if test "$ret" -gt 0 -a "$ret" -lt 32
  292 then
  293   printf "\nFAIL : ${SELF} : xorriso file extraction run failed\n\n"
  294   cleanup
  295   exit 1
  296 fi
  297 
  298 if test "$simulate_failure" = 1
  299 then
  300   echo -e "\n${SELF}: SIMULATING FAILURE BY REMOVING AN EXTRACTED FILE" >&2
  301   echo -e "\nFAIL : ${SELF} : Simulated failure caused by option -fail"
  302   rm "$copy_on_disk"/file_1_link_b
  303 fi
  304 
  305 
  306 printf "\n${SELF}: Comparing original disk tree and temporary one..." >&2
  307 diff -r "$on_disk" "$copy_on_disk"
  308 if test "$?" -ne 0
  309 then
  310   echo -e "\nFAIL : ${SELF} : diff -r $on_disk $copy_on_disk   reports differences" >&2
  311   echo -e "\nFAIL : ${SELF} : diff -r reports differences"
  312   failure=1
  313 else
  314   printf "OK" >&2
  315 fi
  316 
  317 printf "\n${SELF}: Checking for hardlinks being siblings...\n"
  318 ls -l "$copy_on_disk"/*
  319 x=$(echo $(ls -ld "$copy_on_disk"/*file* | awk '{print $2}'))
  320 expected="1 3 3 3 2 2"
  321 if test x"$x" = x"$expected"
  322 then
  323   printf "${SELF}: Checking for hardlinks being siblings done: ok.\n" >&2
  324 else
  325   printf "\nFAIL : ${SELF} : Link count of extracted files is not as expected." >&2
  326   printf "\n${SELF}: Expected:  $expected" >&2
  327   printf "\n${SELF}: Got     :  $x\n" >&2
  328   failure=1
  329 fi
  330 
  331 if test "$acls" = yes
  332 then
  333   printf "\n${SELF}: Checking ACLs ...\n" >&2
  334   acl_on_disk=$(getfacl "$acl_xattr_test_file" | grep -v '^# file:' | sort)
  335   acl_in_copy=$(getfacl "$acl_xattr_copy_file" | grep -v '^# file:' | sort)
  336   if test "$acl_on_disk" = "$acl_in_copy"
  337   then
  338     printf "${SELF}: Checking ACLs done: ok.\n" >&2
  339   else
  340     printf "\nFAIL : ${SELF} : ACL mismatch between original and extracted copy\n"
  341     printf "\nOriginal:\n${acl_on_disk}\n"
  342     printf "\nCopy:\n${acl_in_copy}\n"
  343     failure=1
  344   fi
  345 fi
  346 
  347 if test "$xattrs" = yes
  348 then
  349   printf "\n${SELF}: Checking xattr via getfattr ...\n" >&2
  350   xattr_on_disk=$(getfattr "$acl_xattr_test_file" | \
  351                   grep -v '^# file:' | grep -v '^$' | \sort)
  352   xattr_in_copy=$(getfattr "$acl_xattr_copy_file" | 
  353                   grep -v '^# file:' | grep -v '^$' | sort)
  354   if test "$xattr_on_disk" = "$xattr_in_copy"
  355   then
  356     num_xattr=$(echo "$xattr_on_disk" | wc -l)
  357     printf "${SELF}: Checking xattr done: $num_xattr attributes, ok.\n" >&2
  358   else
  359     printf "\nFAIL : ${SELF} : xattr mismatch between original and extracted copy\n"
  360     printf "\nOriginal:\n${xattr_on_disk}\n"
  361     printf "\nCopy:\n${xattr_in_copy}\n"
  362     failure=1
  363   fi
  364 elif test "$extattrs" = yes
  365 then
  366   printf "\n${SELF}: Checking xattr via lsextattr and getextattr ...\n" >&2
  367   lsext_on_disk=$(lsextattr -q user "$acl_xattr_test_file")
  368   xattr_on_disk=$(for i in $lsext_on_disk ; do echo $i $(getextattr -q user $i "$acl_xattr_test_file"); done | sort)
  369   lsext_in_copy=$(lsextattr -q user "$acl_xattr_copy_file")
  370   xattr_in_copy=$(for i in $lsext_in_copy ; do echo $i $(getextattr -q user $i "$acl_xattr_copy_file"); done | sort)
  371   if test "$xattr_on_disk" = "$xattr_in_copy"
  372   then
  373     num_xattr=$(echo "$xattr_on_disk" | wc -l)
  374     printf "${SELF}: Checking xattr done: $num_xattr attributes, ok.\n" >&2
  375   else
  376     printf "\nFAIL : ${SELF} : xattr mismatch between original and extracted copy\n"
  377     printf "\nOriginal:\n${xattr_on_disk}\n"
  378     printf "\nCopy:\n${xattr_in_copy}\n"
  379     failure=1
  380   fi
  381 
  382 fi
  383 
  384 #
  385 echo
  386 cleanup
  387 
  388 # Report result
  389 echo 
  390 if test "$failure" = 1
  391 then
  392   printf "${SELF}: FAILED"
  393   echo 
  394   exit 1
  395 else
  396   printf "${SELF}: Passed"
  397   echo 
  398 fi
  399 
  400 exit 0