Skip to content

Instantly share code, notes, and snippets.

@holly
Created March 27, 2026 11:45
Show Gist options
  • Select an option

  • Save holly/314462ec66ef55605d466006a82507c7 to your computer and use it in GitHub Desktop.

Select an option

Save holly/314462ec66ef55605d466006a82507c7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
set -C
# Configuration
REPO="LuaLS/lua-language-server"
BIN_NAME="lua-language-server"
INSTALL_DIR="${HOME}/.local/share/${BIN_NAME}"
BIN_DIR="${HOME}/.local/bin"
echo "Detecting OS and Architecture..."
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
case "$OS" in
linux) OS="linux" ;;
darwin) OS="darwin" ;;
*)
echo "Error: Unsupported OS: $OS"
exit 1
;;
esac
case "$ARCH" in
x86_64) ARCH="x64" ;;
aarch64) ARCH="arm64" ;;
arm64) ARCH="arm64" ;;
*)
echo "Error: Unsupported Architecture: $ARCH"
exit 1
;;
esac
echo "Fetching the latest version..."
# Get latest release tag name (e.g., 3.7.4)
REMOTE_VERSION=$(curl -s "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$REMOTE_VERSION" ]; then
echo "Error: Could not determine latest version."
exit 1
fi
# --- Check existing installation ---
INSTALLED_BIN="${BIN_DIR}/${BIN_NAME}"
if [ -x "$INSTALLED_BIN" ]; then
# Get local version.
# Output format of lua-language-server --version is typically: "lua-language-server 3.7.4"
# We extract the last field using awk.
LOCAL_VERSION=$("$INSTALLED_BIN" --version 2>/dev/null | awk '{print $NF}')
if [ "$LOCAL_VERSION" = "$REMOTE_VERSION" ]; then
echo ""
echo "Latest version (${REMOTE_VERSION}) is already installed."
echo "Skipping installation."
exit 0
else
echo "Update available: ${LOCAL_VERSION} -> ${REMOTE_VERSION}"
fi
fi
# ----------------------------------
FILENAME="${BIN_NAME}-${REMOTE_VERSION}-${OS}-${ARCH}.tar.gz"
DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${REMOTE_VERSION}/${FILENAME}"
echo "Installing ${BIN_NAME} ${REMOTE_VERSION}..."
echo "Platform: ${OS}-${ARCH}"
echo "URL: ${DOWNLOAD_URL}"
# Prepare directories
mkdir -p "$BIN_DIR"
mkdir -p "$INSTALL_DIR"
# Download and Extract
TEMP_DIR=$(mktemp -d)
echo "Downloading..."
curl -sL "$DOWNLOAD_URL" | tar xz -C "$TEMP_DIR"
# Move files to installation directory
# Remove old files to ensure clean update
rm -rf "${INSTALL_DIR:?}"/*
# The tarball usually extracts into a directory structure or directly.
# LuaLS tarballs typically contain: bin/, main.lua, meta/, script/, etc.
# We move everything from temp dir to install dir.
mv "${TEMP_DIR}"/* "${INSTALL_DIR}/"
# Cleanup
rm -rf "$TEMP_DIR"
# Create symlink
EXECUTABLE_PATH="${INSTALL_DIR}/bin/${BIN_NAME}"
if [ -f "$EXECUTABLE_PATH" ]; then
chmod +x "$EXECUTABLE_PATH"
ln -sf "$EXECUTABLE_PATH" "${BIN_DIR}/${BIN_NAME}"
echo ""
echo "Installation complete!"
echo "Binary linked to: ${BIN_DIR}/${BIN_NAME}"
else
echo "Error: Executable not found at ${EXECUTABLE_PATH}"
exit 1
fi
echo ""
echo "Please ensure '${BIN_DIR}' is in your PATH."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment