moved most of the BASH initialisation from config/profile.bash to init/bash

This commit is contained in:
2018-07-11 10:18:26 +02:00
parent 0e23b71f92
commit f40491b5e3
2 changed files with 25 additions and 32 deletions
+18 -8
View File
@@ -5,7 +5,7 @@
# #
if [ ${BASH_VERSINFO:-0} -lt 3 ]; then if [ ${BASH_VERSINFO:-0} -lt 3 ]; then
echo "BASH version ${BASH_VERSION} ist not supported! You need at least version 3..." echo "BASH version ${BASH_VERSION} ist not supported! You need at least version 3..."
return return 1
fi fi
############################################################################# #############################################################################
@@ -60,12 +60,12 @@ export -f module
# helper functions # helper functions
# #
std::append_path () { std::append_path () {
local -r P=$1 local -r P="$1"
local -r d=$2 local -r d="$2"
if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then if ! echo ${!P} | egrep -q "(^|:)${d}($|:)" ; then
if [[ -z ${!P} ]]; then if [[ -z ${!P} ]]; then
eval $P=${d} eval $P="${d}"
else else
eval $P="${!P}:${d}" eval $P="${!P}:${d}"
fi fi
@@ -90,9 +90,9 @@ std::append_path () {
# https://stackoverflow.com/questions/273909/how-do-i-manipulate-path-elements-in-shell-scripts # https://stackoverflow.com/questions/273909/how-do-i-manipulate-path-elements-in-shell-scripts
# #
std::replace_path () { std::replace_path () {
local -r path=$1 local -r path="$1"
local -r removepat=$2 local -r removepat="$2"
local -r replacestr=$3 local -r replacestr="$3"
local -r removestr=$(echo "${!path}" | tr ":" "\n" | grep -m 1 "^$removepat\$") local -r removestr=$(echo "${!path}" | tr ":" "\n" | grep -m 1 "^$removepat\$")
export $path=$(echo "${!path}" | tr ":" "\n" | sed "s:^${removestr}\$:${replacestr}:" | export $path=$(echo "${!path}" | tr ":" "\n" | sed "s:^${removestr}\$:${replacestr}:" |
@@ -108,7 +108,17 @@ save_env() {
echo export PMODULES_ENV=$( "${PMODULES_HOME}/sbin/base64" --wrap=0 <<< "$s" ) echo export PMODULES_ENV=$( "${PMODULES_HOME}/sbin/base64" --wrap=0 <<< "$s" )
} }
#module purge ############################################################################
# some sanity checks
#
if [[ ! -d ${PMODULES_ROOT} ]]; then
echo "Oops: ${PMODULES_ROOT}: Set as Pmodules root, but this is not a directory." 1>&2
return 1
fi
if [[ ! -d ${PMODULES_HOME} ]]; then
echo "Oops: ${PMODULES_HOME}: Set as Pmodules home, but this is not a directory." 1>&2
return 1
fi
############################################################################# #############################################################################
# setup environment # setup environment
+7 -24
View File
@@ -7,10 +7,6 @@
# ${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION} # ${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}
# #
declare -x PMODULES_DEFAULT_GROUPS
declare -x PMODULES_DEFAULT_RELEASES
declare -x PMODULES_VERSION
: ${PMODULES_DEFAULT_GROUPS:='Tools Programming'} : ${PMODULES_DEFAULT_GROUPS:='Tools Programming'}
: ${PMODULES_DEFAULT_RELEASES:='stable'} : ${PMODULES_DEFAULT_RELEASES:='stable'}
: ${PMODULES_VERSION:=@PMODULES_VERSION@} : ${PMODULES_VERSION:=@PMODULES_VERSION@}
@@ -19,6 +15,10 @@ declare -x PMODULES_VERSION
# N O C H A N G E S B E L O W T H I S L I N E ! # # N O C H A N G E S B E L O W T H I S L I N E ! #
############################################################################# #############################################################################
export PMODULES_DEFAULT_GROUPS
export PMODULES_DEFAULT_RELEASES
export PMODULES_VERSION
declare -x PMODULES_MODULEFILES_DIR='modulefiles' declare -x PMODULES_MODULEFILES_DIR='modulefiles'
declare -x PMODULES_DEFINED_RELEASES=':unstable:stable:deprecated:' declare -x PMODULES_DEFINED_RELEASES=':unstable:stable:deprecated:'
@@ -27,29 +27,12 @@ declare -x PMODULES_CONFIG_DIR=$(basename $(cd $(dirname "${BASH_SOURCE}") && pw
declare -x PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}" declare -x PMODULES_HOME="${PMODULES_ROOT}/Tools/Pmodules/${PMODULES_VERSION}"
declare -x PMODULES_DIR="${PMODULES_HOME}" declare -x PMODULES_DIR="${PMODULES_HOME}"
############################################################################ test -r "${PMODULES_HOME}/init/bash" && source "$_"
# some sanity checks
#
if [[ ! -d ${PMODULES_ROOT} ]]; then
echo "Oops: ${PMODULES_ROOT}: Set as Pmodules root, but this is not a directory." 1>&2
return 1
fi
if [[ ! -d ${PMODULES_HOME} ]]; then
echo "Oops: ${PMODULES_HOME}: Set as Pmodules home, but this is not a directory." 1>&2
return 1
fi
############################################################################ if [[ $? != 0 ]]; then
# inititialize Pmodules for bash echo "Oops: cannot initialize Pmodules!"
#
_init_bash="${PMODULES_HOME}/init/bash"
if [[ ! -r "${_init_bash}" ]]; then
echo "Oops: cannot initialize Modules!"
echo "${_init_bash}: File does not exist or is not readable."
return 1 return 1
fi fi
source "${_init_bash}"
unset _init_bash
# Local Variables: # Local Variables:
# mode: sh # mode: sh