Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
gram/install.sh
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
78 lines (64 sloc)
2.46 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.3}" | |
# 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.' | |
) |