diff --git a/scripts/ingest-tarball.sh b/scripts/ingest-tarball.sh index d71ff733..9b008199 100755 --- a/scripts/ingest-tarball.sh +++ b/scripts/ingest-tarball.sh @@ -168,6 +168,23 @@ function check_arch() { fi } +function update_lmod_caches() { + # Update the Lmod caches for the stacks of all supported CPUs + script_dir=$(dirname $(realpath $BASH_SOURCE)) + update_caches_script=${script_dir}/update_lmod_caches.sh + if [ ! -f ${update_caches_script} ] + then + error "cannot find the script for updating the Lmod caches; it should be placed in the same directory as the ingestion script!" + fi + if [ ! -x ${update_caches_script} ] + then + error "the script for updating the Lmod caches (${update_caches_script}) does not have execute permissions!" + fi + cvmfs_server transaction "${repo}" + ${update_caches_script} /cvmfs/${repo}/${basedir}/${version} + cvmfs_server publish -m "update Lmod caches after ingesting ${tar_file_basename}" "${repo}" +} + function ingest_init_tarball() { # Handle the ingestion of tarballs containing init scripts cvmfs_ingest_tarball @@ -183,6 +200,7 @@ function ingest_software_tarball() { check_arch check_os cvmfs_ingest_tarball + update_lmod_caches } function ingest_compat_tarball() { diff --git a/scripts/update_lmod_caches.sh b/scripts/update_lmod_caches.sh new file mode 100755 index 00000000..f1765f0c --- /dev/null +++ b/scripts/update_lmod_caches.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +function echo_green() { + echo -e "\e[32m$1\e[0m" +} + +function echo_red() { + echo -e "\e[31m$1\e[0m" +} + +function error() { + echo_red "ERROR: $1" >&2 + exit 1 +} + +# Check if a stack base dir has been specified +if [ "$#" -ne 1 ]; then + error "usage: $0 " +fi + +stack_base_dir="$1" + +# Check if the given stack base dir exists +if [ ! -d ${stack_base_dir} ] +then + error "${stack_base_dir} does not point to an existing directory!" +fi + +# Check if Lmod's cache update script can be found at the expected location (in the compatibility layer of the given stack) +update_lmod_system_cache_files="${stack_base_dir}/compat/linux/$(uname -m)/usr/share/Lmod/libexec/update_lmod_system_cache_files" +if [ ! -f ${update_lmod_system_cache_files} ] +then + error "expected to find Lmod's cache update script at ${update_lmod_system_cache_files}, but it doesn't exist." +fi + +# Find all subtrees of supported CPU targets by looking for "modules" directories, and taking their parent directory +architectures=$(find ${stack_base_dir}/software/ -maxdepth 5 -type d -name modules -exec dirname {} \;) + +# Create/update the Lmod cache for all architectures +for archdir in ${architectures} +do + lmod_cache_dir="${archdir}/.lmod/cache" + ${update_lmod_system_cache_files} -d ${lmod_cache_dir} -t ${lmod_cache_dir}/timestamp ${archdir}/modules/all + exit_code=$? + if [[ ${exit_code} -eq 0 ]]; then + echo_green "Updated the Lmod cache for ${archdir}." + ls -lrt ${lmod_cache_dir} + else + echo_red "Updating the Lmod cache failed for ${archdir}." + exit ${exit_code} + fi +done