Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
218 lines (187 loc) · 7.36 KB
/
Copy pathsetup.sh
File metadata and controls
218 lines (187 loc) · 7.36 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
# AgentFlow — Safe Local Setup Script
# This script NEVER uses sudo, NEVER modifies system files,
# and NEVER installs anything globally.
# ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'
BOLD='\033[1m'
echo ""
echo -e "${BLUE}${BOLD} ╔══════════════════════════════════════════════╗${NC}"
echo -e "${BLUE}${BOLD} ║ 🚀 AgentFlow — Safe Local Setup ║${NC}"
echo -e "${BLUE}${BOLD} ╚══════════════════════════════════════════════╝${NC}"
echo ""
# ── Safety Pre-flight Checks ──────────────────────────
echo -e "${BOLD}Pre-flight Safety Checks:${NC}"
echo ""
# Check we're not running as root
if [ "$(id -u)" -eq 0 ]; then
echo -e " ${RED}✗ Running as root — this script should NOT be run with sudo${NC}"
echo " Please run as your normal user: ./setup.sh"
exit 1
fi
echo -e " ${GREEN}✓ Not running as root (safe)${NC}"
# Check we're in the right directory
if [ ! -f "server.js" ] || [ ! -f "kanban.html" ] || [ ! -f "package.json" ]; then
echo -e " ${RED}✗ Missing files — run this script from the AgentFlow directory${NC}"
echo " Expected: server.js, kanban.html, package.json"
exit 1
fi
echo -e " ${GREEN}✓ AgentFlow files found${NC}"
# Check port 3000 is available
if lsof -i :3000 -sTCP:LISTEN > /dev/null 2>&1; then
echo -e " ${YELLOW}⚠ Port 3000 is already in use${NC}"
echo " You can use a different port: PORT=3001 npm start"
SUGGESTED_PORT=3001
while lsof -i :$SUGGESTED_PORT -sTCP:LISTEN > /dev/null 2>&1; do
SUGGESTED_PORT=$((SUGGESTED_PORT + 1))
done
echo -e " Suggested free port: ${BOLD}$SUGGESTED_PORT${NC}"
else
echo -e " ${GREEN}✓ Port 3000 is available${NC}"
SUGGESTED_PORT=3000
fi
# Check disk space (need at least 100MB)
AVAILABLE_MB=$(df -m . | awk 'NR==2 {print $4}')
if [ "$AVAILABLE_MB" -lt 100 ] 2>/dev/null; then
echo -e " ${RED}✗ Less than 100MB disk space available${NC}"
exit 1
fi
echo -e " ${GREEN}✓ Disk space OK (${AVAILABLE_MB}MB available)${NC}"
echo ""
# ── Detect Available Runtimes ─────────────────────────
HAS_NODE=false
HAS_DOCKER=false
NODE_VERSION=""
if command -v node &> /dev/null; then
NODE_VERSION=$(node -v 2>/dev/null)
NODE_MAJOR=$(echo "$NODE_VERSION" | sed 's/v//' | cut -d. -f1)
if [ "$NODE_MAJOR" -ge 18 ] 2>/dev/null; then
HAS_NODE=true
echo -e " ${GREEN}✓ Node.js $NODE_VERSION found (>= 18 required)${NC}"
else
echo -e " ${YELLOW}⚠ Node.js $NODE_VERSION found but >= 18 required${NC}"
fi
else
echo -e " ${YELLOW}○ Node.js not found${NC}"
fi
if command -v docker &> /dev/null; then
if docker info > /dev/null 2>&1; then
HAS_DOCKER=true
echo -e " ${GREEN}✓ Docker found and running${NC}"
else
echo -e " ${YELLOW}○ Docker found but not running${NC}"
fi
else
echo -e " ${YELLOW}○ Docker not found${NC}"
fi
echo ""
# ── Choose Deployment Method ──────────────────────────
if [ "$HAS_NODE" = true ] && [ "$HAS_DOCKER" = true ]; then
echo -e "${BOLD}Both Node.js and Docker available. Choose:${NC}"
echo " 1) Node.js (fastest, uses your local Node)"
echo " 2) Docker (most isolated, runs in a container)"
echo ""
read -p " Choice [1/2, default=1]: " CHOICE
CHOICE=${CHOICE:-1}
elif [ "$HAS_NODE" = true ]; then
CHOICE=1
elif [ "$HAS_DOCKER" = true ]; then
CHOICE=2
else
echo -e "${RED}Neither Node.js >= 18 nor Docker found.${NC}"
echo ""
echo "To install Node.js (recommended):"
echo " Option A: brew install node (if you have Homebrew)"
echo " Option B: Download from https://nodejs.org"
echo " Option C: curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash"
echo " then: nvm install 22"
echo ""
echo "To install Docker:"
echo " Download Docker Desktop from https://docker.com/products/docker-desktop"
echo ""
exit 1
fi
# ── Deploy with Node.js ──────────────────────────────
if [ "$CHOICE" = "1" ]; then
echo -e "${BOLD}Setting up with Node.js...${NC}"
echo ""
# Install dependencies (local only, no global)
echo -e " Installing dependencies (local node_modules only)..."
npm install --no-fund --no-audit 2>&1 | tail -3
echo ""
# Create data directory
mkdir -p data
echo -e " ${GREEN}✓ Data directory created (./data/)${NC}"
echo -e " ${GREEN}✓ Database will be at ./data/agentflow.db${NC}"
echo ""
# Create a simple start script
cat > start.sh << 'STARTEOF'
#!/bin/bash
cd "$(dirname "$0")"
PORT=${PORT:-3000}
echo ""
echo " Starting AgentFlow on port $PORT..."
echo " Press Ctrl+C to stop"
echo ""
node server.js
STARTEOF
chmod +x start.sh
# Create a stop script
cat > stop.sh << 'STOPEOF'
#!/bin/bash
echo "Stopping AgentFlow..."
pkill -f "node server.js" 2>/dev/null && echo " Stopped." || echo " Not running."
STOPEOF
chmod +x stop.sh
echo -e "${GREEN}${BOLD} Setup complete!${NC}"
echo ""
echo -e " ${BOLD}To start:${NC} ./start.sh"
echo -e " ${BOLD}To stop:${NC} ./stop.sh (or Ctrl+C)"
echo -e " ${BOLD}Open:${NC} http://localhost:${SUGGESTED_PORT}"
echo ""
echo -e " ${BOLD}Your data:${NC} ./data/agentflow.db (SQLite)"
echo -e " ${BOLD}To backup:${NC} cp data/agentflow.db data/agentflow-backup.db"
echo ""
# Ask if they want to start now
read -p " Start AgentFlow now? [Y/n]: " START_NOW
START_NOW=${START_NOW:-Y}
if [[ "$START_NOW" =~ ^[Yy] ]]; then
PORT=$SUGGESTED_PORT node server.js
fi
fi
# ── Deploy with Docker ───────────────────────────────
if [ "$CHOICE" = "2" ]; then
echo -e "${BOLD}Setting up with Docker...${NC}"
echo ""
# Build the image
echo " Building Docker image..."
docker build -t agentflow . 2>&1 | tail -5
echo ""
# Create data directory on host for persistence
mkdir -p data
echo -e " ${GREEN}✓ Data directory created (./data/)${NC}"
echo ""
echo -e "${GREEN}${BOLD} Setup complete!${NC}"
echo ""
echo -e " ${BOLD}To start:${NC} docker run -d --name agentflow -p ${SUGGESTED_PORT}:3000 -v \$(pwd)/data:/app/data agentflow"
echo -e " ${BOLD}To stop:${NC} docker stop agentflow && docker rm agentflow"
echo -e " ${BOLD}Open:${NC} http://localhost:${SUGGESTED_PORT}"
echo ""
echo -e " ${BOLD}Your data:${NC} ./data/agentflow.db (persisted on host)"
echo ""
# Ask if they want to start now
read -p " Start AgentFlow now? [Y/n]: " START_NOW
START_NOW=${START_NOW:-Y}
if [[ "$START_NOW" =~ ^[Yy] ]]; then
docker run -d --name agentflow -p $SUGGESTED_PORT:3000 -v "$(pwd)/data:/app/data" agentflow
echo ""
echo -e " ${GREEN}✓ AgentFlow running at http://localhost:${SUGGESTED_PORT}${NC}"
echo " View logs: docker logs -f agentflow"
fi
fi