Skip to content

Commit 1b9a5df

Browse files
authored
Update install script to support a custom installation path (#244)
I want this tool to be in my `$HOME/bin` rather than `/usr/local`. Introduces a second argument that is the installation destination. Also allows you to pass `latest` as the first one: ``` install latest $HOME ``` Otherwise one would need to find the latest version manually which I do not like. Also avoid using `mkdir` since `install` allows you to specify permissions ignoring `umask` completely. This is somewhat unrealated, is is my own thing as I am Fedora packager and it is just cought my eye :-) Awesome tool, going to try it now. Cheers! Signed-off-by: Lukáš Zapletal <lukas@zapletalovi.com>
1 parent 9fc88b8 commit 1b9a5df

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

install

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ set -o nounset
55

66
UNAME="$(uname)"
77
ARCH="$(uname -m)"
8+
OUTPUT="${2:-/usr/local}"
89

910
if [ "$UNAME" = "Darwin" ] || [ "$UNAME" = "Linux" ]
1011
then
1112
echo "---- Fetching the pre-built JSON Schema CLI binary from GitHub Releases" 1>&2
1213
OWNER="sourcemeta"
1314
REPOSITORY="jsonschema"
1415

15-
if [ $# -lt 1 ]
16+
if [ $# -lt 1 ] || [ "$1" = "latest" ]
1617
then
1718
VERSION="$(curl --retry 5 --silent "https://api.github.com/repos/$OWNER/$REPOSITORY/releases/latest" \
1819
| grep '"tag_name"' | cut -d ':' -f 2 | tr -d 'v" ,')"
@@ -24,13 +25,12 @@ then
2425
PACKAGE_PLATFORM_NAME="$(echo "$UNAME" | tr '[:upper:]' '[:lower:]')"
2526
PACKAGE_URL="$PACKAGE_BASE_URL/jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH.zip"
2627
echo "---- Fetching version v$VERSION from $PACKAGE_URL" 1>&2
27-
OUTPUT="/usr/local"
2828
TMP="$(mktemp -d)"
2929
clean() { rm -rf "$TMP"; }
3030
trap clean EXIT
3131
curl --retry 5 --location --output "$TMP/artifact.zip" "$PACKAGE_URL"
3232
unzip "$TMP/artifact.zip" -d "$TMP/out"
33-
mkdir -p "$OUTPUT/bin"
33+
install -d -m 0755 "$OUTPUT/bin"
3434
install -v -m 0755 "$TMP/out/jsonschema-$VERSION-$PACKAGE_PLATFORM_NAME-$ARCH/bin/jsonschema" "$OUTPUT/bin"
3535
else
3636
echo "ERROR: I don't know how to install the JSON Schema CLI in $UNAME!" 1>&2

0 commit comments

Comments
 (0)