File size: 7,892 Bytes
f31cfe8 | 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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 | #!/bin/bash
# Tinker - Complete Setup and Run Guide
# This script walks you through the complete setup process
set -e # Exit on error
# Colors
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}"
}
# Banner
print_header "Tinker - Autonomous Arbitrage Agent Setup"
echo "This script will guide you through the complete setup process."
echo ""
# Step 1: Check Node.js
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
# Step 2: Install Dependencies
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
# Step 3: Setup Environment
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
# Step 4: Setup PostgreSQL
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
# Step 5: Setup Database
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
# Step 6: Setup Ollama (Optional)
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
# Step 7: Verify Installation
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!"
# Step 8: Build Production
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
# Final Summary
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 ""
|