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. azd present + version29if ! command -v azd >/dev/null 2>&1; then30note_action "Azure Developer CLI (azd) is not installed. Install it from https://aka.ms/azd-install, then re-run."31echo ""32echo "Summary: azd missing -- cannot continue."33exit 134fi3536AZD_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)"37note_ok "azd installed (version ${AZD_VERSION})."3839# 2. Required extensions40EXT_JSON="$(azd extension list --output json 2>/dev/null || echo '[]')"41for ext in azure.ai.agents azure.ai.projects; do42if printf '%s' "$EXT_JSON" | grep -q "$ext"; then43note_ok "Extension '$ext' is installed."44else45note_action "Extension '$ext' is missing. Run: azd extension install $ext"46fi47done4849# 3. Auth status50if azd auth login --check-status >/dev/null 2>&1; then51note_ok "Logged in to azd."52else53note_action "Not logged in. Ask the user to run 'azd auth login' (it opens a browser; never run it for them)."54fi5556# 4. Foundry project endpoint (optional at this stage)57# Short-circuit when there's no azd project in cwd: `azd ai project show` / `agent show`58# would just return nothing after a ~3s subprocess each.59if [ ! -f "azure.yaml" ]; then60note_warn "No Foundry project endpoint set yet. A new project will be created at provision/deploy time, or supply an existing project resource ID."61note_ok "No agent deployed yet. Proceed with create."62else63PROJECT_JSON="$(azd ai project show --output json 2>/dev/null || echo '')"64ENDPOINT=""65if [ -n "$PROJECT_JSON" ]; then66ENDPOINT="$(printf '%s' "$PROJECT_JSON" | python3 -c 'import json,sys67try:68d=json.load(sys.stdin)69except Exception:70print(""); raise SystemExit71if isinstance(d,dict):72for k in ("endpoint","projectEndpoint","aiProjectEndpoint"):73if d.get(k):74print(d[k]); break75' 2>/dev/null)"76fi77if [ -n "$ENDPOINT" ]; then78note_ok "Foundry project endpoint configured: ${ENDPOINT}"79else80note_warn "No Foundry project endpoint set yet. A new project will be created at provision/deploy time, or supply an existing project resource ID."81fi8283# 5. Agent deployment status84AGENT_JSON="$(azd ai agent show --output json 2>/dev/null || echo '')"85if [ -n "$AGENT_JSON" ]; then86STATUS="$(printf '%s' "$AGENT_JSON" | python3 -c 'import json,sys87try:88d=json.load(sys.stdin)89except Exception:90print("unknown"); raise SystemExit91print(d.get("status","unknown") if isinstance(d,dict) else "unknown")' 2>/dev/null)"92case "$STATUS" in93active|deployed) note_ok "An agent is already deployed (status: ${STATUS}). Skip to deploy.md to redeploy, or tools to add a tool." ;;94not_deployed) note_ok "No agent deployed yet (status: not_deployed). Proceed with create." ;;95*) note_warn "Agent status: ${STATUS}." ;;96esac97else98note_ok "No agent deployed yet. Proceed with create."99fi100fi101102echo ""103if [ "$ACTION_REQUIRED" -eq 1 ]; then104echo "Summary: action required -- resolve the [ACTION] items above before continuing."105exit 1106else107echo "Summary: environment ready for 'azd ai' hosted-agent creation."108exit 0109fi110