#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
IMAGE="${FLUTTER_DOCKER_IMAGE:-ghcr.io/cirruslabs/flutter:stable}"
OUT_DIR="$ROOT_DIR/.tools/android-platform-tools"

mkdir -p "$OUT_DIR"

docker run --rm \
  -v "$OUT_DIR:/out" \
  "$IMAGE" \
  sh -lc '
    set -e
    adb_path="$(command -v adb)"
    cp "$adb_path" /out/adb
    chmod 755 /out/adb
  '

"$OUT_DIR/adb" version
