"Fossies" - the Fresh Open Source Software Archive

Member "libisoburn-1.5.4/releng/manual_devices" (8 Jul 2020, 4773 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.

    1 #!/bin/bash
    2 
    3 # Copyright 2011 George Danchev <danchev@spnet.net>
    4 # Copyright 2011 Thomas Schmitt <scdbackup@gmx.net>
    5 # Licensed under GNU GPL version 2 or later
    6 
    7 # set -e
    8 
    9 print_specific_help() {
   10 cat << HLP
   11 Specific options:
   12        --dev path  Suppress dialog and use path as drive address.
   13        --priv_cmd 'command [arg [arg ...]]'
   14                    With drive operations execute xorriso as argument
   15                    of the given command (e.g. pfexec, sudo) with the
   16                    optionally given arguments: command arg arg xorriso ...
   17                    Command and arguments must be single words.
   18 Overview:
   19        Test device scanning and list of speeds.
   20 HLP
   21 }
   22 
   23 # Include common bits and interpret general options
   24 getopts_inc=inc/releng_getopts.inc
   25 if test -e "$getopts_inc"
   26 then
   27   . "$getopts_inc"
   28 
   29   if test "$SPECIFIC_HELP" = 1
   30   then
   31        print_specific_help
   32        exit 0
   33   fi
   34 else
   35   echo >&2
   36   echo "File not found: $getopts_inc" >&2
   37   echo "Are we in the ./releng directory of a libisoburn SVN checkout ?" >&2
   38   echo "(Please execute the tests from that ./releng directory.)" >&2
   39   echo >&2
   40   exit 2
   41 fi
   42 
   43 # Interpret private options, they begin after the first --.
   44 dev=
   45 priv_cmd=
   46 next_is=ignore
   47 for i in "$@"
   48 do
   49   if test "$next_is" = "ignore"
   50   then
   51        if test "$i" = "--"
   52        then
   53             next_is=""
   54        fi
   55   elif test "$next_is" = "dev"
   56   then
   57        dev="$i"
   58        next_is=""
   59   elif test "$next_is" = "priv_cmd"
   60   then
   61        priv_cmd="$i"
   62        next_is=""
   63   elif test "$i" = "--dev"
   64   then
   65        next_is="dev"
   66   elif test "$i" = "--priv_cmd"
   67   then
   68        next_is="priv_cmd"
   69   else
   70        echo >&2
   71        echo "Unknown test specific option: $i" >&2
   72        print_help
   73        print_specific_help
   74        exit 31
   75   fi
   76 done
   77 
   78 # Insist in having a xorriso 
   79 check_for_xorriso -x
   80 
   81 has_device_links=$("$RELENG_XORRISO" -help 2>/dev/null | fgrep ' -device_links')
   82 if test -n "$has_device_links"
   83 then
   84   devices_opt="-device_links"
   85 else
   86   devices_opt="-devices"
   87 fi
   88 
   89 #
   90 get_speeds() {
   91   echo -e "\n${SELF}: Running:  ${priv_cmd} ${RELENG_XORRISO} -report_about WARNING -outdev ${1} -toc -list_formats -list_profiles out -list_speeds"
   92    ${priv_cmd} "$RELENG_XORRISO" -report_about WARNING -outdev "$1" \
   93                     -print '---toc :'            -toc \
   94                     -print '---list_formats :'   -list_formats \
   95                     -print '---list_profiles :'  -list_profiles out \
   96                     -print '---list_speeds :'    -list_speeds
   97 }
   98 
   99 cat_var() {
  100 # $1 = variable to put out with line feeds
  101 cat <<+
  102 $1
  103 +
  104 }
  105 
  106 get_devices() {
  107   # $1 = if not empty: device lines from xorriso -devices or -device_links
  108   # $2 = if not empty: suppress dialog and use $2 as input
  109 
  110   if test -n "$1"
  111   then
  112        DEVICES="$1"
  113   else
  114        DEVICES=$( ${priv_cmd} "$RELENG_XORRISO" $devices_opt 2>/dev/null | grep "\-dev")
  115   fi
  116   NUM_DEV=$(cat_var "$DEVICES" | wc -l)
  117   case "${NUM_DEV}" in
  118        0)
  119           echo -e "\n${SELF}: No drives found."
  120       exit 1
  121        ;;
  122        1)
  123           echo -e "\n${SELF}: 1 drive found:\n"
  124        ;;
  125        *)
  126           echo -e "\n${SELF}: ${NUM_DEV} drives found:\n"
  127        ;;
  128   esac
  129   echo =================================================================
  130   echo "$DEVICES"
  131   echo =================================================================
  132 
  133   OUTDEV=$( cat_var "$DEVICES" | head -1 | \
  134             sed -e "s/[0-9]  *-dev '\//\//"  -e "s/'.*$//" )
  135   if test -n "$2"
  136   then
  137        x="$2"
  138   else
  139        echo >&2
  140        echo "WARNING: The following tests might pull in the drive tray." >&2
  141        echo "         Best is if you now put in a suitable media and" >&2
  142        echo "         load it manually, so nobody gets surprised. :))" >&2
  143        echo >&2
  144        echo "Which drive to examine ? (Empty input = ${OUTDEV})" >&2
  145        read x
  146   fi
  147   if test -n "$x"
  148   then
  149        OUTDEV="$x"
  150   fi
  151 
  152   get_speeds "$OUTDEV"
  153 }
  154 
  155 # main
  156 "$RELENG_XORRISO"  -version
  157 echo -e "\n${SELF}: Running: $RELENG_XORRISO $devices_opt ..."
  158 devices=$( ${priv_cmd} "$RELENG_XORRISO" -report_about WARNING $devices_opt | grep "\-dev")
  159 RET="$?"
  160 if test "$SIMULATE_FAILURE" = 1
  161 then
  162      echo "===" >&2
  163      echo "=== SIMULATING FAILURE BY OVERRIDING EXIT VALUE OF XORRISO" >&2
  164      echo "===" >&2
  165      echo "FAIL : ${SELF} : Simulated failure caused by option -f"
  166      RET=1
  167 fi
  168 case ${RET} in
  169      0)
  170       get_devices "$devices" "$dev"
  171       RET="$?"
  172       if test "$RET" = 0
  173       then :
  174       else
  175            echo "FAIL : ${SELF} : Device scan or single drive listing failed"
  176            exit "$RET"
  177       fi
  178      ;;
  179      *)
  180       boldify
  181       echo -ne "\n${SELF}: ${priv_cmd} ${RELENG_XORRISO} $devices_opt returned ${RET}."
  182       unboldify
  183       echo -e  "\n${SELF}: Already mounted?"
  184       df -kh
  185       exit 1
  186 esac
  187 
  188 exit 0