BASIS  version 1.2.3 (revision 2104)
basistest-svn.sh
Go to the documentation of this file.
00001 #! /bin/bash
00002 ##############################################################################
00003 # @file  basistest-svn.sh
00004 # @brief Wrapper script for Subversion svn command.
00005 #
00006 # This script is used as wrapper for the svn command to enable automated
00007 # software testing at our lab. In general, anonymous access to the Subversion
00008 # repositories is not permitted. Only the svnuser is allowed to do so.
00009 # Hence, a wrapper script was implemented which is only readable by the
00010 # svnuser where the password is hard code. Moreover, only the svnuser can
00011 # execute this script. The swtest user on the other side is allowed to run
00012 # this script as svnuser via sudoers list.
00013 #
00014 # Copyright (c) 2011 University of Pennsylvania. All rights reserved.<br />
00015 # See https://www.cbica.upenn.edu/sbia/software/license.html or COPYING file.
00016 #
00017 # Contact: SBIA Group <sbia-software at uphs.upenn.edu>
00018 # @ingroup Tools
00019 ##############################################################################
00020 
00021 
00022 # constants used by the shflags.sh module
00023 HELP_COMMAND='basistest-svn (BASIS)'
00024 HELP_CONTACT='SBIA Group <sbia-software at uphs.upenn.edu>'
00025 HELP_VERSION='version 1.2.3 (revision 2104)'
00026 HELP_COPYRIGHT='Copyright (c) University of Pennsylvania. All rights reserved.
00027 See https://www.rad.upenn.edu/sbia/software/license.html or COPYING file.'
00028 
00029 
00030 # ----------------------------------------------------------------------------
00031 ## @brief Get real path of given file or directory.
00032 #
00033 # @note This function was substituted by BASIS either for the string
00034 #       \@BASIS_BASH_UTILITIES\@ or \@BASIS_BASH_FUNCTION_realpath\@.
00035 #
00036 # Example:
00037 # @code
00038 # exec_dir=`realpath $0`
00039 # @endcode
00040 #
00041 # @param [in] path File or directory path.
00042 #
00043 # @returns Canonical path.
00044 #
00045 # @sa http://stackoverflow.com/questions/7665/how-to-resolve-symbolic-links-in-a-shell-script
00046 function realpath
00047 {
00048     local path=$1
00049 
00050     local linkdir=''
00051     local symlink=''
00052 
00053     while [ -h ${path} ]; do
00054         # 1) change to directory of the symbolic link
00055         # 2) change to directory where the symbolic link points to
00056         # 3) get the current working directory
00057         # 4) append the basename
00058         linkdir=$(dirname -- "${path}")
00059         symlink=$(readlink ${path})
00060         path=$(cd "${linkdir}" && cd $(dirname -- "${symlink}") && pwd)/$(basename -- "${symlink}")
00061     done
00062 
00063     echo -n "$(cd -P -- "$(dirname "${path}")" && pwd -P)/$(basename -- "${path}")"
00064 }
00065 
00066 readonly _SBIA_BASIS_BASISTEST_SVN_DIR="$(dirname -- "$(realpath "$(cd -P -- "$(dirname -- "${BASH_SOURCE}")" && pwd -P)/$(basename -- "$BASH_SOURCE")")")"
00067 source "${_SBIA_BASIS_BASISTEST_SVN_DIR}/../lib/basis.sh" || exit 1
00068 
00069 
00070 args=()
00071 verbose=0
00072 
00073 while [ $# -gt 0 ]; do
00074     case "$1" in
00075         --verbose|-v)
00076             (( verbose++ ))
00077             ;;
00078 
00079         --help|-h)
00080             get_executable_name exec_name
00081             echo "Usage:"
00082             echo "  ${exec_name} [svn options/arguments]"
00083             echo "  ${exec_name} [options]"
00084             echo
00085             echo "Description:"
00086             echo "  This command is used as a wrapper for the svn command to enable"
00087             echo "  automated software testing at SBIA where anonymous Subversion"
00088             echo "  access is generally not permitted."
00089             echo
00090             echo "Options:"
00091             echo "  --help, -h    Print help and exit."
00092             echo "  --helpshort   Print short help and exit."
00093             echo "  --version     Print version information and exit."
00094             echo
00095             print_contact
00096             exit 0
00097             ;;
00098 
00099         --helpshort)
00100             get_executable_name exec_name
00101             echo "Usage:"
00102             echo "  ${exec_name} [svn options/arguments]"
00103             echo "  ${exec_name} [options]"
00104             echo
00105             echo "Options:"
00106             echo "  --help, -h    Print help and exit."
00107             echo "  --helpshort   Print short help and exit."
00108             echo "  --version     Print version information and exit."
00109             echo
00110             print_contact
00111             exit 0
00112             ;;
00113 
00114         --version)
00115             print_version 'basistest-svn'
00116             exit 0
00117             ;;
00118         *)
00119             args=("${args[@]}" "$1")
00120             ;;
00121     esac
00122     shift
00123 done
00124 
00125 # simply call the wrapper script with the password encoded as svnuser
00126 cmd=(sudo -u svnuser /bin/sh /sbia/home/svn/bin/svnwrap "${args[@]}")
00127 if [ $verbose -gt 0 ]; then
00128     echo "$ ${cmd[@]}"
00129 fi
00130 exec "${cmd[@]}"