Commit ae448134 by Eric Coissac

Merge both version of lecaluke.sh

parents d69e224e f30d5d0b
Pipeline #4 skipped
This diff is collapsed. Click to expand it.
# 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 atexit package"
include stacks
newstack __LECABASHLIB_ATEXITSTACK__
function __atexit__manager__() {
echo coucou
while popvalue __LECABASHLIB_ATEXITSTACK__ cmd ; do
eval "$cmd"
done
}
function registeratexit() {
pushvalue __LECABASHLIB_ATEXITSTACK__ "${*}"
}
trap "__atexit__manager__" EXIT ERR
......@@ -55,7 +55,9 @@ if onluke; then
}
else
logwarning Script is not running on the LUKE cluster
if onfroggy ; then
logdebug Script run on the FROGGY cluster
# Register scratch_dir as place where to create temp directory
......
# 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 tempdir package"
include ifs
include stacks
include atexit
newstack __LECABASHLIB_BASETMPDIRSTACK__
newstack __LECABASHLIB_TMPDIRSTACK__
__LECABASHLIB_TMPBASENAME__="__tmp__$(whoami).${$}__lecabashlib__.XXXXX"
function __remove_tmp__() {
echo "@@${__LECABASHLIB_TMPDIRSTACK__[@]}@@"
while popvalue __LECABASHLIB_TMPDIRSTACK__ directory ; do
echo coucou tmp
loginfo "Removing tempdir : $directory"
rm -rf "$directory"
done
}
registeratexit __remove_tmp__
function availabledisk() {
local FILENAME="${1}"
pushifs $'\n'
local lines=( $(df -k -P "${FILENAME}") )
pushifs ' '
local fields=(${lines[0]})
local values=(${lines[1]})
popifs
popifs
nfield=${#fields[@]}
i=0
while (( i < nfield )) && [[ "$(lower ${fields[$i]})" != "available" ]] ; do
i=$(( i + 1 ))
done
if (( i < nfield )) ; then
size=$(( values[i] / 1024 / 1024 ))
echo $size
return 0
else
return 1
fi
}
function registertmpdir() {
pushvalue __LECABASHLIB_BASETMPDIRSTACK__ "${1}"
}
function tempdirectory() {
local minsize="0"
if [[ ! -z "${1}" ]]; then
COMMAND="${1}="
else
COMMAND="echo "
fi
shift
if [[ "$(stacksize __LECABASHLIB_BASETMPDIRSTACK__)" == "0" ]]; then
if [[ ! -z "$TMPDIR" ]] ; then
registertmpdir "$TMPDIR"
else
mkdir -p "$HOME/tmp"
registertmpdir "$HOME/tmp"
fi
fi
if [[ ! -z "${1}" ]] ; then
minsize="${1}"
fi
local nbase=$(stacksize __LECABASHLIB_BASETMPDIRSTACK__)
local i=0
while (( i < nbase )) && \
(( $(availabledisk "${__LECABASHLIB_BASETMPDIRSTACK__[$i]}") < minsize )) ; do
i=$(( i + 1 ))
done
if (( i >= nbase )) ; then
return 1
fi
local basedir="${__LECABASHLIB_BASETMPDIRSTACK__[$i]}"
local directory=$(mktemp -d "${basedir%/}/${__LECABASHLIB_TMPBASENAME__}")
pushvalue __LECABASHLIB_TMPDIRSTACK__ "$directory"
local valcmd="${COMMAND}${directoty}"
eval $valcmd
}
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