Path: blob/main/Tools/scripts/hackage-get-latest-version.sh
17720 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>"19echo "Example: $0 cryptol"20echo "Example: $0 ShellCheck"21exit 122fi2324# check that packaged dependencies are installed2526for dep in curl jq version_sort; do27if ! which -s $dep; then28echo "error: the '$dep' dependency is missing"29if [ $dep = "curl" ]; then30echo "... please install the 'curl' package"31elif [ $dep = "jq" ]; then32echo "... please install the 'jq' package"33elif [ $dep = "version_sort" ]; then34echo "... please install the 'libversion' package"35fi36exit 137fi38done394041# MAIN4243curl -H "Accept: application/json" https://hackage.haskell.org/package/$PACKAGE_NAME 2>/dev/null |44grep -v "Package not found: No such package in package index" |45jq -r 'keys[]' |46version_sort |47tail -1 ||48! echo "failed to find the Haskell package '$PACKAGE_NAME'"495051