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
11+ fi
12+ fi
13+
514require_fetch ()
615{
716 if command -v curl > /dev/null 2>&1 ; then
@@ -18,7 +27,7 @@ require_fetch()
1827# https://github.com/cea-hpc/modules
1928install_environment_modules_apt () {
2029 echo " Installing environment-modules package..."
21- sudo apt-get install -y environment-modules
30+ $SUDO apt-get install -y environment-modules
2231 echo " Environment-modules installed."
2332 echo " Sourcing modules.sh script to set up environment modules..."
2433 source /etc/profile.d/modules.sh
@@ -53,8 +62,8 @@ install_gcc_brew()
5362install_gcc_apt ()
5463{
5564 if [ " $version " == " latest" ]; then
56- sudo apt-get update
57- sudo apt-get install -y gcc gfortran g++
65+ $SUDO apt-get update
66+ $SUDO apt-get install -y gcc gfortran g++
5867 else
5968 # Check whether the system gcc version is the version we are after.
6069 cur=$( apt show gcc | grep " Version" | cut -d' :' -f3 | cut -d' -' -f1)
@@ -68,15 +77,15 @@ install_gcc_apt()
6877 fi
6978 else
7079 # Install the PPA for installing other versions of gcc.
71- sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
72- sudo apt-get update
80+ $SUDO add-apt-repository --yes ppa:ubuntu-toolchain-r/test
81+ $SUDO apt-get update
7382 fi
7483
7584 if [ " ${needs_install} " == " 1" ]; then
76- sudo apt-get install -y gcc-${version} gfortran-${version} g++-${version}
85+ $SUDO apt-get install -y gcc-${version} gfortran-${version} g++-${version}
7786 fi
7887
79- sudo update-alternatives \
88+ $SUDO update-alternatives \
8089 --install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \
8190 --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \
8291 --slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \
@@ -367,25 +376,25 @@ install_intel_apt()
367376 require_fetch
368377 local _KEY=" GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB"
369378 $fetch https://apt.repos.intel.com/intel-gpg-keys/$_KEY > $_KEY
370- sudo apt-key add $_KEY
379+ $SUDO apt-key add $_KEY
371380 rm $_KEY
372381 echo " deb https://apt.repos.intel.com/oneapi all main" \
373- | sudo tee /etc/apt/sources.list.d/oneAPI.list
374- sudo apt-get update
382+ | $SUDO tee /etc/apt/sources.list.d/oneAPI.list
383+ $SUDO apt-get update
375384
376385 if [ " $version " == " latest" ]; then
377- sudo apt-get install -y \
386+ $SUDO apt-get install -y \
378387 intel-oneapi-compiler-fortran \
379388 intel-oneapi-compiler-dpcpp-cpp
380389 else
381390 # c/cpp compiler package names changed with 2024+
382391 case $version in
383392 2024* | 2025* )
384- sudo apt-get install -y \
393+ $SUDO apt-get install -y \
385394 intel-oneapi-compiler-{fortran,dpcpp-cpp}-$version
386395 ;;
387396 * )
388- sudo apt-get install -y \
397+ $SUDO apt-get install -y \
389398 intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version
390399 ;;
391400 esac
@@ -453,7 +462,7 @@ install_intel_dmg()
453462 require_fetch
454463 $fetch $MACOS_HPCKIT_URL > m_HPCKit.dmg
455464 hdiutil attach m_HPCKit.dmg
456- sudo /Volumes/" $( basename " $MACOS_HPCKIT_URL " .dmg) " /bootstrapper.app/Contents/MacOS/bootstrapper -s \
465+ $SUDO /Volumes/" $( basename " $MACOS_HPCKIT_URL " .dmg) " /bootstrapper.app/Contents/MacOS/bootstrapper -s \
457466 --action install \
458467 --eula=accept \
459468 --continue-with-optional-error=yes \
@@ -589,10 +598,10 @@ install_nvidiahpc_apt()
589598
590599 # install NVIDIA HPC SDK
591600 echo " Installing NVIDIA HPC SDK $version ..."
592- 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
593- 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
594- sudo apt-get update -y
595- sudo apt-get install -y nvhpc-$cversion
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
596605 echo " NVIDIA HPC SDK $version installed."
597606
598607 # load NVIDIA HPC SDK module
0 commit comments