utils.sh 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# 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
#
#


if [[ -z "${LECALIB_UTIL_SH}" ]]; then
	LECALIB_UTIL_SH=1

	THIS_DIR="$(dirname ${BASH_SOURCE[0]})"

17 18 19 20 21 22 23 24
    source "${THIS_DIR}/utils.sh"

	function abspath() {
		local P=$1
		echo "$(cd "$(dirname "${P}")" && pwd -P)/$(basename "${P}")"
	}

	LECALIB_DIR=$(abspath "${THIS_DIR}")
25 26 27 28 29 30

	function upper() {
		echo $1 | tr "a-z" "A-Z"
	}

	function lower() {
31
		echo $1 | tr "A-Z" "a-z"
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
	}

	function indirect() {
		eval echo \$${1}
	}

  function include() {
		local MODULE=$(upper $1)
		local LOADED_MODULE_VAR="LECALIB_${MODULE}_SH"
		local LOADED_MODULE=$(indirect $LOADED_MODULE_VAR)
		if [[ -z "${LOADED_MODULE}" ]]; then
			source "${LECALIB_DIR}/${1}.sh"
			eval $LOADED_MODULE_VAR=1
		fi
	}

	function onluke() {
		[[ $(hostname | sed -E 's/^(....).*$/\1/') == "luke" ]]
	}

	function onfroggy() {
Eric Coissac committed
53
		[[ $(hostname | sed -E 's/^(....).*$/\1/') == "frog" ]]
54 55 56
	}

fi