Add script which creates env setup script

This commit is contained in:
Jose Gracia 2024-06-03 17:08:32 +02:00
parent dd3b779fd9
commit b542575d3b

View file

@ -0,0 +1,78 @@
#!/bin/bash
#
# Creates a script which can be used to source the environment variables
# for a release in <base_prefix>/release/<release_tag> tagged as <release_tag>.
#
# Input arguments:
# - release_tag: tag/branch/commit in repo
# - base_prefix: prefix to base directory for softweare installation; e.g. /opt/hlrs
#
_VERBOSITY=1
if [[ "$#" -ne 2 ]]; then
echo "Syntax: $0 release_tag base_prefix"
echo "Creates a script which can be used to source the environment variables "
echo "for a release in <base_prefix>/release/<release_tag> tagged as <release_tag>."
exit 1
fi
arg_tag=$1
arg_prefix=$2
log () {
local msg=$1
if [[ -n $_VERBOSITY ]]; then
echo $msg
fi
}
# modify tag by stripping "hlrs-release-" prefix
canonize_tag () {
echo ${1##hlrs-release-}
}
# create and prepare destination directory
# or return existing directory
create_dir () {
local dir=$1
local rc
if [[ -d $dir ]]; then
rc=$dir
else
mkdir -p $dir
chmod g=u $dir
rc=$dir
fi
echo $rc
}
# process input arguments
HLRS_SOFTWARE_STACK_RELEASE_VERSION__USER=$(canonize_tag $arg_tag)
HLRS_OPT_PREFIX__USER=$(create_dir $arg_prefix)
# Define various repo locations
_HLRS_SPACK_REPO=file://$HOME/spack-test/dummy_repo/spack-v0.21.2.git
_HLRS_SPACK_PLUMBING_REPO=file://$HOME/spack-test/dummy_repo/software-stack-plumbing.git
_HLRS_SPACK_CONFIG_REPO=
# bootstrap environment variables
# (using [bash process substitution](https://tldp.org/LDP/abs/html/process-sub.html))
source <(curl $_HLRS_SPACK_PLUMBING_REPO/hlrs-plumbing/envs/00_base_prefix.env)
source <(curl $_HLRS_SPACK_PLUMBING_REPO/hlrs-plumbing/envs/01_release_root.env)
source <(curl $_HLRS_SPACK_PLUMBING_REPO/hlrs-plumbing/envs/02_hlrs_spack_root.env)
# destination for output script
destination=$HLRS_SOFTWARE_STACK_RELEASE_ROOT/setup-release-variables.env
# write environment variables to file for sourcing
echo "# Setup environment variables for the release" > $destination
echo "#" >> $destination
echo "" >> $destination
echo "export HLRS_SOFTWARE_STACK_HLRS_SPACK_ROOT=${HLRS_SOFTWARE_STACK_HLRS_SPACK_ROOT}" >> $destination
echo "export HLRS_SOFTWARE_STACK_SPACK_INSTALL_TREE=${HLRS_SOFTWARE_STACK_SPACK_INSTALL_TREE}" >> $destination
echo "export HLRS_SOFTWARE_STACK_RELEASE_VERSION=${HLRS_SOFTWARE_STACK_RELEASE_VERSION}" >> $destination
echo "export HLRS_SOFTWARE_STACK_RELEASE_ROOT=${HLRS_SOFTWARE_STACK_RELEASE_ROOT}" >> $destination