From d50fdf89229ba2f65310c0a2f7a5fbf16d954fe6 Mon Sep 17 00:00:00 2001 From: Tim Dawborn Date: Thu, 20 Mar 2025 23:05:01 +1000 Subject: [PATCH] Fix `gcc` install check. --- setup-fortran.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/setup-fortran.sh b/setup-fortran.sh index 89958b2..128f0ea 100755 --- a/setup-fortran.sh +++ b/setup-fortran.sh @@ -45,14 +45,23 @@ install_gcc_brew() install_gcc_apt() { - # check if gcc preinstalled via apt + # Check whether the system gcc version is the version we are after. cur=$(apt show gcc | grep "Version" | cut -d':' -f3 | cut -d'-' -f1) maj=$(echo $cur | cut -d'.' -f1) + needs_install=1 if [ "$maj" == "$version" ]; then - echo "GCC $version already installed" + # Check whether that version is installed. + if apt list --installed gcc-${version} | grep -q "gcc-${version}/"; then + echo "GCC $version already installed" + needs_install=0 + fi else + # Install the PPA for installing other versions of gcc. sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test sudo apt-get update + fi + + if [ "${needs_install}" == "1" ]; then sudo apt-get install -y gcc-${version} gfortran-${version} g++-${version} fi