|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Set text colors |
| 4 | +RED='\033[0;31m' |
| 5 | +GREEN='\033[0;32m' |
| 6 | +YELLOW='\033[0;33m' |
| 7 | +NC='\033[0m' # No Color |
| 8 | + |
| 9 | +# Set the latest release version |
| 10 | +LATEST_VERSION=$(curl -s "https://api.github.com/repos/harshdoesdev/rayql/releases/latest" | grep -o '"tag_name": "v.*"' | cut -d'"' -f4) |
| 11 | + |
| 12 | +# Determine the operating system and architecture |
| 13 | +OS=$(uname -s) |
| 14 | +ARCH=$(uname -m) |
| 15 | + |
| 16 | +# Set the file extension based on the operating system |
| 17 | +if [ "$OS" = "Darwin" ]; then |
| 18 | + FILE_EXTENSION="apple-darwin.zip" |
| 19 | +elif [ "$OS" = "Linux" ]; then |
| 20 | + if [ "$ARCH" = "x86_64" ]; then |
| 21 | + FILE_EXTENSION="unknown-linux-musl.tar.gz" |
| 22 | + else |
| 23 | + echo "${RED}Unsupported architecture: $ARCH${NC}" |
| 24 | + exit 1 |
| 25 | + fi |
| 26 | +else |
| 27 | + echo "${RED}Unsupported operating system: $OS${NC}" |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Get download URL |
| 32 | +DOWNLOAD_URL=$(curl -s "https://api.github.com/repos/harshdoesdev/rayql/releases/latest" | grep -o "\"browser_download_url\": *\"[^\"]*${FILE_EXTENSION}\"" | cut -d '"' -f 4) |
| 33 | + |
| 34 | +# Print the download URL |
| 35 | +echo -e "⬇️ ${YELLOW}Downloading rayql version $LATEST_VERSION for $OS...${NC}" |
| 36 | + |
| 37 | +# Download the binary |
| 38 | +curl -LO "$DOWNLOAD_URL" |
| 39 | + |
| 40 | +# Extract the binary if it's a tarball or zip |
| 41 | +if [[ "$DOWNLOAD_URL" == *".tar.gz" ]]; then |
| 42 | + tar -xzf "rayql_${LATEST_VERSION}_${ARCH}-${OS}.${FILE_EXTENSION}" |
| 43 | + BINARY_PATH="./rayql_${LATEST_VERSION}_${ARCH}-${OS}/rayql" |
| 44 | +elif [[ "$DOWNLOAD_URL" == *".zip" ]]; then |
| 45 | + ZIP_FILE=$(basename "$DOWNLOAD_URL") |
| 46 | + unzip "$ZIP_FILE" |
| 47 | + BINARY_PATH="./rayql" |
| 48 | +else |
| 49 | + echo "${RED}Unsupported file format for extraction${NC}" |
| 50 | + exit 1 |
| 51 | +fi |
| 52 | + |
| 53 | +# Make the binary executable |
| 54 | +chmod +x "$BINARY_PATH" |
| 55 | + |
| 56 | +# Move the binary to a directory in the user's PATH |
| 57 | +echo -e "🚀 ${YELLOW}Installing rayql into /usr/local/bin...${NC}" |
| 58 | +sudo mv "$BINARY_PATH" /usr/local/bin/rayql |
| 59 | + |
| 60 | +# Check if rayql binary exists in PATH |
| 61 | +if command -v rayql &>/dev/null; then |
| 62 | + # Display installation complete message |
| 63 | + echo "" |
| 64 | + echo -e "✅ ${GREEN}rayql ${LATEST_VERSION} has been successfully installed.${NC}" |
| 65 | +else |
| 66 | + echo "${RED}❌ Error: Failed to install rayql.${NC}" |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | + |
| 70 | +# Clean up downloaded zip file |
| 71 | +rm -f "$ZIP_FILE" |
0 commit comments