#!/bin/sh set -e REPO="Papaya-Voldemort/Lightning-Readme" BINARY_NAME="readme-gen" INSTALL_DIR="/usr/local/bin" RED='\033[0;31m' GREEN='\033[0;32m' BLUE='\033[0;34m' NC='\033[0m' printf "${BLUE}Starting installation of ${BINARY_NAME}...${NC}\n" OS_TYPE="$(uname -s | tr '[:upper:]' '[:lower:]')" case "$OS_TYPE" in linux*) OS="linux" ;; darwin*) OS="macos" ;; msys*|cygwin*|mingw*) OS="windows" ;; *) printf "${RED}Error: Unsupported OS (%s)${NC}\n" "$OS_TYPE" exit 1 ;; esac FILENAME="${BINARY_NAME}-${OS}" if [ "$OS" = "windows" ]; then FILENAME="${FILENAME}.exe" fi DOWNLOAD_URL="https://github.com/${REPO}/releases/download/latest/${FILENAME}" printf "Detecting OS: ${GREEN}${OS}${NC}\n" printf "Downloading from: ${BLUE}${DOWNLOAD_URL}${NC}\n" TMP_DIR="$(mktemp -d)" trap 'rm -rf "$TMP_DIR"' EXIT if ! curl --fail --location --silent --show-error "$DOWNLOAD_URL" -o "$TMP_DIR/$FILENAME"; then printf "${RED}Error: Failed to download binary from GitHub.${NC}\n" printf "Make sure a release exists and contains %s.\n" "$FILENAME" exit 1 fi chmod +x "$TMP_DIR/$FILENAME" if [ "$OS" = "windows" ]; then printf "${GREEN}Download complete: %s${NC}\n" "$TMP_DIR/$FILENAME" printf "Move the executable to a directory on your PATH.\n" else printf "Installing to %s...\n" "$INSTALL_DIR" if [ -w "$INSTALL_DIR" ]; then mv "$TMP_DIR/$FILENAME" "$INSTALL_DIR/$BINARY_NAME" else sudo mv "$TMP_DIR/$FILENAME" "$INSTALL_DIR/$BINARY_NAME" fi printf "${GREEN}Successfully installed %s! Try running '%s'.${NC}\n" "$BINARY_NAME" "$BINARY_NAME" fi