#!/bin/sh set -eu BASE_URL="https://install.adamohq.com" BINARY_NAME="adamo-network" die() { printf 'Error: %s\n' "$1" >&2; exit 1; } # ── Detect platform ────────────────────────────────────────────────────── ARCH=$(uname -m) OS=$(uname -s) case "$OS" in Linux) OS_TAG="linux" ;; *) die "Unsupported OS: $OS (only Linux is currently supported)" ;; esac case "$ARCH" in aarch64|arm64) ARCH_TAG="aarch64" ;; x86_64) ARCH_TAG="x86_64" ;; *) die "Unsupported architecture: $ARCH" ;; esac BINARY_URL="${BASE_URL}/bin/${BINARY_NAME}-${ARCH_TAG}-${OS_TAG}" # ── Parse args ─────────────────────────────────────────────────────────── API_KEY="" ROBOT_NAME="" PASSTHROUGH_ARGS="" while [ $# -gt 0 ]; do case "$1" in --api-key) API_KEY="$2"; shift 2 ;; --api-key=*) API_KEY="${1#*=}"; shift ;; --robot-name) ROBOT_NAME="$2"; shift 2 ;; --robot-name=*) ROBOT_NAME="${1#*=}"; shift ;; *) PASSTHROUGH_ARGS="$PASSTHROUGH_ARGS $1"; shift ;; esac done if [ -z "$API_KEY" ]; then die "--api-key is required. Usage: curl -sL $BASE_URL | bash -s -- --api-key ak_xxx --robot-name my-bot" fi if [ -z "$ROBOT_NAME" ]; then die "--robot-name is required. Usage: curl -sL $BASE_URL | bash -s -- --api-key ak_xxx --robot-name my-bot" fi # ── Set up project directory ───────────────────────────────────────────── PROJECT_DIR="$HOME/adamo-robot" if [ ! -d "$PROJECT_DIR" ]; then printf 'Creating project directory at %s...\n' "$PROJECT_DIR" mkdir -p "$PROJECT_DIR" fi cd "$PROJECT_DIR" # Initialize git repo if not already one if [ ! -d .git ]; then if command -v git >/dev/null 2>&1; then git init -q printf '# %s\n\nAdamo robot configuration for `%s`.\n\nLaunched with:\n```bash\ncd %s && adamo-network --config config.yaml\n```\n' \ "$ROBOT_NAME" "$ROBOT_NAME" "$PROJECT_DIR" > README.md printf 'target/\n' > .gitignore git add -A && git commit -q -m "Initial adamo-robot setup" printf 'Initialized git repo at %s\n' "$PROJECT_DIR" fi fi # ── Generate config.yaml ──────────────────────────────────────────────── CONFIG_FILE="$PROJECT_DIR/config.yaml" if [ -f "$CONFIG_FILE" ]; then printf 'Config already exists at %s, skipping generation.\n' "$CONFIG_FILE" else printf 'Generating %s...\n' "$CONFIG_FILE" cat > "$CONFIG_FILE" << YAML api_key: "${API_KEY}" robot_name: "${ROBOT_NAME}" ros: enabled: true backend: "ros2dds" auto_start_bridge: true control: enabled: true # Video tracks can be configured here or from the frontend. # Example: # video_tracks: # - name: "front-camera" # source_type: "jetson_argus" # encoder: "nvv4l2h264enc" # bitrate: 2000 # fps: 30 YAML if command -v git >/dev/null 2>&1 && [ -d .git ]; then git add config.yaml && git commit -q -m "Add config.yaml" fi fi # ── Download binary ────────────────────────────────────────────────────── INSTALL_DIR="${INSTALL_DIR:-/usr/local/bin}" TMP=$(mktemp) trap 'rm -f "$TMP"' EXIT printf 'Downloading %s...\n' "$BINARY_URL" if command -v curl >/dev/null 2>&1; then curl -fsSL "$BINARY_URL" -o "$TMP" elif command -v wget >/dev/null 2>&1; then wget -qO "$TMP" "$BINARY_URL" else die "Neither curl nor wget found. Install one and try again." fi chmod +x "$TMP" # ── Install binary ────────────────────────────────────────────────────── if [ -w "$INSTALL_DIR" ]; then mv "$TMP" "${INSTALL_DIR}/${BINARY_NAME}" trap - EXIT printf 'Installed to %s/%s\n' "$INSTALL_DIR" "$BINARY_NAME" else mkdir -p "$PROJECT_DIR/bin" mv "$TMP" "$PROJECT_DIR/bin/${BINARY_NAME}" trap - EXIT INSTALL_DIR="$PROJECT_DIR/bin" printf 'Installed to %s/%s\n' "$INSTALL_DIR" "$BINARY_NAME" fi # ── Launch ─────────────────────────────────────────────────────────────── printf '\n' printf ' Project: %s\n' "$PROJECT_DIR" printf ' Config: %s\n' "$CONFIG_FILE" printf ' Binary: %s/%s\n' "$INSTALL_DIR" "$BINARY_NAME" printf '\n' printf 'Launching adamo-network...\n\n' exec "${INSTALL_DIR}/${BINARY_NAME}" --config "$CONFIG_FILE" $PASSTHROUGH_ARGS