2
2
3
3
set -ex
4
4
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
+
5
14
require_fetch ()
6
15
{
7
16
if command -v curl > /dev/null 2>&1 ; then
@@ -18,7 +27,7 @@ require_fetch()
18
27
# https://github.com/cea-hpc/modules
19
28
install_environment_modules_apt () {
20
29
echo " Installing environment-modules package..."
21
- sudo apt-get install -y environment-modules
30
+ $SUDO apt-get install -y environment-modules
22
31
echo " Environment-modules installed."
23
32
echo " Sourcing modules.sh script to set up environment modules..."
24
33
source /etc/profile.d/modules.sh
@@ -53,8 +62,8 @@ install_gcc_brew()
53
62
install_gcc_apt ()
54
63
{
55
64
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++
58
67
else
59
68
# Check whether the system gcc version is the version we are after.
60
69
cur=$( apt show gcc | grep " Version" | cut -d' :' -f3 | cut -d' -' -f1)
@@ -68,15 +77,15 @@ install_gcc_apt()
68
77
fi
69
78
else
70
79
# 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
73
82
fi
74
83
75
84
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}
77
86
fi
78
87
79
- sudo update-alternatives \
88
+ $SUDO update-alternatives \
80
89
--install /usr/bin/gcc gcc /usr/bin/gcc-${version} 100 \
81
90
--slave /usr/bin/gfortran gfortran /usr/bin/gfortran-${version} \
82
91
--slave /usr/bin/gcov gcov /usr/bin/gcov-${version} \
@@ -367,25 +376,25 @@ install_intel_apt()
367
376
require_fetch
368
377
local _KEY=" GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB"
369
378
$fetch https://apt.repos.intel.com/intel-gpg-keys/$_KEY > $_KEY
370
- sudo apt-key add $_KEY
379
+ $SUDO apt-key add $_KEY
371
380
rm $_KEY
372
381
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
375
384
376
385
if [ " $version " == " latest" ]; then
377
- sudo apt-get install -y \
386
+ $SUDO apt-get install -y \
378
387
intel-oneapi-compiler-fortran \
379
388
intel-oneapi-compiler-dpcpp-cpp
380
389
else
381
390
# c/cpp compiler package names changed with 2024+
382
391
case $version in
383
392
2024* | 2025* )
384
- sudo apt-get install -y \
393
+ $SUDO apt-get install -y \
385
394
intel-oneapi-compiler-{fortran,dpcpp-cpp}-$version
386
395
;;
387
396
* )
388
- sudo apt-get install -y \
397
+ $SUDO apt-get install -y \
389
398
intel-oneapi-compiler-{fortran,dpcpp-cpp-and-cpp-classic}-$version
390
399
;;
391
400
esac
@@ -453,7 +462,7 @@ install_intel_dmg()
453
462
require_fetch
454
463
$fetch $MACOS_HPCKIT_URL > m_HPCKit.dmg
455
464
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 \
457
466
--action install \
458
467
--eula=accept \
459
468
--continue-with-optional-error=yes \
@@ -589,10 +598,10 @@ install_nvidiahpc_apt()
589
598
590
599
# install NVIDIA HPC SDK
591
600
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
596
605
echo " NVIDIA HPC SDK $version installed."
597
606
598
607
# load NVIDIA HPC SDK module
0 commit comments