#!/usr/bin/env bash set -e REPO_URL="https://git.rootiest.dev/rootiest/icon-color-tool.git" API_URL="https://git.rootiest.dev/api/v1/repos/rootiest/icon-color-tool/releases/latest" INSTALL_DIR="${XDG_BIN_HOME:-$HOME/.local/bin}" TMP_DIR=$(mktemp -d) trap 'rm -rf "$TMP_DIR"' EXIT BUILD=0 for arg in "$@"; do if [ "$arg" = "--build" ]; then BUILD=1 fi done echo "Installing icon-color-tool..." if [ "$BUILD" -eq 1 ]; then echo "Mode: Building from source" if ! command -v cargo &> /dev/null; then echo "Error: 'cargo' (Rust) is required to build from source." exit 1 fi if ! command -v git &> /dev/null; then echo "Error: 'git' is required to clone the repository." exit 1 fi git clone --depth 1 "$REPO_URL" "$TMP_DIR/repo" cd "$TMP_DIR/repo" echo "Building release binary..." cargo build --release cp target/release/icon-color-tool "$TMP_DIR/icon-color-tool" cd - > /dev/null else echo "Mode: Downloading pre-built binary" DOWNLOAD_URL=$(curl -sL "$API_URL" | grep -o '"browser_download_url":"[^"]*"' | cut -d'"' -f4 | head -n 1) if [ -z "$DOWNLOAD_URL" ]; then echo "Error: Could not find latest release binary download URL." echo "If the release doesn't exist yet, you can use the --build flag to build from source." exit 1 fi if ! curl -sfL "$DOWNLOAD_URL" -o "$TMP_DIR/icon-color-tool"; then echo "Error: Failed to download binary from $DOWNLOAD_URL" exit 1 fi fi mkdir -p "$INSTALL_DIR" cp "$TMP_DIR/icon-color-tool" "$INSTALL_DIR/icon-color-tool" chmod +x "$INSTALL_DIR/icon-color-tool" echo "Successfully installed to $INSTALL_DIR/icon-color-tool" if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then echo "" echo "WARNING: $INSTALL_DIR is not in your PATH." echo "To run 'icon-color-tool' globally, add this directory to your PATH." echo "For example, add the following line to your ~/.bashrc or ~/.zshrc:" echo " export PATH=\"\$PATH:$INSTALL_DIR\"" fi