|
| 1 | +#!/bin/bash |
| 2 | +# Que installer script |
| 3 | +# Downloads and installs the latest release of Que |
| 4 | + |
| 5 | +set -e |
| 6 | + |
| 7 | +REPO="njenia/que" |
| 8 | +INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" |
| 9 | +BINARY_NAME="que" |
| 10 | + |
| 11 | +# Colors for output |
| 12 | +RED='\033[0;31m' |
| 13 | +GREEN='\033[0;32m' |
| 14 | +YELLOW='\033[1;33m' |
| 15 | +NC='\033[0m' # No Color |
| 16 | + |
| 17 | +# Detect OS |
| 18 | +OS=$(uname -s | tr '[:upper:]' '[:lower:]') |
| 19 | +if [[ "$OS" == "linux" ]]; then |
| 20 | + OS="linux" |
| 21 | +elif [[ "$OS" == "darwin" ]]; then |
| 22 | + OS="darwin" |
| 23 | +else |
| 24 | + echo -e "${RED}Error: Unsupported OS: $OS${NC}" |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | + |
| 28 | +# Detect architecture |
| 29 | +ARCH=$(uname -m) |
| 30 | +case $ARCH in |
| 31 | + x86_64) |
| 32 | + ARCH="amd64" |
| 33 | + ;; |
| 34 | + aarch64|arm64) |
| 35 | + ARCH="arm64" |
| 36 | + ;; |
| 37 | + *) |
| 38 | + echo -e "${RED}Error: Unsupported architecture: $ARCH${NC}" |
| 39 | + exit 1 |
| 40 | + ;; |
| 41 | +esac |
| 42 | + |
| 43 | +# Determine file extension |
| 44 | +if [[ "$OS" == "darwin" || "$OS" == "linux" ]]; then |
| 45 | + EXT="tar.gz" |
| 46 | +else |
| 47 | + EXT="zip" |
| 48 | +fi |
| 49 | + |
| 50 | +# Use the /latest/download/ endpoint which automatically redirects to the latest release |
| 51 | +DOWNLOAD_URL="https://github.com/${REPO}/releases/latest/download/que-${OS}-${ARCH}.${EXT}" |
| 52 | +VERSION="latest" |
| 53 | + |
| 54 | +if [[ -n "$VERSION" ]]; then |
| 55 | + echo -e "${GREEN}Installing Que ${VERSION} for ${OS}/${ARCH}...${NC}" |
| 56 | +else |
| 57 | + echo -e "${GREEN}Installing Que (latest) for ${OS}/${ARCH}...${NC}" |
| 58 | +fi |
| 59 | + |
| 60 | +# Create temporary directory |
| 61 | +TMP_DIR=$(mktemp -d) |
| 62 | +trap "rm -rf $TMP_DIR" EXIT |
| 63 | + |
| 64 | +# Download and extract |
| 65 | +echo -e "${YELLOW}Downloading from ${DOWNLOAD_URL}...${NC}" |
| 66 | +cd "$TMP_DIR" |
| 67 | + |
| 68 | +if command -v curl >/dev/null 2>&1; then |
| 69 | + HTTP_CODE=$(curl -sL -w "%{http_code}" -o "que.${EXT}" "$DOWNLOAD_URL" || echo "000") |
| 70 | + if [[ "$HTTP_CODE" != "200" ]]; then |
| 71 | + echo -e "${RED}Error: Failed to download (HTTP $HTTP_CODE)${NC}" |
| 72 | + if [[ -f "que.${EXT}" ]]; then |
| 73 | + echo -e "${YELLOW}Response:$(cat que.${EXT})${NC}" |
| 74 | + rm -f "que.${EXT}" |
| 75 | + fi |
| 76 | + exit 1 |
| 77 | + fi |
| 78 | +elif command -v wget >/dev/null 2>&1; then |
| 79 | + if ! wget -q -O "que.${EXT}" "$DOWNLOAD_URL"; then |
| 80 | + echo -e "${RED}Error: Failed to download${NC}" |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | +else |
| 84 | + echo -e "${RED}Error: Neither curl nor wget is installed${NC}" |
| 85 | + exit 1 |
| 86 | +fi |
| 87 | + |
| 88 | +# Verify downloaded file size |
| 89 | +FILE_SIZE=$(stat -f%z "que.${EXT}" 2>/dev/null || stat -c%s "que.${EXT}" 2>/dev/null || echo "0") |
| 90 | +if [[ "$FILE_SIZE" -lt 1000 ]]; then |
| 91 | + echo -e "${RED}Error: Downloaded file is too small (${FILE_SIZE} bytes), likely an error page${NC}" |
| 92 | + echo -e "${YELLOW}Response:$(head -c 200 que.${EXT})${NC}" |
| 93 | + rm -f "que.${EXT}" |
| 94 | + exit 1 |
| 95 | +fi |
| 96 | + |
| 97 | +# Extract |
| 98 | +if [[ "$EXT" == "tar.gz" ]]; then |
| 99 | + tar -xzf "que.${EXT}" |
| 100 | +else |
| 101 | + unzip -q "que.${EXT}" |
| 102 | +fi |
| 103 | + |
| 104 | +# Check if binary exists |
| 105 | +if [[ ! -f "$BINARY_NAME" ]]; then |
| 106 | + echo -e "${RED}Error: Binary not found after extraction${NC}" |
| 107 | + exit 1 |
| 108 | +fi |
| 109 | + |
| 110 | +# Make binary executable |
| 111 | +chmod +x "$BINARY_NAME" |
| 112 | + |
| 113 | +# Install to target directory |
| 114 | +if [[ ! -w "$INSTALL_DIR" ]]; then |
| 115 | + echo -e "${YELLOW}Note: ${INSTALL_DIR} requires sudo permissions${NC}" |
| 116 | + sudo mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" |
| 117 | +else |
| 118 | + mv "$BINARY_NAME" "$INSTALL_DIR/$BINARY_NAME" |
| 119 | +fi |
| 120 | + |
| 121 | +# Verify installation |
| 122 | +if command -v "$BINARY_NAME" >/dev/null 2>&1; then |
| 123 | + INSTALLED_VERSION=$("$BINARY_NAME" --version 2>&1 | head -n 1 || echo "unknown") |
| 124 | + echo -e "${GREEN}✓ Que installed successfully!${NC}" |
| 125 | + echo -e "${GREEN} Version: ${INSTALLED_VERSION}${NC}" |
| 126 | + echo -e "${GREEN} Location: $(which $BINARY_NAME)${NC}" |
| 127 | +else |
| 128 | + echo -e "${YELLOW}Warning: Que installed but not found in PATH${NC}" |
| 129 | + echo -e "${YELLOW} Installed to: ${INSTALL_DIR}/${BINARY_NAME}${NC}" |
| 130 | + echo -e "${YELLOW} Make sure ${INSTALL_DIR} is in your PATH${NC}" |
| 131 | +fi |
| 132 | + |
0 commit comments