#!/bin/sh set -o errexit set -o nounset UNAME="$(uname)" ARCH="$(uname -m)" OUTPUT="${2:-/usr/local}" if [ "$UNAME" = "Darwin" ] || [ "$UNAME" = "Linux" ] then echo "---- Fetching the pre-built JSON Schema CLI binary from GitHub Releases" 1>&2 OWNER="sourcemeta" REPOSITORY="jsonschema" if [ $# -lt 1 ] || [ "$1" = "latest" ] then VERSION="$(curl --retry 5 --silent "https://api.github.com/repos/$OWNER/$REPOSITORY/releases/latest" \ | grep '"tag_name"' | cut -d ':' -f 2 | tr -d 'v" ,')" else VERSION="$1" fi PACKAGE_BASE_URL="https://github.com/$OWNER/$REPOSITORY/releases/download/v$VERSION" PACKAGE_PLATFORM_NAME="$(echo "$UNAME" | tr '[:upper:]' '[:lower:]')" if [ "$UNAME" = "Linux" ] && [ -f /etc/os-release ] && grep -qi alpine /etc/os-release then PACKAGE_NAME="jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH-musl" else PACKAGE_NAME="jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH" fi PACKAGE_URL="$PACKAGE_BASE_URL/$PACKAGE_NAME.zip" echo "---- Fetching version v$VERSION from $PACKAGE_URL" 1>&2 TMP="$(mktemp -d)" clean() { rm -rf "$TMP"; } trap clean EXIT curl --retry 5 --location --output "$TMP/artifact.zip" "$PACKAGE_URL" unzip "$TMP/artifact.zip" -d "$TMP/out" install -d -m 0755 "$OUTPUT/bin" install -v -m 0755 "$TMP/out/$PACKAGE_NAME/bin/jsonschema" "$OUTPUT/bin" echo "" 1>&2 echo "Tip: Try the Sourcemeta Studio VS Code extension for an enhanced experience!" 1>&2 echo " Open in VS Code: vscode:extension/sourcemeta.sourcemeta-studio" 1>&2 echo " Or visit: https://marketplace.visualstudio.com/items?itemName=sourcemeta.sourcemeta-studio" 1>&2 else echo "ERROR: I don't know how to install the JSON Schema CLI in $UNAME!" 1>&2 echo "Open an issue here: https://github.com/sourcemeta/jsonschema/issues" 1>&2 exit 1 fi