-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·78 lines (64 loc) · 2.46 KB
/
install.sh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env sh
# This installer script supports Linux and macOS machines running on x86-64 only.
# Usage examples:
# ./install.sh
# VERSION=x.y.z ./install.sh
# PREFIX=/usr/local/bin ./install.sh
# We wrap everything in parentheses to prevent the shell from executing only a prefix of the script
# if the download is interrupted.
(
# Where the binary will be installed
DESTINATION="${PREFIX:-/usr/local/bin}/gram"
# Which version to download
RELEASE="v${VERSION:-0.0.4}"
# Determine which binary to download.
FILENAME=''
if uname -a | grep -qi 'x86_64.*GNU/Linux'; then
echo 'x86-64 GNU Linux detected.'
FILENAME=gram-x86_64-unknown-linux-gnu
elif uname -a | grep -qi 'x86_64.*Linux'; then
echo 'x86-64 non-GNU Linux detected.'
FILENAME=gram-x86_64-unknown-linux-musl
elif uname -a | grep -qi 'aarch64.*GNU/Linux'; then
echo 'AArch64 GNU Linux detected.'
FILENAME=gram-aarch64-unknown-linux-gnu
elif uname -a | grep -qi 'aarch64.*Linux'; then
echo 'AArch64 non-GNU Linux detected.'
FILENAME=gram-aarch64-unknown-linux-musl
elif uname -a | grep -qi 'Darwin.*x86_64'; then
echo 'x86-64 macOS detected.'
FILENAME=gram-x86_64-apple-darwin
elif uname -a | grep -qi 'Darwin.*arm64'; then
echo 'AArch64 macOS detected.'
FILENAME=gram-aarch64-apple-darwin
fi
# Find a temporary location for the binary.
TEMPDIR=$(mktemp -d /tmp/gram.XXXXXXXX)
# This is a helper function to clean up and fail.
fail() {
echo "$1" >&2
rm -rf "$TEMPDIR"
exit 1
}
# Fail if there is no pre-built binary for this platform.
if [ -z "$FILENAME" ]; then
fail 'Unfortunately, there is no pre-built binary for this platform.'
fi
# Compute the full file path.
SOURCE="$TEMPDIR/$FILENAME"
# Download the binary.
curl \
"https://github.com/gramlang/gram/releases/download/$RELEASE/$FILENAME" \
-o "$SOURCE" -LSf || fail 'There was an error downloading the binary.'
# Make it executable.
chmod a+x "$SOURCE" || fail 'There was an error setting the permissions for the binary.'
# Install it at the requested destination.
# shellcheck disable=SC2024
mv -f "$SOURCE" "$DESTINATION" 2> /dev/null ||
sudo mv -f "$SOURCE" "$DESTINATION" < /dev/tty ||
fail "Unable to install the binary at $DESTINATION."
# Remove the temporary directory.
rm -rf "$TEMPDIR"
# Let the user know if the installation was successful.
"$DESTINATION" --version || fail 'There was an error installing the binary.'
)