BASIS  r3148
basistest.sh
Go to the documentation of this file.
00001 #! /bin/bash
00002 __FILE__="$(cd -P -- "$(dirname -- "$BASH_SOURCE")" && pwd -P)/$(basename -- "$BASH_SOURCE")"; if [[ -n "$SGE_ROOT" ]] && [[ $__FILE__ =~ $SGE_ROOT/.* ]] && [[ -n "${BASIS_DIR}" ]] && [[ -f "${BASIS_DIR}/bin/basistest.sh" ]]; then __FILE__="${BASIS_DIR}/bin/basistest.sh"; fi; i=0; lnk="$__FILE__"; while [[ -h "$lnk" ]] && [[ $i -lt 100 ]]; do dir=`dirname -- "$lnk"`; lnk=`readlink -- "$lnk"`; lnk=`cd "$dir" && cd $(dirname -- "$lnk") && pwd`/`basename -- "$lnk"`; let i++; done; [[ $i -lt 100 ]] && __FILE__="$lnk"; unset -v i dir lnk; __DIR__="$(dirname -- "$__FILE__")"; BASIS_BASH_UTILITIES="$__DIR__/../lib/bash/basis/basis.sh"; BASHPATH="$__DIR__/../lib:$__DIR__/../lib/bash:$BASHPATH" # <-- added by BASIS
00003 ##############################################################################
00004 # @file  basistest.sh
00005 # @brief Common wrapper for the basistest subcommands.
00006 #
00007 # Copyright (c) 2011, 2012 University of Pennsylvania. All rights reserved.<br />
00008 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00009 #
00010 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00011 #
00012 # @ingroup Tools
00013 ##############################################################################
00014 
00015 . ${BASIS_BASH_UTILITIES} || exit 1
00016 
00017 # ============================================================================
00018 # constants
00019 # ============================================================================
00020 
00021 exename _EXEC_NAME && readonly _EXEC_NAME
00022 
00023 # ============================================================================
00024 # help
00025 # ============================================================================
00026 
00027 # ----------------------------------------------------------------------------
00028 ## @brief Print help.
00029 function print_help
00030 {
00031     print_synopsis
00032     echo
00033     cat - << EOF-DESCRIPTION
00034 Description:
00035   This executable is a wrapper for the basistest subcommands. The name of the
00036   subcommand to execute must be given as first argument.
00037 EOF-DESCRIPTION
00038     echo
00039     print_options
00040     echo
00041     print_contact
00042 }
00043 
00044 # ----------------------------------------------------------------------------
00045 ## @brief Print usage information.
00046 function print_helpshort
00047 {
00048     print_synopsis
00049     echo
00050     print_options
00051     echo
00052     print_contact
00053 }
00054 
00055 # ----------------------------------------------------------------------------
00056 ## @brief Print synopsis, i.e., usage section.
00057 function print_synopsis
00058 {
00059     cat - << EOF-SYNOPSIS
00060 Usage:
00061   ${_EXEC_NAME} [<cmd>] [options] [options of subcommand]
00062   ${_EXEC_NAME} help <cmd>
00063 EOF-SYNOPSIS
00064 }
00065 
00066 # ----------------------------------------------------------------------------
00067 ## @brief Print options.
00068 function print_options
00069 {
00070     cat - << EOF-OPTIONS
00071 Optional arguments:
00072   <cmd>         Recognized subcommands are cron, master, slave, and svn. (default: slave)
00073   -h, --help    Print help and exit
00074   --helpshort   Print short help and exit.
00075 EOF-OPTIONS
00076 }
00077 
00078 # ============================================================================
00079 # options
00080 # ============================================================================
00081 
00082 cmd='slave' # subcommand to run
00083 verbose=0   # verbosity of output messages
00084 
00085 if [ -n "$1" ]; then
00086     if match "$1" '^(cron|master|slave|svn)$'; then
00087         cmd="$1"
00088         shift
00089     elif [ "$1" == "help" ]; then
00090         if [ -n "$2" ]; then
00091             if match "$2" '^(cron|master|slave|svn)$'; then
00092                 cmd="$2"
00093                 shift
00094             else
00095                 echo "Unknown command: $2" 1>&2
00096                 exit 1
00097             fi
00098         else
00099             echo "Missing subcommand! See ${_EXEC_NAME} --help." 1>&2
00100             exit 1
00101         fi
00102         execute "basistest-${cmd}" '--help'
00103         exit $?
00104     elif [ "$1" == "--help" ] || [ "$1" == "-h" ]; then
00105         print_help
00106         exit 0
00107     elif [ "$1" == "--helpshort" ]; then
00108         print_helpshort
00109         exit 0
00110     elif [ "$1" == "--version" ]; then
00111         print_version ''
00112         exit 0
00113     fi
00114 fi
00115 
00116 # ============================================================================
00117 # main
00118 # ============================================================================
00119 
00120 [ -n "${cmd}" ] || { echo "Missing subcommand! See ${_EXEC_NAME} --help."; exit 1; }
00121 execute "basistest-${cmd}" "$@"