Skip to content
Snippets Groups Projects
Select Git revision
  • bc8e3271f8fee1f53ad3f0f7aeb27787a3d3bc06
  • master default protected
  • dev protected
  • spack-compatible-0.23.1
  • dedal-py-39
  • ECM_testing
  • VT-109-restructure-spack
  • VT-87-Enabling-coverage-report-for-the-dedal-respository
  • VT-70-function-Migrate-Spack-env-setup-into-ESD-repo-with-buildcache
  • koutakia protected
  • oci_cache
  • image_testing
  • ebrains_testing
  • Dedal@1.0.0
  • Dedal@0.9.1
  • Dedal@0.9.0
16 results

generate_modules.sh

Blame
  • Philipp Spilger's avatar
    Philipp Spilger authored
    * allows easy checking of working relative locations without actual install
    
    Change-Id: Ib7d01b7e4be522edaa683eefa854a1bb1ce35560
    bc8e3271
    History
    generate_modules.sh 1.50 KiB
    #!/bin/bash
    
    set -euo pipefail
    shopt -s inherit_errexit 2>/dev/null || true
    
    # This script searches the environment-modules install folder for the init
    # folder which contains the init scripts for a variety of shells.
    # Unfortunately the location of the init folder changed between versions 3.x
    # and 4.x which is why we now "find" it.
    
    TARGET="/opt/init/modules.sh"
    PATH_SOURCE="$(readlink -m "${BASH_SOURCE[0]}")"
    
    MODULESHOME="$(/opt/spack/bin/spack location -i environment-modules)"
    PATH_MODULES="$(find "${MODULESHOME}" -type d -path "*init" | head -n 1)"
    
    cat <<EOF > "${TARGET}"
    #!/bin/bash
    
    EOF
    
    cat <<EOF | tr '\n' ' ' | fold -w 78 -s | sed "s:^:# :g" >> "${TARGET}"
    This script has been generated on $(date) via ${PATH_SOURCE} by searching
    the environment-modules install folder for the init folder which contains the
    init scripts for a variety of shells. It can be regenerated by running
    ${PATH_SOURCE} again.
    EOF
    
    (echo; echo) >> "${TARGET}"
    
    cat <<EOF >> "${TARGET}"
    source "${PATH_MODULES}/\$(readlink -f /proc/\$\$/exe | xargs -r basename)"
    EOF
    
    # Provide MODULESHOME for all singularity environments
    cat <<EOF >> ${SINGULARITY_ENVIRONMENT}
    MODULESHOME=${MODULESHOME}
    export MODULESHOME
    EOF
    
    # ensure that the directories with spack-generated module files are available
    # to use after sourcing /opt/init/modules.sh
    (
    IFS=$'\n'
    for moduledir in $(find /opt/spack/share/spack/modules -mindepth 1 -maxdepth 1 -type d); do
    cat <<EOF >> "${TARGET}"
    export MODULEPATH="${moduledir}\${MODULEPATH:+:\${MODULEPATH}}"
    EOF
    done
    )