-
Notifications
You must be signed in to change notification settings - Fork 5
/
install
executable file
·39 lines (34 loc) · 1.29 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/sh
set -o errexit
set -o nounset
UNAME="$(uname)"
ARCH="$(uname -m)"
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 ]
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:]')"
PACKAGE_URL="$PACKAGE_BASE_URL/jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH.zip"
echo "---- Fetching version v$VERSION from $PACKAGE_URL" 1>&2
OUTPUT="/usr/local"
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"
mkdir -p "$OUTPUT/bin"
install -v -m 0755 "$TMP/out/jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH/bin/jsonschema" "$OUTPUT/bin"
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