"Fossies" - the Fresh Open Source Software Archive

Member "libisoburn-1.5.6/releng/inc/releng_getopts.inc" (8 Jul 2020, 5376 Bytes) of package /linux/misc/libisoburn-1.5.6.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "releng_getopts.inc" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.4.6_vs_1.4.8.

    1 # Copyright 2011 George Danchev <danchev@spnet.net>
    2 # Copyright 2011 Thomas Schmitt <scdbackup@gmx.net>
    3 # Licensed under GNU GPL version 2 or later
    4 
    5 SELF=$(basename $0)
    6 RELENG_XORRISO=0
    7 SIMULATE_FAILURE=0
    8 CLEANUP=1
    9 SPECIFIC_HELP=0
   10 START_DIR_DONT_CHANGE=`pwd`
   11 GEN_DATA_DIR=releng_generated_data/${SELF}
   12 
   13 #############################################
   14 standalone_or_supervised() {
   15  case "${RELENG_SCRIPT_RUN_BY_RUN_ALL_AUTO}" in
   16   1)
   17      echo "${SELF}: Running in Supervised mode"
   18   ;;
   19   *)
   20      echo "${SELF}: Running in Standalone mode"
   21   ;;
   22  esac
   23 }
   24 
   25 # Unconditionally shout out the invocation mode - standalone or supervised
   26 standalone_or_supervised
   27 
   28 #############################################
   29 print_help() {
   30 cat << EOF
   31 
   32 Usage: $SELF -x path/to/xorriso [-k] [-f] [-c] [-h] 
   33                                               [-- ...test specific options...]
   34 General options:
   35        -x  absolute or relative path to xorriso binary to be run.
   36        -k  keep self-generated data.
   37        -c  cleanup self-generated data kept from previous run and exit.
   38        -f  simulate failure.
   39        -h  print this help text
   40        --  end of general options, begin of test specific options.
   41 EOF
   42 }
   43 
   44 #############################################
   45 boldify() {
   46  if which tput >/dev/null 2>&1
   47  then
   48    tput smso || dummy_variable=1
   49  fi
   50 }
   51 
   52 #############################################
   53 unboldify() {
   54  if which tput >/dev/null 2>&1
   55  then
   56    tput rmso || dummy_variable=1
   57  fi
   58 }
   59 
   60 #############################################
   61 cleanup() {
   62  if [ ${CLEANUP} -eq 1 ]; then
   63    # safety net, just in case -> we want to be in the starting
   64    # directory before removing whatever self-generated stuff
   65    if [ -d "${GEN_DATA_DIR}" ]; then
   66        cd "${START_DIR_DONT_CHANGE}" || exit 2
   67        
   68        # Verify once again we are in the releng_generated_data directory
   69        # Check for both returned code of grep and returned matching string
   70        # There is no "readlink -e" on FreeBSD
   71        READ_CANON_EXISTS=`cd "${GEN_DATA_DIR}" 2>/dev/null && pwd`
   72        DIR_NAME_GEN_DATA=`dirname "${READ_CANON_EXISTS}"`
   73        set +e
   74        # There is no "grep -P" on FreeBSD
   75        RET_NON_EMPTY_STRING=`echo "${DIR_NAME_GEN_DATA}" | grep "[a-zA-Z0-9_][a-zA-Z0-9_]*/releng_generated_data$"`
   76        GREP_RET_GEN_DATA="$?"
   77        case "${GREP_RET_GEN_DATA}" in
   78             0)
   79           if [ x"${RET_NON_EMPTY_STRING}" != x"" ]; then
   80                  # now call the nastiness
   81                  chmod -R +w ${GEN_DATA_DIR}
   82                  rm -rf ${GEN_DATA_DIR}
   83 #        boldify
   84                  printf "${SELF}: Removed (self-generated) %s\n" ${GEN_DATA_DIR}
   85 #        unboldify
   86           else
   87                  printf "FAIL : ${SELF} : Safety check for being in releng_generated_data directory.\n"
   88                  printf "FAIL : ${SELF} : GREP returned empty string: ${RET_NON_EMPTY_STRING}.\n"
   89                  printf "FAIL : ${SELF} : Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n"
   90           fi
   91             ;;
   92         *)
   93               printf "FAIL : ${SELF} : Safety check for being in releng_generated_data directory.\n"
   94               printf "FAIL : ${SELF} : GREP returned code: ${GREP_RET_GEN_DATA}.\n"
   95               printf "FAIL : ${SELF} : Skipped trying to remove ${GEN_DATA_DIR} directory. Exiting.\n"
   96           exit 30
   97         ;;
   98        esac
   99    else
  100        printf "${SELF}: ${GEN_DATA_DIR} does not exist. Nothing to clean.\n"
  101    fi
  102  else
  103 #   boldify
  104    printf "${SELF}: Leaving (self-generated) %s\n" ${GEN_DATA_DIR}
  105 #   unboldify
  106  fi 
  107 }
  108 
  109 #############################################
  110 check_for_xorriso() {
  111  # $1: if "-x" then check executability
  112 
  113  if test -z "$RELENG_XORRISO" -o "$RELENG_XORRISO" = "0"
  114  then
  115    print_help
  116 #  print_specific_help
  117    echo
  118    echo "${SELF}: Need -x  absolute or relative path to xorriso binary."
  119    echo
  120    exit 31
  121  fi
  122  if [ x"$1" = x"-x" -a ! -x "$RELENG_XORRISO" ]
  123  then
  124    print_help
  125 #  print_specific_help
  126    echo
  127    echo "${SELF}: Path given by option -x does not lead to an executable file."
  128    echo "Given is: '$RELENG_XORRISO'"
  129    if test "$RELENG_XORRISO" = "xorriso"
  130    then
  131      xorriso=$(type -p xorriso)
  132      if test -n "xorriso"
  133      then
  134        echo "Hint: Try '$xorriso'"
  135      fi
  136    fi
  137    echo
  138    exit 31
  139  fi
  140 }
  141 
  142 
  143 #############################################
  144 
  145 # To catch the exit value of a command in a pipe
  146 return_value_file="$GEN_DATA_DIR"/wrapper_"$$"_return_value
  147 return_wrapper()
  148 {
  149  cmd="$1"
  150  shift 1
  151  "$cmd" "$@"
  152  RET="$?"
  153  echo "$RET" >"$return_value_file"
  154  return "$RET"
  155 }
  156 
  157 #############################################
  158 
  159 next_is=
  160 for i in "$@"
  161 do
  162   if test "$next_is" = "ignore"
  163   then :
  164   elif test "$next_is" = "x"
  165   then
  166        RELENG_XORRISO="$i"
  167        next_is=
  168   elif test x"$i" = x"-x"
  169   then
  170        next_is="x"
  171   elif test x"$i" = x"-k"
  172   then
  173        CLEANUP=0
  174   elif test x"$i" = x"-c"
  175   then
  176        CLEANUP=1
  177        cleanup
  178        exit 0
  179   elif test x"$i" = x"-f"
  180   then
  181        SIMULATE_FAILURE=1
  182   elif test x"$i" = x"-h"
  183   then
  184        print_help
  185        SPECIFIC_HELP=1
  186   elif test x"$i" = x"--"
  187   then 
  188        # Begin of private arguments for caller
  189        next_is="ignore"
  190   else
  191        echo >&2
  192        echo "Unknown general option: $i" >&2
  193        print_help
  194        exit 31
  195   fi
  196 done
  197 
  198 if test "$next_is" = x
  199 then
  200        echo >&2
  201        echo "Option -x expects an argument (the path to the xorriso program)" >&2
  202        print_help
  203        exit 31
  204 fi