#!/usr/bin/env bash set -euo pipefail # GyanDoot v2.0 — Cross-platform installer # Detects OS, architecture, and installs the gyandoot binary. GREEN='\033[0;32m' BLUE='\033[0;34m' RED='\033[0;31m' NC='\033[0m' info() { echo -e "${BLUE}[INFO]${NC} $*"; } ok() { echo -e "${GREEN}[OK]${NC} $*"; } err() { echo -e "${RED}[ERR]${NC} $*" >&2; exit 1; } detect_architecture() { local arch arch="$(uname -m)" case "$arch" in x86_64|amd64) echo "x86_64" ;; aarch64|arm64) echo "aarch64" ;; *) err "Unsupported architecture: $arch" ;; esac } detect_os() { local os os="$(uname -s)" case "$os" in Linux) echo "linux" ;; Darwin) echo "darwin" ;; CYGWIN*|MINGW*|MSYS*) echo "windows" ;; *) err "Unsupported OS: $os" ;; esac } install_rust_if_needed() { if ! command -v cargo &>/dev/null; then info "Rust toolchain not found. Installing..." curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y source "$HOME/.cargo/env" ok "Rust installed" else ok "Rust already installed ($(cargo --version))" fi } build_release() { local root_dir root_dir="$(cd "$(dirname "$0")" && pwd)" info "Building GyanDoot v2.0 in release mode..." cd "$root_dir" cargo build --release ok "Build complete" } install_binary() { local root_dir root_dir="$(cd "$(dirname "$0")" && pwd)" local target_dir="$root_dir/target/release" local bin_name="gyandoot" if [ ! -f "$target_dir/$bin_name" ]; then err "Binary not found at $target_dir/$bin_name" fi local install_dir="/usr/local/bin" if [ ! -w "$install_dir" ]; then info "Need sudo to install to $install_dir" sudo cp "$target_dir/$bin_name" "$install_dir/$bin_name" sudo chmod +x "$install_dir/$bin_name" else cp "$target_dir/$bin_name" "$install_dir/$bin_name" chmod +x "$install_dir/$bin_name" fi ok "Installed to $install_dir/$bin_name" } main() { local os arch os=$(detect_os) arch=$(detect_architecture) info "Detected: $os / $arch" install_rust_if_needed build_release install_binary echo "" ok "GyanDoot v2.0 installed successfully!" echo "Run 'gyandoot --help' to get started." } main "$@"