#!/bin/bash # # Glintlog Installer # Usage: curl -fsSL https://raw.githubusercontent.com/ibero-data/glintlog/main/scripts/install.sh | sh # set -e REPO="ibero-data/glintlog" INSTALL_DIR="/usr/local/bin" BINARY_NAME="glintlog" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color info() { echo -e "${GREEN}[INFO]${NC} $1" } warn() { echo -e "${YELLOW}[WARN]${NC} $1" } error() { echo -e "${RED}[ERROR]${NC} $1" exit 1 } # Detect OS and architecture detect_platform() { OS=$(uname -s | tr '[:upper:]' '[:lower:]') ARCH=$(uname -m) case $ARCH in x86_64|amd64) ARCH="amd64" ;; aarch64|arm64) ARCH="arm64" ;; *) error "Unsupported architecture: $ARCH" ;; esac case $OS in linux) OS="linux" ;; darwin) OS="darwin" ;; *) error "Unsupported operating system: $OS" ;; esac PLATFORM="${OS}-${ARCH}" info "Detected platform: $PLATFORM" } # Get latest version from GitHub get_latest_version() { VERSION=$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" | grep '"tag_name"' | sed -E 's/.*"([^"]+)".*/\1/') if [ -z "$VERSION" ]; then error "Could not determine latest version" fi info "Latest version: $VERSION" } # Download and install install() { DOWNLOAD_URL="https://github.com/${REPO}/releases/download/${VERSION}/${BINARY_NAME}-${PLATFORM}" info "Downloading from: $DOWNLOAD_URL" TMP_FILE=$(mktemp) if ! curl -fsSL "$DOWNLOAD_URL" -o "$TMP_FILE"; then rm -f "$TMP_FILE" error "Download failed. Binary for $PLATFORM may not be available." fi chmod +x "$TMP_FILE" # Try to install to /usr/local/bin, fall back to ~/.local/bin if [ -w "$INSTALL_DIR" ]; then mv "$TMP_FILE" "$INSTALL_DIR/$BINARY_NAME" info "Installed to: $INSTALL_DIR/$BINARY_NAME" elif command -v sudo &> /dev/null; then info "Installing to $INSTALL_DIR (requires sudo)" sudo mv "$TMP_FILE" "$INSTALL_DIR/$BINARY_NAME" info "Installed to: $INSTALL_DIR/$BINARY_NAME" else # Fall back to user directory INSTALL_DIR="$HOME/.local/bin" mkdir -p "$INSTALL_DIR" mv "$TMP_FILE" "$INSTALL_DIR/$BINARY_NAME" info "Installed to: $INSTALL_DIR/$BINARY_NAME" # Check if in PATH if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then warn "Add $INSTALL_DIR to your PATH:" echo " export PATH=\"\$PATH:$INSTALL_DIR\"" fi fi } # Verify installation verify() { if command -v glintlog &> /dev/null; then info "Installation successful!" echo "" glintlog version echo "" info "Get started:" echo " glintlog start -d # Start in background" echo " glintlog status # Check status" echo " glintlog help # Show all commands" else warn "Installation complete, but 'glintlog' not found in PATH" warn "You may need to restart your shell or add the install directory to PATH" fi } main() { echo "" echo " ┌─────────────────────────────────────┐" echo " │ Glintlog Installer │" echo " │ Lightweight observability tool │" echo " └─────────────────────────────────────┘" echo "" detect_platform get_latest_version install verify echo "" } main