more readable script (#956)

This commit is contained in:
Mikhail Timofeev
2020-05-29 14:38:59 +03:00
committed by GitHub
parent 696110c157
commit 6ac6655c9f

View File

@@ -13,14 +13,20 @@ apt-get install -y software-properties-common
add-apt-repository -y ppa:hvr/ghc add-apt-repository -y ppa:hvr/ghc
apt-get update apt-get update
# Get 3 latest Haskell versions and latest Cabal version # Get 3 latest Haskell Major.Minor versions
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) allGhcVersions=$(apt-cache search "^ghc-" | grep -Po '(\d*\.){2}\d*' | sort --unique --version-sort)
cabalVersion=$(apt-cache search cabal-install-[0-9] | grep -Po '\d*\.\d*' | sort --unique --version-sort | tail -1) ghcMajorMinorVersions=$(echo "$allGhcVersions" | cut -d "." -f 1,2 | sort --unique --version-sort | tail -3)
for version in $ghcVersions; do for version in $ghcMajorMinorVersions; do
apt-get install -y ghc-$version # Get latest patch version for given Major.Minor one (ex. 8.6.5 for 8.6) and install it
exactVersion=$(echo "$allGhcVersions" | grep $version | sort --unique --version-sort | tail -1)
apt-get install -y ghc-$exactVersion
ghcInstalledVersions+=("$exactVersion")
done done
# Get latest cabal version
cabalVersion=$(apt-cache search cabal-install-[0-9] | grep -Po '\d*\.\d*' | sort --unique --version-sort | tail -1)
apt-get install -y cabal-install-$cabalVersion apt-get install -y cabal-install-$cabalVersion
# Install the latest stable release of haskell stack # Install the latest stable release of haskell stack
@@ -50,7 +56,7 @@ 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 "Lastly, documenting what we added to the metadata file"
DocumentInstalledItem "Haskell Cabal ($(/opt/cabal/$cabalVersion/bin/cabal --version))" DocumentInstalledItem "Haskell Cabal ($(/opt/cabal/$cabalVersion/bin/cabal --version))"
for version in $ghcVersions; do for version in ${ghcInstalledVersions[@]}; do
DocumentInstalledItem "GHC ($(/opt/ghc/$version/bin/ghc --version))" DocumentInstalledItem "GHC ($(/opt/ghc/$version/bin/ghc --version))"
done done
DocumentInstalledItem "Haskell Stack ($(stack --version))" DocumentInstalledItem "Haskell Stack ($(stack --version))"