Last active
November 1, 2023 08:21
-
-
Save alexjoedt/e4b99a24e990c08e9df4901dcd24e7fa to your computer and use it in GitHub Desktop.
get-grip.sh
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
#!/bin/bash | |
set -euo pipefail | |
TEMP_DIR="" | |
install_grip() { | |
local PLATFORM=$1 | |
local ARCH=$2 | |
local INSTALL_PATH="/usr/local/bin/grip" | |
if grip >/dev/null 2>&1; then | |
INSTALL_PATH="$(which grip)" | |
fi | |
local PACKAGE="grip_${PLATFORM}_${ARCH}.tar.gz" | |
TEMP_DIR=$(mktemp -d "${TMPDIR:-/tmp/}$(basename "dotfiles").XXXXXXXXXXXX") | |
trap 'test -d "$TEMP_DIR" && rm -rf "$TEMP_DIR"' EXIT | |
curl -sLo "$TEMP_DIR/$PACKAGE" "https://github.com/alexjoedt/grip/releases/latest/download/$PACKAGE" >/dev/null || { | |
echo "Error downloading package" | |
exit 1 | |
} | |
tar -xf "$TEMP_DIR/$PACKAGE" -C "$TEMP_DIR" || { | |
echo "Error extracting package" | |
exit 1 | |
} | |
sudo mv "$TEMP_DIR/grip" "$INSTALL_PATH" || { | |
echo "Error moving grip to /usr/local/bin" | |
exit 1 | |
} | |
} | |
main() { | |
command -v curl >/dev/null 2>&1 || { | |
echo >&2 "curl is required but it's not installed. Aborting." | |
exit 1 | |
} | |
local PLATFORM=$(uname -s) | |
local ARCH=$(uname -m) | |
install_grip "$PLATFORM" "$ARCH" | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment