forked from coinbase/x402
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·196 lines (171 loc) · 5.53 KB
/
setup.sh
File metadata and controls
executable file
·196 lines (171 loc) · 5.53 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
set -e
# Parse command line arguments
INCLUDE_LEGACY=false
VERBOSE=false
for arg in "$@"; do
case $arg in
--legacy)
INCLUDE_LEGACY=true
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
-h|--help)
echo "Usage: ./setup.sh [options]"
echo ""
echo "Runs install.sh and build.sh for all e2e components"
echo ""
echo "Options:"
echo " --legacy Include legacy (v1) implementations"
echo " -v, --verbose Show detailed output"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " ./setup.sh # Setup v2 implementations only"
echo " ./setup.sh --legacy # Setup v2 and legacy"
echo " ./setup.sh --legacy -v # Setup with verbose output"
exit 0
;;
esac
done
echo "🚀 X402 E2E Setup"
echo "=================="
echo ""
if [ "$INCLUDE_LEGACY" = true ]; then
echo "📚 Including legacy (v1) implementations"
echo ""
fi
# Track results
TOTAL=0
SUCCESS=0
FAILED=0
FAILED_COMPONENTS=()
# Function to setup a component
setup_component() {
local dir=$1
local name=$(basename "$dir")
local type=$2
TOTAL=$((TOTAL + 1))
echo ""
echo "📦 $type: $name"
local component_success=true
# Run install.sh if it exists
if [ -f "$dir/install.sh" ]; then
if [ "$VERBOSE" = true ]; then
if (cd "$dir" && bash install.sh); then
echo " ✅ Install completed"
else
echo " ❌ Install failed"
component_success=false
fi
else
if (cd "$dir" && bash install.sh) > /dev/null 2>&1; then
echo " ✅ Install completed"
else
echo " ❌ Install failed"
echo " 💡 Run with -v for detailed output"
component_success=false
fi
fi
fi
# Run build.sh if it exists
if [ -f "$dir/build.sh" ]; then
if [ "$VERBOSE" = true ]; then
if (cd "$dir" && bash build.sh); then
echo " ✅ Build completed"
else
echo " ❌ Build failed"
component_success=false
fi
else
if (cd "$dir" && bash build.sh) > /dev/null 2>&1; then
echo " ✅ Build completed"
else
echo " ❌ Build failed"
echo " 💡 Run with -v for detailed output"
component_success=false
fi
fi
fi
if [ "$component_success" = true ]; then
SUCCESS=$((SUCCESS + 1))
else
FAILED=$((FAILED + 1))
FAILED_COMPONENTS+=("$type/$name")
fi
}
# Function to process directory (with optional recursion for nested structures)
process_directory() {
local base_dir=$1
local type=$2
local recurse_into=${3:-""}
if [ ! -d "$base_dir" ]; then
return
fi
for dir in "$base_dir"/*; do
if [ -d "$dir" ] && [ ! "$(basename "$dir")" = "node_modules" ]; then
local basename=$(basename "$dir")
# Handle special nested directories (external-proxies, local)
if [ "$basename" = "$recurse_into" ] || [ "$basename" = "local" ]; then
# Recurse into nested directory
process_directory "$dir" "$type" ""
continue
fi
# Check if component has install.sh or build.sh
if [ -f "$dir/install.sh" ] || [ -f "$dir/build.sh" ]; then
setup_component "$dir" "$type"
fi
fi
done
}
echo "======================================================="
echo "Starting Setup Process"
echo "======================================================="
# Setup servers
process_directory "servers" "server"
# Setup clients
process_directory "clients" "client"
# Setup facilitators (including external-proxies and local subdirectories)
process_directory "facilitators" "facilitator" "external-proxies"
# Setup legacy if requested
if [ "$INCLUDE_LEGACY" = true ]; then
process_directory "legacy/servers" "server"
process_directory "legacy/clients" "client"
process_directory "legacy/facilitators" "facilitator"
fi
# Print summary
echo ""
echo ""
echo "═══════════════════════════════════════════════════════"
echo " Setup Summary"
echo "═══════════════════════════════════════════════════════"
echo "✅ Successful: $SUCCESS"
echo "❌ Failed: $FAILED"
echo "📈 Total: $TOTAL"
if [ $FAILED -gt 0 ]; then
echo ""
echo "❌ FAILED COMPONENTS:"
for component in "${FAILED_COMPONENTS[@]}"; do
echo " • $component"
done
echo ""
echo "═══════════════════════════════════════════════════════"
echo "❌ Setup completed with errors"
echo "═══════════════════════════════════════════════════════"
echo ""
exit 1
else
echo ""
echo "═══════════════════════════════════════════════════════"
echo "✅ All setup tasks completed successfully!"
echo "═══════════════════════════════════════════════════════"
echo ""
echo "💡 You can now run: pnpm test"
if [ "$INCLUDE_LEGACY" = false ]; then
echo " Or with legacy: pnpm test --legacy"
fi
echo ""
fi