#!/bin/sh set -eu BIOME_SERVER_URL="${BIOME_SERVER_URL:-__BIOME_SERVER_URL__}" BIOME_REPO_URL="${BIOME_REPO_URL:-https://github.com/algutifana/biome.git}" BIOME_RELEASE_BASE_URL="${BIOME_RELEASE_BASE_URL:-https://github.com/algutifana/biome/releases/latest/download}" INSTALL_DIR="${BIOME_INSTALL_DIR:-$HOME/.local/bin}" if [ "$BIOME_SERVER_URL" = "__BIOME_SERVER""_URL__" ]; then BIOME_SERVER_URL="" fi detect_os() { case "$(uname -s)" in Linux*) echo "linux" ;; Darwin*) echo "darwin" ;; *) echo "unknown" ;; esac } detect_arch() { case "$(uname -m)" in x86_64|amd64) echo "x86_64" ;; arm64|aarch64) echo "aarch64" ;; *) echo "unknown" ;; esac } find_bio_bin() { if [ -n "${BIO_BIN:-}" ] && [ -x "$BIO_BIN" ]; then echo "$BIO_BIN" return 0 fi if command -v bio >/dev/null 2>&1; then command -v bio return 0 fi if [ -x "$INSTALL_DIR/bio" ]; then echo "$INSTALL_DIR/bio" return 0 fi if [ -x "./target/release/bio" ]; then echo "./target/release/bio" return 0 fi if [ -x "./target/debug/bio" ]; then echo "./target/debug/bio" return 0 fi return 1 } install_bio_bin() { mkdir -p "$INSTALL_DIR" OS="$(detect_os)" ARCH="$(detect_arch)" if command -v curl >/dev/null 2>&1; then TMP_BIN="$INSTALL_DIR/bio.tmp.$$" CANDIDATES="${BIOME_RELEASE_BASE_URL%/}/bio-${OS}-${ARCH}" if [ -n "$BIOME_SERVER_URL" ]; then CANDIDATES="${BIOME_SERVER_URL%/}/downloads/bio-${OS}-${ARCH} $CANDIDATES" fi for CANDIDATE_URL in $CANDIDATES; do if curl -fsSL "$CANDIDATE_URL" -o "$TMP_BIN" 2>/dev/null && [ -s "$TMP_BIN" ]; then chmod +x "$TMP_BIN" mv "$TMP_BIN" "$INSTALL_DIR/bio" echo "$INSTALL_DIR/bio" return 0 fi rm -f "$TMP_BIN" done fi if [ -f "./Cargo.toml" ] && grep -q 'crates/cli' "./Cargo.toml" 2>/dev/null; then echo "Building bio CLI from local workspace..." >&2 cargo build --release --bin bio >&2 cp "./target/release/bio" "$INSTALL_DIR/bio" chmod +x "$INSTALL_DIR/bio" echo "$INSTALL_DIR/bio" return 0 fi echo "Error: could not download prebuilt bio binary for ${OS}-${ARCH} from ${BIOME_RELEASE_BASE_URL}." >&2 echo "Check https://github.com/algutifana/biome/releases for available platforms." >&2 return 1 } BIO_BIN="$(find_bio_bin || install_bio_bin)" PATH="$INSTALL_DIR:$PATH" export PATH IS_NON_INTERACTIVE=0 for arg in "$@"; do if [ "$arg" = "--non-interactive" ]; then IS_NON_INTERACTIVE=1 fi done if [ -n "$BIOME_SERVER_URL" ]; then if [ "$IS_NON_INTERACTIVE" -eq 0 ] && [ ! -t 0 ] && [ -r /dev/tty ]; then exec "$BIO_BIN" --server "$BIOME_SERVER_URL" setup "$@" < /dev/tty else exec "$BIO_BIN" --server "$BIOME_SERVER_URL" setup "$@" fi else if [ "$IS_NON_INTERACTIVE" -eq 0 ] && [ ! -t 0 ] && [ -r /dev/tty ]; then exec "$BIO_BIN" setup "$@" < /dev/tty else exec "$BIO_BIN" setup "$@" fi fi