Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build and deploy AI applications on Azure AI Foundry using Microsoft's model catalog and AI services
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
foundry-agent/create/scripts/verify-environment.sh
1#!/usr/bin/env bash2# verify-environment.sh3# Verifies the local environment for creating a hosted Foundry agent with `azd ai`.4# Runs all the read-only checks in one pass and prints a single concise summary,5# so the agent does not have to run (and reason over) each azd command separately.6#7# Usage:8# ./verify-environment.sh9#10# Output: human-readable summary lines, each prefixed with [OK], [WARN], or [ACTION].11# Exit code: 0 if no blocking actions, 1 if at least one [ACTION] is required.1213set -uo pipefail1415ACTION_REQUIRED=01617note_ok() { echo "[OK] $1"; }18note_warn() { echo "[WARN] $1"; }19note_action() { echo "[ACTION] $1"; ACTION_REQUIRED=1; }2021# Refresh PATH to pick up recently-installed tools (e.g. azd installed in same session)22if [ -f /etc/environment ]; then23# shellcheck disable=SC109124. /etc/environment 2>/dev/null || true25fi26hash -r 2>/dev/null || true2728# 1. Required CLIs29AZD_AVAILABLE=130AZ_AVAILABLE=13132if ! command -v azd >/dev/null 2>&1; then33note_action "Azure Developer CLI (azd) is not installed. Install it from https://aka.ms/azd-install, then re-run."34AZD_AVAILABLE=035fi3637if ! command -v az >/dev/null 2>&1; then38note_action "Azure CLI (az) is not installed. Install it from https://aka.ms/installazurecli, then re-run."39AZ_AVAILABLE=040fi4142if [ "$AZD_AVAILABLE" -eq 0 ] || [ "$AZ_AVAILABLE" -eq 0 ]; then43echo ""44echo "Summary: CLI missing -- cannot continue."45exit 146fi4748AZD_VERSION="$(azd version --output json 2>/dev/null | python3 -c 'import json,sys; print(json.load(sys.stdin).get("azd",{}).get("version","unknown"))' 2>/dev/null || echo unknown)"49note_ok "azd installed (version ${AZD_VERSION})."5051AZ_VERSION="$(az version --query '"azure-cli"' -o tsv 2>/dev/null || echo unknown)"52note_ok "Azure CLI installed (version ${AZ_VERSION})."5354# 2. Required azd extensions55EXT_JSON="$(azd extension list --output json 2>/dev/null || echo '[]')"56for ext in azure.ai.agents azure.ai.projects; do57if printf '%s' "$EXT_JSON" | grep -q "$ext"; then58note_ok "Extension '$ext' is installed."59else60note_action "Extension '$ext' is missing. Run: azd extension install $ext"61fi62done6364# 3. Auth status65AZD_AUTH_OUTPUT="$(azd auth login --check-status 2>&1)"; AZD_AUTH_EXIT=$?66if printf '%s' "$AZD_AUTH_OUTPUT" | grep -Eiq '(not[[:space:]]+logged[[:space:]]+in|not[[:space:]]+authenticated|no[[:space:]]+account|login[[:space:]]+required|please[[:space:]]+run.*azd[[:space:]]+auth[[:space:]]+login|run.*azd[[:space:]]+auth[[:space:]]+login|expired)'; then67note_action "Not logged in to azd. Ask the user to run 'azd auth login' (it opens a browser; never run it for them)."68elif printf '%s' "$AZD_AUTH_OUTPUT" | grep -Eiq '(logged[[:space:]]+in|authenticated|already[[:space:]]+logged[[:space:]]+in)'; then69note_ok "Logged in to azd."70elif [ "$AZD_AUTH_EXIT" -eq 0 ]; then71# Unrecognized output -- fall back to exit code72note_ok "Logged in to azd."73else74note_action "Unable to verify azd auth status. Ask the user to run 'azd auth login' and re-run this script."75fi7677AZ_ACCOUNT_JSON="$(az account show --output json 2>/dev/null || true)"78if [ -z "$AZ_ACCOUNT_JSON" ]; then79note_action "Not logged in to Azure CLI. Ask the user to run 'az login' (it opens a browser; never run it for them)."80else81AZ_ACCOUNT_PARSED="$(printf '%s' "$AZ_ACCOUNT_JSON" | python3 -c 'import json,sys82try:83d=json.load(sys.stdin)84except Exception:85raise SystemExit(1)86if not isinstance(d, dict):87raise SystemExit(1)88print((d.get("name") or "unknown").replace("\t", " "), d.get("state") or "", sep="\t")89' 2>/dev/null || true)"90if [ -z "$AZ_ACCOUNT_PARSED" ]; then91note_action "Unable to verify Azure CLI login status. Ask the user to run 'az login' and re-run this script."92else93IFS=$'\t' read -r AZ_SUB_NAME AZ_SUB_STATE <<< "$AZ_ACCOUNT_PARSED"94AZ_SUB_STATE="${AZ_SUB_STATE//$'\r'/}"95if [ -n "$AZ_SUB_STATE" ] && [ "$AZ_SUB_STATE" != "Enabled" ]; then96note_action "Azure CLI active subscription state is '${AZ_SUB_STATE}'. Ask the user to select an enabled subscription with 'az account set --subscription <id>'."97else98note_ok "Azure CLI logged in (subscription: ${AZ_SUB_NAME:-unknown})."99fi100fi101fi102103if [ "$ACTION_REQUIRED" -eq 1 ]; then104echo ""105echo "Summary: action required -- resolve the [ACTION] items above before continuing."106exit 1107fi108109# 4. Foundry project endpoint (optional at this stage)110# Short-circuit when there's no azd project in cwd: `azd ai project show` / `agent show`111# would just return nothing after a ~3s subprocess each.112if [ ! -f "azure.yaml" ]; then113note_warn "No Foundry project endpoint set yet. A new project will be created at provision/deploy time, or supply an existing project resource ID."114note_ok "No agent deployed yet. Proceed with create."115else116PROJECT_JSON="$(azd ai project show --output json 2>/dev/null || echo '')"117ENDPOINT=""118if [ -n "$PROJECT_JSON" ]; then119ENDPOINT="$(printf '%s' "$PROJECT_JSON" | python3 -c 'import json,sys120try:121d=json.load(sys.stdin)122except Exception:123print(""); raise SystemExit124if isinstance(d,dict):125for k in ("endpoint","projectEndpoint","aiProjectEndpoint"):126if d.get(k):127print(d[k]); break128' 2>/dev/null)"129fi130if [ -n "$ENDPOINT" ]; then131note_ok "Foundry project endpoint configured: ${ENDPOINT}"132else133note_warn "No Foundry project endpoint set yet. A new project will be created at provision/deploy time, or supply an existing project resource ID."134fi135136# 5. Agent deployment status137AGENT_JSON="$(azd ai agent show --output json 2>/dev/null || echo '')"138if [ -n "$AGENT_JSON" ]; then139STATUS="$(printf '%s' "$AGENT_JSON" | python3 -c 'import json,sys140try:141d=json.load(sys.stdin)142except Exception:143print("unknown"); raise SystemExit144print(d.get("status","unknown") if isinstance(d,dict) else "unknown")' 2>/dev/null)"145case "$STATUS" in146active|deployed) note_ok "An agent is already deployed (status: ${STATUS}). Skip to deploy.md to redeploy, or tools to add a tool." ;;147not_deployed) note_ok "No agent deployed yet (status: not_deployed). Proceed with create." ;;148*) note_warn "Agent status: ${STATUS}." ;;149esac150else151note_ok "No agent deployed yet. Proceed with create."152fi153fi154155echo ""156if [ "$ACTION_REQUIRED" -eq 1 ]; then157echo "Summary: action required -- resolve the [ACTION] items above before continuing."158exit 1159else160echo "Summary: environment ready for 'azd ai' hosted-agent creation."161exit 0162fi163