Commit f581949d by Eric Coissac

Add the possibility to define an environment variable LECABASHLIB_PATH

to indicate other directory where modules can be stored
parent 6dad27d4
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
if [[ -z "${LECALIB_UTIL_SH}" ]]; then if [[ -z "${LECALIB_UTIL_SH}" ]]; then
LECALIB_UTIL_SH=1 LECALIB_UTIL_SH=1
LECABASHLIB_RELOADING=0 LECABASHLIB_RELOADING=0
if [[ -z "$LECABASHLIB_PATH" ]] ; then
export LECABASHLIB_PATH=""
fi
THIS_DIR="$(dirname ${BASH_SOURCE[0]})" THIS_DIR="$(dirname ${BASH_SOURCE[0]})"
...@@ -40,12 +44,37 @@ if [[ -z "${LECALIB_UTIL_SH}" ]]; then ...@@ -40,12 +44,37 @@ if [[ -z "${LECALIB_UTIL_SH}" ]]; then
local MODULE=$(upper $1) local MODULE=$(upper $1)
local LOADED_MODULE_VAR="LECALIB_${MODULE}_SH" local LOADED_MODULE_VAR="LECALIB_${MODULE}_SH"
local LOADED_MODULE=$(indirect $LOADED_MODULE_VAR) local LOADED_MODULE=$(indirect $LOADED_MODULE_VAR)
if [[ -z "${LOADED_MODULE}" || "$LECABASHLIB_RELOADING" == 1 ]]; then local found=""
for path in $(echo $LECABASHLIB_PATH | sed 's/:/ /g') ; do
if [[ -z "$found" && \
( -z "${LOADED_MODULE}" || \
"$LECABASHLIB_RELOADING" == 1 ) && \
-f "${path}/${1}.sh" ]] ; then
source "${path}/${1}.sh"
eval $LOADED_MODULE_VAR=1
found=1
fi
done
if [[ -z "$found" && \
( -z "${LOADED_MODULE}" || \
"$LECABASHLIB_RELOADING" == 1 ) && \
-f "${LECALIB_DIR}/${1}.sh" ]] ; then
source "${LECALIB_DIR}/${1}.sh" source "${LECALIB_DIR}/${1}.sh"
eval $LOADED_MODULE_VAR=1 eval $LOADED_MODULE_VAR=1
found=1
fi
if (( found == 1 )) ; then
if (( LECABASHLIB_RELOADING == 1 )) ; then if (( LECABASHLIB_RELOADING == 1 )) ; then
loginfo "Module $1 reloaded..." logdebug "Module $1 reloaded..."
else
logdebug "Module $1 loaded..."
fi fi
else
if [[ -z "${LOADED_MODULE}" ]] ; then
logerror "Cannot load module $1"
fi
fi fi
} }
...@@ -72,5 +101,7 @@ if [[ -z "${LECALIB_UTIL_SH}" ]]; then ...@@ -72,5 +101,7 @@ if [[ -z "${LECALIB_UTIL_SH}" ]]; then
command popd "$@" > /dev/null command popd "$@" > /dev/null
} }
include logging
fi fi
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