Commit 8b490c0e authored by Bogdan Vacaliuc's avatar Bogdan Vacaliuc
Browse files

perform environment injection after base parameters

- I suspect this will be more clear to the reviewers as they will see
  familiar boilerplate at the top of the script
parent 8da81e1c
Loading
Loading
Loading
Loading
Loading
+27 −27
Original line number Diff line number Diff line
@@ -6,33 +6,6 @@ _usage() {
    fi
}

# overwrite these values with environment injection e.g.
# TMP=path-to-text-file			- default a file from mktemp
# PIXI_PREFIX=path-to-parent-folder	- default /usr/local/pixi
# PROFILE_ENV=mantid			- default mantid_dev (needs to have mantidprofiler module)
# PROFILE_OUT=path-to-html-file		- default ./profile.html
# -or-
# PROFILE_OPT="--outfile path-to-html --logfile path-to-txt ..."

TMP="${TMP:=$(mktemp)}"
PIXI_PREFIX="${PIXI_PREFIX:=/usr/local/pixi}"
PROFILE_ENV="${PROFILE_ENV:=mantid_dev}"
PROFILE_OUT="${PROFILE_OUT:=}"
# ensure PROFILE_OUT is a path-to-html-file, and PROFILE_OPT is an array
if [ -z "${PROFILE_OUT}" ] ; then
    read -r -a PROFILE_OPT <<< "${PROFILE_OPT//[\(\)]/}"
    # https://superuser.com/a/1732848
    # shellcheck disable=SC2199 # use implicit concatenation
    # shellcheck disable=SC2076 # rhs quoted syntax is correct
    if [[ "${PROFILE_OPT[@]}" =~ "--outfile ([^ ]+) " ]]; then
        PROFILE_OUT="${BASH_REMATCH[1]}"
    else
        PROFILE_OUT="$(pwd)/profile.html"
    fi
else
    PROFILE_OPT=("--outfile ${PROFILE_OUT}")
fi

# select the environment to use
ENV=
if [ -n "$1" ]; then
@@ -76,6 +49,33 @@ if [ -z "$CMD" ] ; then
    exit 255
fi

# overwrite these values with environment injection e.g.
# TMP=path-to-text-file			- default a file from mktemp
# PIXI_PREFIX=path-to-parent-folder	- default /usr/local/pixi
# PROFILE_ENV=mantid			- default mantid_dev (needs to have mantidprofiler module)
# PROFILE_OUT=path-to-html-file		- default ./profile.html
# -or-
# PROFILE_OPT="--outfile path-to-html --logfile path-to-txt ..."

TMP="${TMP:=$(mktemp)}"
PIXI_PREFIX="${PIXI_PREFIX:=/usr/local/pixi}"
PROFILE_ENV="${PROFILE_ENV:=mantid_dev}"
PROFILE_OUT="${PROFILE_OUT:=}"
# ensure PROFILE_OUT is a path-to-html-file, and PROFILE_OPT is an array
if [ -z "${PROFILE_OUT}" ] ; then
    read -r -a PROFILE_OPT <<< "${PROFILE_OPT//[\(\)]/}"
    # https://superuser.com/a/1732848
    # shellcheck disable=SC2199 # use implicit concatenation
    # shellcheck disable=SC2076 # rhs quoted syntax is correct
    if [[ "${PROFILE_OPT[@]}" =~ "--outfile ([^ ]+) " ]]; then
        PROFILE_OUT="${BASH_REMATCH[1]}"
    else
        PROFILE_OUT="$(pwd)/profile.html"
    fi
else
    PROFILE_OPT=("--outfile ${PROFILE_OUT}")
fi

# execute main app in background
nsd-conda-wrap.sh "${ENV}" --classic "${CMD}" "$@" > "${TMP}" & pid=$!
echo "Writing script output to ${TMP}"