spack/run-find-external.sh.in
2023-03-24 08:30:29 +00:00

86 lines
2.5 KiB
Bash

#!/bin/bash
scope=system
what=$1
addpath() {
path=$1
shift
while [ -n "$1" ]; do
eval "${path}"=${1}:${!path}
shift
done
}
find_packages() {
if [ $scope = user ]; then
test -e /etc/spack/packages.yaml && mv /etc/spack/packages.yaml /etc/spack/packages.yaml.old
# drop all root rights, when calling external find
sudo -u nobody PATH=${mypath}:${PATH} spack external find --scope user --all #--exclude 'installdbgsymbols'
if [ -e /var/lib/nobody/.spack/packages.yaml ] ; then
mv -v /var/lib/nobody/.spack/packages.yaml /etc/spack/packages.yaml
chown root:root /etc/spack/packages.yaml
fi
rm -r /var/lib/nobody/.spack
else
# May run in a container...
PATH=${mypath}:${PATH} spack external find --scope system --all #--exclude 'installdbgsymbols'
fi
}
find_compilers() {
if [ $scope = user ]; then
test -e /etc/spack/compilers.yaml && mv /etc/spack/compilers.yaml /etc/spack/compilers.yaml.old
# drop all root rights, when calling external find
sudo -u nobody PATH=${cpath}:${PATH} spack compiler find --scope user
if [ -e /var/lib/nobody/.spack/compilers.yaml ] ; then
mv -v /var/lib/nobody/.spack/compilers.yaml /etc/spack/compilers.yaml
chown root:root /etc/spack/compilers.yaml
fi
else
# May run in a container...
PATH=${cpath}:${PATH} spack compiler find --scope system
fi
}
if [ -e /etc/spack/no_rpm_trigger ] ; then
exit 0
fi
if [ "x$(id -u)" != "x0" ] ; then
echo "Must run as root, in order to copy back the configuration files and use sudo"
exit 0
fi
echo "Create /etc/spack/no_rpm_trigger to stop spack to search for new packages after a rpm install"
# save old packages.yml, it has to be removed as when not
# the new and old packages.yaml files would have to be
# combined
# prepare the path
shopt -s nullglob
addpath mypath /usr/lib64/mpi/gcc/openmpi4/bin
addpath mypath /usr/lib64/mpi/gcc/openmpi3/bin
addpath mypath /usr/lib64/mpi/gcc/openmpi2/bin
addpath mypath /usr/lib64/mpi/gcc/openmpi1/bin
addpath mypath /usr/lib64/mpi/gcc/mvapich2/bin
addpath mypath /usr/lib64/mpi/gcc/mpich/bin
addpath mypath /usr/lib/hpc/gnu*/mpi/openmpi/[2-9].*/bin
addpath mypath /usr/lib/hpc/gnu*/mpi/mpich/[3-9].*/bin
addpath mypath /usr/lib/hpc/gnu*/mpi/mvapich2/[2-9].*/bin
addpath cpath /usr/lib/hpc/compiler/gnu/*/bin
# test if we can run as nobody
getent passwd nobody &> /dev/null
if [ "x$?" == "x0" ] ; then
scope=user
fi
case $what in
packages) find_packages $scope ;;
compilers) find_compilers $scope ;;
'') find_packages $scope
find_compilers $scope ;;
*) exit 1 ;;
esac