Last active
May 28, 2024 18:22
-
-
Save faabiosr/b35924f5c203ada245ca858c91c7e6e5 to your computer and use it in GitHub Desktop.
lb-install.sh
This file contains hidden or 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 | |
# Install `lb` | |
function main { | |
local p="install: error:" | |
# check that required one of the commands are installed before doing anything. | |
if command -v curl &> /dev/null; then | |
cmd="curl -sSL" | |
elif command -v wget &> /dev/null; then | |
cmd="wget -qO -" | |
else | |
echo "${p} neither curl nor wget was found, please install of them and try again!" | |
exit 1 | |
fi | |
# Get the latest version | |
local VERSION=$(${cmd} "https://api.github.com/repos/faabiosr/lb/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | cut -c 2-) | |
if [ -z "${VERSION}" ]; then | |
echo "${p} failed to get the latest version, please check your network connection and try again!" | |
exit 1 | |
fi | |
echo "installing lb v${VERSION} ..." | |
# Check if the OS is supported | |
local OS=$(uname -s | tr '[:upper:]' '[:lower:]') | |
if [ "${OS}" = "darwin" ]; then | |
OS="macos" | |
fi | |
local ARCH=$(uname -m) | |
if [ "${ARCH}" = "arm64" ]; then | |
ARCH="aarch64" | |
fi | |
local FILENAME="lb_${VERSION}_${OS}_${ARCH}" | |
local INSTALL_PATH="${INSTALL_PATH:-${HOME}/.local/bin}" | |
echo https://github.com/faabiosr/lb/releases/download/v${VERSION}/${TAR_FILE} | |
echo "installation path: ${INSTALL_PATH}" | |
mkdir -p ${INSTALL_PATH} | |
if [ $? -ne 0 ]; then | |
echo "${p} failed to create ${INSTALL_PATH} directory, please check your sudo permissions and try again!" | |
exit 1 | |
fi | |
${cmd} https://github.com/faabiosr/lb/releases/download/v${VERSION}/${FILENAME}.tar.gz | tar -xzvf - -C ${INSTALL_PATH} "${FILENAME}/lb" --strip-components=1 | |
if [ $? -ne 0 ]; then | |
echo "${p} failed to extract lb binary, please check you sudo permissions and try again!" | |
exit 1 | |
fi | |
echo "lb installed successfully!" | |
} | |
main $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment