Path: blob/main/Tools/scripts/hackage-get-latest-version.sh
18878 views
#!/bin/sh1#2# MAINTAINER: [email protected]34set -e5set -o pipefail67export LC_ALL=C89##10## hackage-get-latest-version.sh: retrieves the latest version of a given Haskell package as registered on https://hackage.haskell.org11##1213# args1415PACKAGE_NAME="$1"1617if [ -z "$PACKAGE_NAME" ]; then18echo "Usage: $0 <package-name>"19exit 120fi2122# check that packaged dependencies are installed2324for dep in curl jq version_sort; do25if ! which -s $dep; then26echo "error: the '$dep' dependency is missing"27if [ $dep == "curl" ]; then28echo "... please install the 'curl' package"29elif [ $dep == "jq" ]; then30echo "... please install the 'jq' package"31elif [ $dep == "version_sort" ]; then32echo "... please install the 'libversion' package"33fi34exit 135fi36done373839# MAIN4041curl -H "Accept: application/json" https://hackage.haskell.org/package/$PACKAGE_NAME 2>/dev/null |42grep -v "Package not found: No such package in package index" |43jq -r 'keys[]' |44version_sort |45tail -1 ||46! echo "failed to find the Haskell package '$PACKAGE_NAME'"474849