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

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

OS=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)

case "$ARCH" in
    x86_64)
        ARCH="amd64"
        ;;
    aarch64|arm64)
        ARCH="arm64"
        ;;
esac

BINARY="${SCRIPT_DIR}/bin/safe-gcloud-${OS}-${ARCH}"

if [[ ! -x "$BINARY" ]]; then
    echo "ERROR: Binary not found: $BINARY" >&2
    echo "Please run 'make build' in the safe-gcloud plugin directory." >&2
    exit 1
fi

exec "$BINARY" "$@"
