Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add installer script for linux/macOS (#270)
* feat: add installer script for linux/macOS * remove -e flag from script
- Loading branch information
Showing
4 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
# Most of this script is taken from https://github.com/mitsuhiko/rye/blob/main/scripts/install.sh | ||
|
||
# Wrap everything in a function so that a truncated script | ||
# does not have the chance to cause issues. | ||
__wrap__() { | ||
|
||
# allow overriding the version | ||
VERSION=${LEETGO_VERSION:-latest} | ||
PREFIX=${LEETGO_PREFIX:-${HOME}/.local} | ||
|
||
REPO=j178/leetgo | ||
PLATFORM=`uname -s` | ||
ARCH=`uname -m` | ||
|
||
if [[ $PLATFORM == "Darwin" ]]; then | ||
PLATFORM="macOS" | ||
elif [[ $PLATFORM == "Linux" ]]; then | ||
PLATFORM="linux" | ||
fi | ||
|
||
if [[ $ARCH == armv8* ]] || [[ $ARCH == arm64* ]] || [[ $ARCH == aarch64* ]]; then | ||
ARCH="arm64" | ||
elif [[ $ARCH == i686* ]]; then | ||
ARCH="x86_64" | ||
fi | ||
|
||
BINARY="leetgo_${PLATFORM}_${ARCH}" | ||
|
||
# Oddly enough GitHub has different URLs for latest vs specific version | ||
if [[ $VERSION == "latest" ]]; then | ||
DOWNLOAD_URL=https://github.com/${REPO}/releases/latest/download/${BINARY}.tar.gz | ||
else | ||
DOWNLOAD_URL=https://github.com/${REPO}/releases/download/${VERSION}/${BINARY}.tar.gz | ||
fi | ||
|
||
echo "This script will automatically download and install leetgo (${VERSION}) for you." | ||
if [ "x$(id -u)" == "x0" ]; then | ||
echo "warning: this script is running as root. This is dangerous and unnecessary!" | ||
fi | ||
|
||
if ! hash curl 2> /dev/null; then | ||
echo "error: you do not have 'curl' installed which is required for this script." | ||
exit 1 | ||
fi | ||
|
||
if ! hash tar 2> /dev/null; then | ||
echo "error: you do not have 'tar' installed which is required for this script." | ||
exit 1 | ||
fi | ||
|
||
TEMP_INSTALL_DIR=`mktemp "${TMPDIR:-/tmp/}.leetgoinstall.XXXXXXXX"` | ||
TEMP_FILE_GZ="${TEMP_INSTALL_DIR}.tar.gz" | ||
|
||
rm -rf "$TEMP_INSTALL_DIR" | ||
mkdir -p "$TEMP_INSTALL_DIR" | ||
|
||
cleanup() { | ||
rm -rf "$TEMP_INSTALL_DIR" | ||
rm -f "$TEMP_FILE_GZ" | ||
} | ||
|
||
trap cleanup EXIT | ||
echo "Downloading $DOWNLOAD_URL" | ||
HTTP_CODE=$(curl -SL --progress-bar "$DOWNLOAD_URL" --output "$TEMP_FILE_GZ" --write-out "%{http_code}") | ||
if [[ ${HTTP_CODE} -lt 200 || ${HTTP_CODE} -gt 299 ]]; then | ||
echo "error: platform ${PLATFORM} (${ARCH}) is unsupported." | ||
exit 1 | ||
fi | ||
|
||
tar -xzf "$TEMP_FILE_GZ" -C "$TEMP_INSTALL_DIR" | ||
|
||
DEST="$PREFIX/bin/leetgo" | ||
|
||
# Continue? | ||
echo "leetgo will be installed into '$DEST'." | ||
echo -n "Continue? (y/n) " | ||
read -r yn | ||
case $yn in | ||
[Yy]* ) ;; | ||
* ) exit;; | ||
esac | ||
|
||
chmod +x "$TEMP_INSTALL_DIR/leetgo" | ||
mv "$TEMP_INSTALL_DIR/leetgo" "$DEST" | ||
|
||
}; __wrap__ |