197 lines
5.5 KiB
Bash
Executable File

#!/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