-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·134 lines (112 loc) · 3.42 KB
/
setup.sh
File metadata and controls
executable file
·134 lines (112 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")" && pwd)"
usage() {
cat <<EOF
Usage: ./setup.sh <example-folder> [--run]
Sets up a Fetch.ai Innovation Lab example for local development.
Arguments:
<example-folder> Name of the example folder (e.g. fetch-hackathon-quickstarter)
--run Automatically run the agent after setup (optional)
Examples:
./setup.sh fetch-hackathon-quickstarter
./setup.sh gemini-quickstart/01-basic-gemini-agent --run
./setup.sh fet-example
What this script does:
1. Validates the example folder exists
2. Creates a Python virtual environment (.venv)
3. Installs dependencies from requirements.txt
4. Copies .env.example to .env (if present and .env doesn't exist)
5. Prints instructions to run the agent
EOF
exit 1
}
if [[ $# -lt 1 ]]; then
echo "Error: No example folder specified."
echo ""
usage
fi
EXAMPLE="$1"
AUTO_RUN="${2:-}"
EXAMPLE_DIR="$REPO_ROOT/$EXAMPLE"
if [[ ! -d "$EXAMPLE_DIR" ]]; then
echo "Error: Example folder '$EXAMPLE' not found."
echo ""
echo "Available examples:"
for dir in "$REPO_ROOT"/*/; do
dirname="$(basename "$dir")"
[[ "$dirname" == .* || "$dirname" == docs || "$dirname" == .github ]] && continue
if [[ -f "$dir/requirements.txt" ]] || [[ -f "$dir/agent.py" ]] || [[ -f "$dir/main.py" ]]; then
echo " $dirname"
fi
done
exit 1
fi
echo "=== Fetch.ai Innovation Lab Setup ==="
echo "Example: $EXAMPLE"
echo ""
cd "$EXAMPLE_DIR"
PYTHON_CMD=""
for cmd in python3 python; do
if command -v "$cmd" &>/dev/null; then
version=$("$cmd" --version 2>&1 | grep -oE '[0-9]+\.[0-9]+')
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
if [[ "$major" -ge 3 ]] && [[ "$minor" -ge 10 ]]; then
PYTHON_CMD="$cmd"
break
fi
fi
done
if [[ -z "$PYTHON_CMD" ]]; then
echo "Error: Python 3.10+ is required but not found."
echo "Install Python from https://www.python.org/downloads/"
exit 1
fi
echo "[1/4] Using $($PYTHON_CMD --version)"
if [[ ! -d ".venv" ]]; then
echo "[2/4] Creating virtual environment..."
$PYTHON_CMD -m venv .venv
else
echo "[2/4] Virtual environment already exists."
fi
source .venv/bin/activate
if [[ -f "requirements.txt" ]]; then
echo "[3/4] Installing dependencies..."
pip install -q --upgrade pip
pip install -q -r requirements.txt
else
echo "[3/4] No requirements.txt found — skipping dependency install."
fi
if [[ -f ".env.example" ]] && [[ ! -f ".env" ]]; then
cp .env.example .env
echo "[4/4] Created .env from .env.example — edit it with your API keys."
elif [[ -f ".env" ]]; then
echo "[4/4] .env already exists — skipping."
else
echo "[4/4] No .env.example found — no environment variables needed."
fi
ENTRY_FILE=""
for candidate in agent.py main.py workflow.py app.py; do
if [[ -f "$candidate" ]]; then
ENTRY_FILE="$candidate"
break
fi
done
echo ""
echo "=== Setup Complete ==="
echo ""
echo "To activate the environment:"
echo " cd $EXAMPLE && source .venv/bin/activate"
echo ""
if [[ -n "$ENTRY_FILE" ]]; then
if [[ "$AUTO_RUN" == "--run" ]]; then
echo "Starting agent..."
$PYTHON_CMD "$ENTRY_FILE"
else
echo "To run the agent:"
echo " python $ENTRY_FILE"
fi
else
echo "Check the example's README.md for run instructions."
fi