Install gcc, gfortran and clang on linux

This commit is contained in:
Ivan Nosar
2020-02-04 17:14:16 +03:00
parent 19da4e4754
commit 58033ad1fd
5 changed files with 133 additions and 31 deletions

View File

@@ -1,25 +1,22 @@
#!/bin/bash #!/bin/bash
################################################################################ ################################################################################
## File: example.sh ## File: clang.sh
## Desc: This is an example script that can be copied to add a new software ## Desc: Installs Clang compiler (versions: 6, 8 and 9)
## installer to the image
################################################################################ ################################################################################
# Source the helpers for use with the script # Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh source $HELPER_SCRIPTS/document.sh
source $HELPER_SCRIPTS/apt.sh source $HELPER_SCRIPTS/apt.sh
function InstallClang6_0 {
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
apt-add-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-6.0 main" apt-add-repository "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-6.0 main"
apt-get update apt-get update
apt-get install -y clang-6.0 lldb-6.0 lld-6.0 apt-get install -y clang-6.0 lldb-6.0 lld-6.0
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-6.0 100
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 100
# Run tests to determine that the software installed as expected # Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work" echo "Testing to make sure that script performed as expected, and basic scenarios work"
for cmd in clang clang++ clang-6.0 clang++-6.0; do for cmd in clang-6.0 clang++-6.0; do
if ! command -v $cmd; then if ! command -v $cmd; then
echo "$cmd was not installed" echo "$cmd was not installed"
exit 1 exit 1
@@ -28,4 +25,53 @@ done
# Document what was added to the image # Document what was added to the image
echo "Lastly, documenting what we added to the metadata file" echo "Lastly, documenting what we added to the metadata file"
DocumentInstalledItem "Clang 6.0 ($(clang-6.0 --version | head -n 1 | sed 's/~/\\~/g'))" DocumentInstalledItem "Clang 6.0 ($(clang-6.0 --version | head -n 1 | cut -d ' ' -f 3 | cut -d '-' -f 1))"
}
function InstallClang {
version=$1
echo "Installing clang-$version..."
./llvm.sh $version
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
for cmd in clang-$version clang++-$version; do
if ! command -v $cmd; then
echo "$cmd was not installed"
exit 1
fi
done
# Document what was added to the image
echo "Documenting clang-$version..."
DocumentInstalledItem "Clang $version ($(clang-$version --version | head -n 1 | cut -d ' ' -f 3 | cut -d '-' -f 1))"
}
# Install Clang compiler
apt-get update -y
# Clang 6.0 is not supported by automatic installation script (`llvm.sh`)
# Thus we have to install it explicitly
InstallClang6_0
# Download script for automatic installation
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
# Install Clang 8 and 9
versions=(
"8"
"9"
)
for version in ${versions[*]}
do
InstallClang $version
done
rm llvm.sh
# Make Clang 9 default
update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-9 100
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-9 100

View File

@@ -7,19 +7,34 @@
# Source the helpers for use with the script # Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh source $HELPER_SCRIPTS/document.sh
# Install GNU C++ compiler function InstallGcc {
add-apt-repository ppa:ubuntu-toolchain-r/test -y version=$1
apt-get update -y
apt-get install g++-7 -y
echo "Installing $version..."
apt-get install $version -y
# Run tests to determine that the software installed as expected # Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work" echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! command -v g++-7; then if ! command -v $version; then
echo "GNU C++ was not installed" echo "$version was not installed"
exit 1 exit 1
fi fi
# Document what was added to the image # Document what was added to the image
echo "Lastly, documenting what we added to the metadata file" echo "Documenting $version..."
DocumentInstalledItem "GNU C++ $(g++-7 --version | head -n 1 | cut -d ' ' -f 4)" DocumentInstalledItem "GNU C++ $($version --version | head -n 1 | cut -d ' ' -f 4)"
}
# Install GNU C++ compiler
apt-get update -y
versions=(
"g++-7"
"g++-8"
"g++-9"
)
for version in ${versions[*]}
do
InstallGcc $version
done

View File

@@ -0,0 +1,39 @@
#!/bin/bash
################################################################################
## File: gfortran.sh
## Desc: Installs GNU Fortran
################################################################################
# Source the helpers for use with the script
source $HELPER_SCRIPTS/document.sh
function InstallFortran {
version=$1
echo "Installing $version..."
apt-get install $version -y
# Run tests to determine that the software installed as expected
echo "Testing to make sure that script performed as expected, and basic scenarios work"
if ! command -v $version; then
echo "$version was not installed"
exit 1
fi
# Document what was added to the image
echo "Documenting $version..."
DocumentInstalledItem "GNU Fortran $($version --version | head -n 1 | cut -d ' ' -f 5)"
}
# Install GNU Fortran compiler
apt-get update -y
versions=(
"gfortran-8"
"gfortran-9"
)
for version in ${versions[*]}
do
InstallFortran $version
done

View File

@@ -132,6 +132,7 @@
"{{template_dir}}/scripts/installers/erlang.sh", "{{template_dir}}/scripts/installers/erlang.sh",
"{{template_dir}}/scripts/installers/firefox.sh", "{{template_dir}}/scripts/installers/firefox.sh",
"{{template_dir}}/scripts/installers/gcc.sh", "{{template_dir}}/scripts/installers/gcc.sh",
"{{template_dir}}/scripts/installers/gfortran.sh",
"{{template_dir}}/scripts/installers/git.sh", "{{template_dir}}/scripts/installers/git.sh",
"{{template_dir}}/scripts/installers/1604/go.sh", "{{template_dir}}/scripts/installers/1604/go.sh",
"{{template_dir}}/scripts/installers/google-chrome.sh", "{{template_dir}}/scripts/installers/google-chrome.sh",

View File

@@ -135,6 +135,7 @@
"{{template_dir}}/scripts/installers/erlang.sh", "{{template_dir}}/scripts/installers/erlang.sh",
"{{template_dir}}/scripts/installers/firefox.sh", "{{template_dir}}/scripts/installers/firefox.sh",
"{{template_dir}}/scripts/installers/gcc.sh", "{{template_dir}}/scripts/installers/gcc.sh",
"{{template_dir}}/scripts/installers/gfortran.sh",
"{{template_dir}}/scripts/installers/git.sh", "{{template_dir}}/scripts/installers/git.sh",
"{{template_dir}}/scripts/installers/1804/go.sh", "{{template_dir}}/scripts/installers/1804/go.sh",
"{{template_dir}}/scripts/installers/google-chrome.sh", "{{template_dir}}/scripts/installers/google-chrome.sh",