-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathinstall
More file actions
executable file
·51 lines (44 loc) · 1.79 KB
/
install
File metadata and controls
executable file
·51 lines (44 loc) · 1.79 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
#!/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