From 728883de5d1e958aa26c2e06d4f01c1666f6e451 Mon Sep 17 00:00:00 2001 From: Mikhail Timofeev <48208649+miketimofeev@users.noreply.github.com> Date: Thu, 28 May 2020 10:36:52 +0300 Subject: [PATCH] [Ubuntu] Install 3 latest Haskell version and latest Cabal version (#939) * Remove deprecated versions * add regexp for the latest versions * refactor some checks * change cabal version * change version retrieval to awk * minor comments improvment --- images/linux/scripts/installers/haskell.sh | 37 +++++++--------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/images/linux/scripts/installers/haskell.sh b/images/linux/scripts/installers/haskell.sh index af9facd1b..1d4dd02da 100644 --- a/images/linux/scripts/installers/haskell.sh +++ b/images/linux/scripts/installers/haskell.sh @@ -6,7 +6,6 @@ # Source the helpers for use with the script source $HELPER_SCRIPTS/document.sh -source $HELPER_SCRIPTS/os.sh # Install Herbert V. Riedel's PPA for managing multiple version of ghc on ubuntu. # https://launchpad.net/~hvr/+archive/ubuntu/ghc @@ -14,25 +13,15 @@ apt-get install -y software-properties-common add-apt-repository -y ppa:hvr/ghc apt-get update -# Install various versions of ghc and cabal -if isUbuntu20 ; then - ghcVersions="8.6.5 8.8.3 8.10.1" - cabalVersions="3.2" -fi - -if isUbuntu16 || isUbuntu18 ; then - # Install various versions of ghc and cabal - ghcVersions="8.0.2 8.2.2 8.4.4 8.6.2 8.6.3 8.6.4 8.6.5 8.8.1 8.8.2 8.8.3 8.10.1" - cabalVersions="2.0 2.2 2.4 3.0 3.2" -fi +# Get 3 latest Haskell versions and latest Cabal version +ghcVersions=$(apt-cache search "^ghc-" | grep -Po '(\d*\.){2}\d*' | awk 'BEGIN {FS=OFS=SUBSEP="."}{if (arr[$1,$2] < $3) arr[$1,$2] = $3} END {for (i in arr) print i,arr[i]}' | sort --version-sort | tail -3) +cabalVersion=$(apt-cache search cabal-install-[0-9] | grep -Po '\d*\.\d*' | sort --unique --version-sort | tail -1) for version in $ghcVersions; do apt-get install -y ghc-$version done -for version in $cabalVersions; do - apt-get install -y cabal-install-$version -done +apt-get install -y cabal-install-$cabalVersion # Install the latest stable release of haskell stack curl -sSL https://get.haskellstack.org/ | sh @@ -46,13 +35,13 @@ for version in $ghcVersions; do exit 1 fi done -# Check all cabal versions -for version in $cabalVersions; do - if ! command -v /opt/cabal/$version/bin/cabal; then - echo "cabal $version was not installed" - exit 1 - fi -done + +# Check cabal +if ! command -v /opt/cabal/$cabalVersion/bin/cabal; then + echo "cabal $cabalVersion was not installed" + exit 1 +fi + # Check stack if ! command -v stack; then exit 1 @@ -60,9 +49,7 @@ fi # Document what was added to the image echo "Lastly, documenting what we added to the metadata file" -for version in $cabalVersions; do - DocumentInstalledItem "Haskell Cabal ($(/opt/cabal/$version/bin/cabal --version))" -done +DocumentInstalledItem "Haskell Cabal ($(/opt/cabal/$cabalVersion/bin/cabal --version))" for version in $ghcVersions; do DocumentInstalledItem "GHC ($(/opt/ghc/$version/bin/ghc --version))" done