#!/bin/bash set -e # Read SDK path from config SDK_DIR=$(grep '^ftc_sdk_path' .weevil.toml | sed 's/.*= "\(.*\)"/\1/') if [ -z "$SDK_DIR" ]; then echo "Error: Could not read FTC SDK path from .weevil.toml" exit 1 fi # Parse arguments USE_USB=false USE_WIFI=false CUSTOM_IP="" WIFI_TIMEOUT=5 while [[ $# -gt 0 ]]; do case $1 in --usb) USE_USB=true; shift ;; --wifi) USE_WIFI=true; shift ;; -i|--ip) CUSTOM_IP="$2"; USE_WIFI=true; shift 2 ;; --timeout) WIFI_TIMEOUT="$2"; shift 2 ;; *) echo "Unknown option: $1"; echo "Usage: $0 [--usb|--wifi] [-i IP] [--timeout SECONDS]"; exit 1 ;; esac done echo "Building APK..." ./gradlew buildApk echo "" echo "Deploying to Control Hub..." # Check for adb if ! command -v adb &> /dev/null; then echo "Error: adb not found. Install Android SDK platform-tools." exit 1 fi # Find the APK in FTC SDK APK=$(find "$SDK_DIR" -path "*/outputs/apk/debug/*.apk" | head -1) if [ -z "$APK" ]; then echo "Error: APK not found in $SDK_DIR" exit 1 fi # Connection logic if [ "$USE_USB" = true ]; then echo "Using USB..." adb devices elif [ "$USE_WIFI" = true ]; then TARGET_IP="${CUSTOM_IP:-192.168.43.1}" echo "Connecting to $TARGET_IP..." timeout ${WIFI_TIMEOUT}s adb connect "$TARGET_IP:5555" || { echo "Failed to connect" exit 1 } else # Auto-detect if adb devices | grep -q "device$"; then echo "Using USB (auto-detected)..." else echo "Trying WiFi..." timeout ${WIFI_TIMEOUT}s adb connect "192.168.43.1:5555" || { echo "No devices found" exit 1 } fi fi echo "Installing: $APK" adb install -r "$APK" echo "" echo "✓ Deployed!"