Commit 30ef5f77 by Eric Coissac

Wrapper functions to deal with iRods

parent ae448134
# LECA Bash library
#
# The LECA bash library provides a set of function used for helping
# development of bash script mainly to write job script on the luke
# cluster
#
# The files from the LECA Bash library must be sourced from your main script
#
#
include logging
logdebug "Load irods package"
LECABASHLIB_MAXTRIAL="5"
#
# Look for the iRods commands on the system
#
if ! which iget 2>&1 > /dev/null ; then
if module 2> /dev/null ; then
module load irods
fi
fi
if ! which iget 2>&1 > /dev/null ; then
logerror "No iRods commands available"
fi
#
# Switch between the secure and the none secure iCommands
#
# --> if the bash function secure_iget is define we use it
# otherwise we use the classical iget
#
if type secure_iget 1> /dev/null; then
LECABASHLIB_IGET="secure_iget"
else
LECABASHLIB_IGET="iget"
fi
#
# Same thing for iput
#
if type secure_iput 1> /dev/null; then
LECABASHLIB_IPUT="secure_iput"
else
LECABASHLIB_IPUT="iput"
fi
#
# Checks between md5sum and md5 is the command to run
# for computing a MD5 checksum
#
if ! which md5 2>&1 > /dev/null ; then
if ! which md5sum 2>&1 > /dev/null ; then
logerror "No md5 commands available"
else
LECABASHLIB_MD5SUM=md5sum
fi
else
LECABASHLIB_MD5SUM=md5
fi
#
# isetresource :
#
function isetresource() {
if [[ ! -z "${1}" ]]; then
local IRESOURCE="${1}"
LECABASHLIB_IPUT="iput -R ${IRESOURCE}"
else
if type secure_iput 1> /dev/null; then
LECABASHLIB_IPUT="secure_iput"
else
LECABASHLIB_IPUT="iput"
fi
fi
}
function isetmaxtrial() {
if [[ ! -z "${1}" ]]; then
LECABASHLIB_MAXTRIAL=$(( $1 + 0 ))
if (( LECABASHLIB_MAXTRIAL )) ; then
logwarning "Max trails set to a no-sens value reset to 5"
LECABASHLIB_MAXTRIAL="5"
fi
else
LECABASHLIB_MAXTRIAL="5"
fi
}
function iresourceexists() {
local rep=1
ils $1 2> /dev/null >/dev/null
if (( $? == 0 )) ; then
rep=0
fi
return $rep
}
function igetwithmd5() {
local SOURCE=$1
shift
if [[ ! -z "${1}" ]]; then
local TARGET=$1
else
local TARGET=""
fi
if ! iresourceexists "$SOURCE" ; then
logerror "The requested iRods resource does not exit : $SOURCE"
return 1
fi
local TRIAL=0
local LMD5="XXXXXX"
local IMD5="YYYYYY"
local IROD_STATUS=1
while [[ "${LMD5}" != "${IMD5}" ]] && (($TRIAL < $LECABASHLIB_MAXTRIAL)); do
TRIAL=$((TRIAL+1))
"${LECABASHLIB_IGET}" "${SOURCE}" "${TARGET}"
HAS_MD5=0
"${LECABASHLIB_IGET}" "${SOURCE}.md5" "${TARGET}.md5" && HAS_MD5=1
if (( "${HAS_MD5}"=="1" ))
then
LMD5=$(${LECABASHLIB_MD5SUM} ${TARGET} | awk '{print $1}')
IMD5=$(cat ${TARGET}.md5 | awk '{print $1}')
else
logwarning "no MD5 available on iRods"
IMD5="NO-MD5"
LMD5="NO-MD5"
fi
if [[ "${LMD5}" != "${IMD5}" ]] && (($TRIAL < $LECABASHLIB_MAXTRIAL)); then
logwarning "MD5 doesn't match; re-load file from iRods"
fi
done
rm -f "${TARGET}.md5"
if [[ "${LMD5}" != "${IMD5}" ]]; then
logerror "MD5 doesn't match; re-load file from iRods"
return 1
fi
return 0
}
function iputwithmd5() {
echo Not yet implemented
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment