| #!/bin/bash |
|
|
| |
| |
|
|
| set -e |
|
|
| |
| GREEN='\033[0;32m' |
| BLUE='\033[0;34m' |
| YELLOW='\033[1;33m' |
| RED='\033[0;31m' |
| CYAN='\033[0;36m' |
| NC='\033[0m' |
|
|
| print_header() { |
| echo "" |
| echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}" |
| echo -e "${CYAN} π§ $1${NC}" |
| echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}" |
| echo "" |
| } |
|
|
| print_step() { |
| echo -e "${BLUE}π¦ Step $1: $2${NC}" |
| } |
|
|
| print_success() { |
| echo -e "${GREEN}β
$1${NC}" |
| } |
|
|
| print_warning() { |
| echo -e "${YELLOW}β οΈ $1${NC}" |
| } |
|
|
| print_error() { |
| echo -e "${RED}β $1${NC}" |
| } |
|
|
| |
| print_header "Tinker - Autonomous Arbitrage Agent Setup" |
|
|
| echo "This script will guide you through the complete setup process." |
| echo "" |
|
|
| |
| print_step "1" "Checking Node.js installation" |
| if command -v node &> /dev/null; then |
| NODE_VERSION=$(node -v) |
| print_success "Node.js is installed: $NODE_VERSION" |
| else |
| print_error "Node.js is not installed" |
| echo "Install it from: https://nodejs.org" |
| echo "Or use: brew install node" |
| exit 1 |
| fi |
|
|
| |
| print_step "2" "Installing dependencies" |
| if [ -d "node_modules" ] && [ -f "node_modules/.package-lock.json" ]; then |
| print_success "Dependencies already installed" |
| else |
| print_warning "Installing dependencies (this may take a few minutes)..." |
| echo "" |
| echo "Choose your package manager:" |
| echo " 1) npm install --legacy-peer-deps (recommended)" |
| echo " 2) pnpm install (faster)" |
| echo " 3) yarn install" |
| echo "" |
| read -p "Select (1-3) [default: 1]: " choice |
| |
| case $choice in |
| 2) |
| echo "Running: pnpm install" |
| pnpm install |
| ;; |
| 3) |
| echo "Running: yarn install" |
| yarn install |
| ;; |
| *) |
| echo "Running: npm install --legacy-peer-deps" |
| npm install --legacy-peer-deps |
| ;; |
| esac |
| |
| if [ $? -eq 0 ]; then |
| print_success "Dependencies installed successfully" |
| else |
| print_error "Dependency installation failed" |
| echo "Try: npm install --legacy-peer-deps --force" |
| exit 1 |
| fi |
| fi |
|
|
| |
| print_step "3" "Setting up environment variables" |
| if [ -f ".env.local" ]; then |
| print_success ".env.local already exists" |
| else |
| print_warning "Creating .env.local from template..." |
| cp .env.example .env.local |
| print_success ".env.local created" |
| echo "" |
| print_warning "IMPORTANT: Edit .env.local with your configuration" |
| echo "At minimum, set:" |
| echo " - DATABASE_URL (PostgreSQL connection string)" |
| echo " - NEXTAUTH_SECRET (random string for session encryption)" |
| echo "" |
| read -p "Open .env.local for editing now? (y/n) [y]: " edit_env |
| |
| if [ "$edit_env" != "n" ]; then |
| ${EDITOR:-nano} .env.local |
| fi |
| fi |
|
|
| |
| print_step "4" "Setting up PostgreSQL" |
| if command -v psql &> /dev/null; then |
| print_success "PostgreSQL is installed" |
| |
| if pg_isready &> /dev/null; then |
| print_success "PostgreSQL is running" |
| else |
| print_warning "PostgreSQL is not running. Starting..." |
| brew services start postgresql@15 2>/dev/null || { |
| print_error "Failed to start PostgreSQL" |
| echo "Try: brew services start postgresql@15" |
| exit 1 |
| } |
| sleep 3 |
| fi |
| else |
| print_warning "PostgreSQL is not installed" |
| echo "" |
| echo "Install it with:" |
| echo " brew install postgresql@15" |
| echo " brew services start postgresql@15" |
| echo "" |
| read -p "Continue anyway? (y/n) [n]: " continue_pg |
| |
| if [ "$continue_pg" != "y" ]; then |
| exit 1 |
| fi |
| fi |
|
|
| |
| print_step "5" "Setting up database" |
| print_warning "Creating database 'tinker_agent'..." |
| createdb tinker_agent 2>/dev/null || print_success "Database already exists" |
|
|
| echo "" |
| print_warning "Generating Prisma client..." |
| npx prisma generate |
|
|
| echo "" |
| print_warning "Running database migrations..." |
| npx prisma migrate dev --name init |
|
|
| if [ $? -eq 0 ]; then |
| print_success "Database setup complete" |
| else |
| print_error "Database migration failed" |
| echo "Check your DATABASE_URL in .env.local" |
| exit 1 |
| fi |
|
|
| |
| print_step "6" "Setting up Ollama (AI Agent)" |
| if command -v ollama &> /dev/null; then |
| print_success "Ollama is installed" |
| |
| if curl -s http://localhost:11434/api/tags &> /dev/null; then |
| print_success "Ollama service is running" |
| else |
| print_warning "Starting Ollama service..." |
| ollama serve &>/dev/null & |
| sleep 3 |
| fi |
| |
| print_warning "Checking for required models..." |
| ollama list | grep -q "llama3.1" || { |
| print_warning "Pulling llama3.1 model (this may take a while)..." |
| ollama pull llama3.1:8b-instruct-q4_K_M |
| } |
| |
| ollama list | grep -q "nomic-embed-text" || { |
| print_warning "Pulling nomic-embed-text model..." |
| ollama pull nomic-embed-text |
| } |
| |
| print_success "Ollama setup complete" |
| else |
| print_warning "Ollama is not installed" |
| echo "" |
| echo "The agent can run without Ollama, but AI features will be limited." |
| echo "" |
| echo "To install Ollama:" |
| echo " curl -fsSL https://ollama.com/install.sh | sh" |
| echo "" |
| read -p "Continue without Ollama? (y/n) [y]: " skip_ollama |
| |
| if [ "$skip_ollama" = "n" ]; then |
| echo "" |
| echo "Install Ollama and run:" |
| echo " ollama serve" |
| echo " ollama pull llama3.1:8b-instruct-q4_K_M" |
| echo "" |
| fi |
| fi |
|
|
| |
| print_step "7" "Verifying installation" |
| echo "" |
|
|
| ERRORS=0 |
|
|
| if [ ! -d "node_modules" ]; then |
| print_error "node_modules not found" |
| ERRORS=$((ERRORS + 1)) |
| else |
| print_success "Dependencies installed" |
| fi |
|
|
| if [ ! -f ".env.local" ]; then |
| print_error ".env.local not found" |
| ERRORS=$((ERRORS + 1)) |
| else |
| print_success "Environment configured" |
| fi |
|
|
| if command -v npx &> /dev/null && npx next --version &> /dev/null; then |
| print_success "Next.js is available" |
| else |
| print_warning "Next.js might not be properly installed" |
| ERRORS=$((ERRORS + 1)) |
| fi |
|
|
| if [ $ERRORS -gt 0 ]; then |
| echo "" |
| print_error "Found $ERRORS issue(s). Please fix them before continuing." |
| exit 1 |
| fi |
|
|
| echo "" |
| print_success "All checks passed!" |
|
|
| |
| print_step "8" "Building production bundle" |
| echo "" |
| read -p "Run production build? (y/n) [y]: " do_build |
|
|
| if [ "$do_build" != "n" ]; then |
| npm run build |
| |
| if [ $? -eq 0 ]; then |
| print_success "Production build successful" |
| else |
| print_error "Build failed" |
| echo "Check the error messages above" |
| exit 1 |
| fi |
| fi |
|
|
| |
| print_header "Setup Complete! π" |
|
|
| echo -e "${GREEN}Your Tinker agent is ready to run!${NC}" |
| echo "" |
| echo -e "${BLUE}To start all services:${NC}" |
| echo " ./start.sh --dev" |
| echo "" |
| echo -e "${BLUE}Or start services individually:${NC}" |
| echo " Terminal 1: npm run dev (Next.js web server)" |
| echo " Terminal 2: npm run dev:socket (WebSocket server)" |
| echo " Terminal 3: npm run agent:worker (Agent worker)" |
| echo "" |
| echo -e "${BLUE}Access points:${NC}" |
| echo " π Dashboard: http://localhost:3000" |
| echo " π‘ WebSocket: ws://localhost:3001" |
| echo " π API: http://localhost:3000/api" |
| echo "" |
| echo -e "${BLUE}For mobile access:${NC}" |
| echo " lt --port 3000 --subdomain tinker" |
| echo "" |
| echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}" |
| echo -e "${CYAN} Happy Tinkering! π§${NC}" |
| echo -e "${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}" |
| echo "" |
|
|