22
33set -ex
44
5- if command -v sudo > /dev/null 2>&1 ; then
6- SUDO=sudo
7- else
8- if [[ $EUID -ne 0 ]]; then
9- echo " This script requires 'sudo' to install packages. Please install 'sudo' or run as root."
10- exit 1
5+ sudo_wrapper () {
6+ if command -v sudo > /dev/null 2>&1 ; then
7+ SUDO=" sudo"
8+ else
9+ if [[ $EUID -ne 0 ]]; then
10+ echo " This script requires 'sudo' to install packages. Please install 'sudo' or run as root."
11+ exit 1
12+ fi
13+ SUDO=" "
1114 fi
12- fi
15+ $SUDO " $@ "
16+ }
1317
1418require_fetch ()
1519{
@@ -27,7 +31,7 @@ require_fetch()
2731# https://github.com/cea-hpc/modules
2832install_environment_modules_apt () {
2933 echo " Installing environment-modules package..."
30- $SUDO apt-get install -y environment-modules
34+ sudo_wrapper apt-get install -y environment-modules
3135 echo " Environment-modules installed."
3236 echo " Sourcing modules.sh script to set up environment modules..."
3337 source /etc/profile.d/modules.sh
@@ -62,8 +66,8 @@ install_gcc_brew()
6266install_gcc_apt ()
6367{
6468 if [ " $version " == " latest" ]; then
65- $SUDO apt-get update
66- $SUDO apt-get install -y gcc gfortran g++
69+ sudo_wrapper apt-get update
70+ sudo_wrapper apt-get install -y gcc gfortran g++
6771 else
6872 # Check whether the system gcc version is the version we are after.
6973 cur=$( apt show gcc | grep " Version" | cut -d' :' -f3 | cut -d' -' -f1)
@@ -77,15 +81,15 @@ install_gcc_apt()
7781 fi
7882 else
7983 # Install the PPA for installing other versions of gcc.
80- $SUDO add-apt-repository --yes ppa:ubuntu-toolchain-r/test
81- $SUDO apt-get update
84+ sudo_wrapper add-apt-repository --yes ppa:ubuntu-toolchain-r/test
85+ sudo_wrapper apt-get update
8286 fi
8387
8488 if [ " ${needs_install} " == " 1" ]; then
85- $SUDO apt-get install -y gcc-${version} gfortran-${version} g++-${version}
89+ sudo_wrapper apt-get install -y gcc-${version} gfortran-${version} g++-${version}
8690 fi
8791
88- $SUDO update-alternatives \
92+ sudo_wrapper update-alternatives \
8993 --install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \
9094 --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \
9195 --slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \
@@ -376,25 +380,25 @@ install_intel_apt()
376380 require_fetch
377381 local _KEY=" GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB"
378382 $fetch https://apt.repos.intel.com/intel-gpg-keys/$_KEY > $_KEY
379- $SUDO apt-key add $_KEY
383+ sudo_wrapper apt-key add $_KEY
380384 rm $_KEY
381385 echo " deb https://apt.repos.intel.com/oneapi all main" \
382- | $SUDO tee /etc/apt/sources.list.d/oneAPI.list
383- $SUDO apt-get update
386+ | sudo_wrapper tee /etc/apt/sources.list.d/oneAPI.list
387+ sudo_wrapper apt-get update
384388
385389 if [ " $version " == " latest" ]; then
386- $SUDO apt-get install -y \
390+ sudo_wrapper apt-get install -y \
387391 intel-oneapi-compiler-fortran \
388392 intel-oneapi-compiler-dpcpp-cpp
389393 else
390394 # c/cpp compiler package names changed with 2024+
391395 case $version in
392396 2024* | 2025* )
393- $SUDO apt-get install -y \
397+ sudo_wrapper apt-get install -y \
394398 intel-oneapi-compiler-{fortran,dpcpp-cpp}-$version
395399 ;;
396400 * )
397- $SUDO apt-get install -y \
401+ sudo_wrapper apt-get install -y \
398402 intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version
399403 ;;
400404 esac
@@ -462,7 +466,7 @@ install_intel_dmg()
462466 require_fetch
463467 $fetch $MACOS_HPCKIT_URL > m_HPCKit.dmg
464468 hdiutil attach m_HPCKit.dmg
465- $SUDO /Volumes/" $( basename " $MACOS_HPCKIT_URL " .dmg) " /bootstrapper.app/Contents/MacOS/bootstrapper -s \
469+ sudo_wrapper /Volumes/" $( basename " $MACOS_HPCKIT_URL " .dmg) " /bootstrapper.app/Contents/MacOS/bootstrapper -s \
466470 --action install \
467471 --eula=accept \
468472 --continue-with-optional-error=yes \
@@ -598,10 +602,10 @@ install_nvidiahpc_apt()
598602
599603 # install NVIDIA HPC SDK
600604 echo " Installing NVIDIA HPC SDK $version ..."
601- curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | $SUDO gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg
602- echo ' deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | $SUDO tee /etc/apt/sources.list.d/nvhpc.list
603- $SUDO apt-get update -y
604- $SUDO apt-get install -y nvhpc-$cversion
605+ curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | sudo_wrapper gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg
606+ echo ' deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | sudo_wrapper tee /etc/apt/sources.list.d/nvhpc.list
607+ sudo_wrapper apt-get update -y
608+ sudo_wrapper apt-get install -y nvhpc-$cversion
605609 echo " NVIDIA HPC SDK $version installed."
606610
607611 # load NVIDIA HPC SDK module
0 commit comments