-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·464 lines (405 loc) · 15.8 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·464 lines (405 loc) · 15.8 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
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#!/bin/bash
# ArgusPAM Setup Script
# This script helps you set up ArgusPAM with minimal effort
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored messages
print_header() {
echo -e "\n${BLUE}========================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}========================================${NC}\n"
}
print_success() {
echo -e "${GREEN}✓ $1${NC}"
}
print_error() {
echo -e "${RED}✗ $1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠ $1${NC}"
}
print_info() {
echo -e "${BLUE}ℹ $1${NC}"
}
# Function to generate random password
generate_password() {
openssl rand -base64 32 | tr -d "=+/" | cut -c1-32
}
# Function to generate Laravel APP_KEY
generate_app_key() {
echo "base64:$(openssl rand -base64 32)"
}
# Function to prompt for input with default
prompt_with_default() {
local prompt="$1"
local default="$2"
local result
if [ -n "$default" ]; then
read -p "$prompt [$default]: " result
echo "${result:-$default}"
else
read -p "$prompt: " result
while [ -z "$result" ]; do
print_error "This field is required."
read -p "$prompt: " result
done
echo "$result"
fi
}
# Function to prompt for password (hidden input)
prompt_password() {
local prompt="$1"
local result
read -s -p "$prompt: " result
echo >&2
while [ -z "$result" ]; do
print_error "This field is required."
read -s -p "$prompt: " result
echo >&2
done
echo "$result"
}
# Clear screen and show welcome message
clear
print_header "Welcome to ArgusPAM Setup"
echo "This script will help you configure and deploy ArgusPAM."
echo "The setup process will take about 5-10 minutes."
echo ""
echo "You will need:"
echo " • A domain name (e.g., arguspam.com)"
echo " • SMTP email credentials (for notifications)"
echo " • OpenAI API key (for AI features)"
echo ""
read -p "Press Enter to continue..."
# Check prerequisites
print_header "Checking Prerequisites"
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
print_success "Docker is installed"
if ! command -v docker compose &> /dev/null; then
print_error "Docker Compose is not installed. Please install Docker Compose first."
exit 1
fi
print_success "Docker Compose is installed"
if ! command -v openssl &> /dev/null; then
print_error "OpenSSL is not installed. Please install OpenSSL first."
exit 1
fi
print_success "OpenSSL is installed"
# Select deployment mode
print_header "Select Deployment Mode"
echo "1) Production - Full setup for live deployment"
echo "2) Development - Local development with hot-reload"
echo ""
DEPLOYMENT_MODE=$(prompt_with_default "Enter your choice (1/2)" "1")
if [ "$DEPLOYMENT_MODE" = "2" ]; then
# Development mode
print_header "Development Configuration"
# Explain mount paths
echo "⚠️ IMPORTANT: Volume Mount Paths"
echo ""
echo "Docker will mount your source code for hot-reload."
echo "Default mount paths (relative to docker-compose.yml location):"
echo " • API: ./api → /var/www/html (inside container)"
echo " • Web: ./web → /app (inside container)"
echo ""
echo "These paths work on Mac, Linux, and Windows."
echo "Press Enter to use defaults, or specify custom paths."
echo ""
# Prompt for mount paths
HOST_API_PATH=$(prompt_with_default "API mount path" "./api")
HOST_WEB_PATH=$(prompt_with_default "Web mount path" "./web")
# Create minimal .env for development
print_header "Creating Development .env File"
cat > .env << EOF
# =============================================================================
# DEVELOPMENT CONFIGURATION
# =============================================================================
# Generated by setup.sh on $(date)
# Host Volume Mounts (relative to docker-compose.yml)
HOST_API_PATH=${HOST_API_PATH}
HOST_WEB_PATH=${HOST_WEB_PATH}
# Development Ports
DEV_API_HOST_PORT=8000
DEV_WEB_HOST_PORT=3000
DEV_VITE_HMR_PORT=5173
# Development Database (use simple credentials for local dev)
DEV_DB_ROOT_PASSWORD=root
DEV_DB_DATABASE=arguspam
DEV_DB_USERNAME=arguspam
DEV_DB_PASSWORD=secret
# Development URLs
DEV_APP_URL=http://localhost:8000
DEV_APP_WEB_URL=http://localhost:3000
DEV_WEB_ORIGIN=http://localhost:3000
DEV_PUBLIC_API_URL=http://localhost:8000
# Development Settings
DEV_APP_ENV=local
DEV_APP_DEBUG=true
DEV_TELESCOPE_ENABLED=true
DEV_MAIL_MAILER=log
# CORS for local development
DEV_SANCTUM_STATEFUL_DOMAINS=localhost:3000
DEV_CORS_ALLOWED_ORIGINS=http://localhost:3000
# Note: For full configuration options, see env.template
EOF
print_success ".env file created successfully!"
echo ""
print_header "Development Setup Complete!"
echo ""
echo "To start development environment:"
echo " cd $(pwd)"
echo " docker compose up"
echo ""
echo "Your application will be available at:"
echo " • API: http://localhost:8000"
echo " • Web: http://localhost:3000"
echo ""
echo "Code changes will hot-reload automatically."
echo "See docs/QUICK_START.md for more information."
echo ""
exit 0
fi
# Continue with production setup
# Generate secure credentials
print_header "Generating Secure Credentials"
DB_ROOT_PASSWORD=$(generate_password)
DB_PASSWORD=$(generate_password)
APP_KEY=$(generate_app_key)
print_success "Generated MySQL root password"
print_success "Generated MySQL user password"
print_success "Generated Laravel application key"
# Select deployment size
print_header "Select Deployment Size"
echo "Choose the size based on your expected usage:"
echo ""
echo "1) Small - 2 CPU cores, 4GB RAM"
echo " • Suitable for: ~50-200 concurrent users"
echo " • Team size: 5-20 people"
echo " • Use case: Small startups, testing, demos"
echo ""
echo "2) Medium - 4 CPU cores, 8GB RAM (Recommended)"
echo " • Suitable for: ~200-1000 concurrent users"
echo " • Team size: 20-100 people"
echo " • Use case: Growing startups, SMEs"
echo ""
echo "3) Large - 8 CPU cores, 16GB RAM"
echo " • Suitable for: ~1000-5000 concurrent users"
echo " • Team size: 100-500 people"
echo " • Use case: Established companies, high-traffic"
echo ""
DEPLOYMENT_SIZE=$(prompt_with_default "Enter your choice (1/2/3)" "2")
case $DEPLOYMENT_SIZE in
1)
SIZE_NAME="small"
ENV_TEMPLATE="env.prod.small.example"
;;
2)
SIZE_NAME="medium"
ENV_TEMPLATE="env.prod.medium.example"
;;
3)
SIZE_NAME="large"
ENV_TEMPLATE="env.prod.large.example"
;;
*)
print_error "Invalid choice. Using medium size."
SIZE_NAME="medium"
ENV_TEMPLATE="env.prod.medium.example"
;;
esac
print_success "Selected: $SIZE_NAME deployment"
# Get domain information
print_header "Domain Configuration"
echo "Your domain should already be pointing to this server's IP address."
echo "Example: if your domain is arguspam.com, make sure:"
echo " • arguspam.com points to this server"
echo " • api.arguspam.com points to this server"
echo ""
DOMAIN=$(prompt_with_default "Enter your domain name (e.g., arguspam.com)" "localhost")
if [ "$DOMAIN" = "localhost" ]; then
print_warning "Using localhost. This is only suitable for local testing."
APP_URL="http://localhost:8000"
APP_WEB_URL="http://localhost:3000"
WEB_ORIGIN="http://localhost:3000"
PUBLIC_API_URL="http://localhost:8000"
SANCTUM_STATEFUL_DOMAINS="localhost:3000"
CORS_ALLOWED_ORIGINS="http://localhost:3000"
else
APP_URL="https://api.$DOMAIN"
APP_WEB_URL="https://$DOMAIN"
WEB_ORIGIN="https://$DOMAIN"
PUBLIC_API_URL="https://api.$DOMAIN"
SANCTUM_STATEFUL_DOMAINS="$DOMAIN"
CORS_ALLOWED_ORIGINS="https://$DOMAIN"
fi
# Get email configuration
print_header "Email Configuration (SMTP)"
echo "ArgusPAM sends notifications via email. You need SMTP credentials."
echo "Popular providers: Gmail, SendGrid, Mailgun, AWS SES"
echo ""
MAIL_HOST=$(prompt_with_default "SMTP Host (e.g., smtp.gmail.com)" "smtp.gmail.com")
MAIL_PORT=$(prompt_with_default "SMTP Port (e.g., 587)" "587")
MAIL_USERNAME=$(prompt_with_default "SMTP Username (email address)" "")
MAIL_PASSWORD=$(prompt_password "SMTP Password")
echo ""
MAIL_FROM_ADDRESS=$(prompt_with_default "From Email Address" "noreply@$DOMAIN")
MAIL_FROM_NAME=$(prompt_with_default "From Name" "ArgusPAM")
# Get OpenAI configuration
print_header "OpenAI Configuration"
echo "ArgusPAM uses OpenAI for AI-assisted security features."
echo "Get your API key from: https://platform.openai.com/api-keys"
echo ""
OPENAI_API_KEY=$(prompt_with_default "OpenAI API Key" "")
OPENAI_ORGANIZATION=$(prompt_with_default "OpenAI Organization ID (optional)" "")
OPENAI_MODEL=$(prompt_with_default "OpenAI Model" "gpt-5-nano")
# Get admin email
print_header "Administrator Configuration"
EMAIL_DEFAULT=$(prompt_with_default "Admin Email Address" "admin@$DOMAIN")
EMAIL_SUPPORT=$(prompt_with_default "Support Email Address" "support@$DOMAIN")
# Create .env file
print_header "Creating Configuration File"
cat > .env << EOF
# ArgusPAM Configuration
# Generated by setup.sh on $(date)
# IMPORTANT: Keep this file secure and do not commit to version control
# =============================================================================
# GENERATED CREDENTIALS - SAVE THESE SECURELY
# =============================================================================
DB_ROOT_PASSWORD=$DB_ROOT_PASSWORD
DB_PASSWORD=$DB_PASSWORD
APP_KEY=$APP_KEY
# =============================================================================
# DEPLOYMENT CONFIGURATION
# =============================================================================
DEPLOYMENT_SIZE=$SIZE_NAME
# =============================================================================
# DATABASE CONFIGURATION
# =============================================================================
DB_DATABASE=arguspam
DB_USERNAME=arguspam
# =============================================================================
# REDIS CONFIGURATION
# =============================================================================
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_CLIENT=predis
# =============================================================================
# APPLICATION URLS
# =============================================================================
APP_NAME=ArgusPAM
APP_ENV=production
APP_DEBUG=false
APP_URL=$APP_URL
APP_WEB_URL=$APP_WEB_URL
WEB_ORIGIN=$WEB_ORIGIN
PUBLIC_API_URL=$PUBLIC_API_URL
# =============================================================================
# SECURITY CONFIGURATION
# =============================================================================
SANCTUM_STATEFUL_DOMAINS=$SANCTUM_STATEFUL_DOMAINS
CORS_ALLOWED_ORIGINS=$CORS_ALLOWED_ORIGINS
# =============================================================================
# EMAIL CONFIGURATION
# =============================================================================
MAIL_MAILER=smtp
MAIL_HOST=$MAIL_HOST
MAIL_PORT=$MAIL_PORT
MAIL_USERNAME=$MAIL_USERNAME
MAIL_PASSWORD=$MAIL_PASSWORD
MAIL_FROM_ADDRESS=$MAIL_FROM_ADDRESS
MAIL_FROM_NAME=$MAIL_FROM_NAME
# =============================================================================
# OPENAI CONFIGURATION
# =============================================================================
OPENAI_API_KEY=$OPENAI_API_KEY
OPENAI_ORGANIZATION=$OPENAI_ORGANIZATION
OPENAI_MODEL=$OPENAI_MODEL
# =============================================================================
# ADMINISTRATOR CONFIGURATION
# =============================================================================
EMAIL_DEFAULT=$EMAIL_DEFAULT
EMAIL_SUPPORT=$EMAIL_SUPPORT
# =============================================================================
# OPTIONAL SERVICES (uncomment and configure if needed)
# =============================================================================
# SLACK_BOT_USER_OAUTH_TOKEN=
# MAXMIND_USER_ID=
# MAXMIND_LICENSE_KEY=
EOF
# Load size-specific resource limits
if [ -f "$ENV_TEMPLATE" ]; then
echo "" >> .env
echo "# =============================================================================" >> .env
echo "# RESOURCE LIMITS (${SIZE_NAME} server)" >> .env
echo "# =============================================================================" >> .env
grep -E "^(MYSQL_|REDIS_|API_|HORIZON_|WEB_).*=" "$ENV_TEMPLATE" >> .env || true
fi
print_success "Configuration file created: .env"
# Display generated credentials
print_header "IMPORTANT: Save These Credentials"
echo -e "${YELLOW}╔════════════════════════════════════════════════════════════════╗${NC}"
echo -e "${YELLOW}║ SAVE THESE CREDENTIALS IN A SECURE LOCATION ║${NC}"
echo -e "${YELLOW}╠════════════════════════════════════════════════════════════════╣${NC}"
echo -e "${YELLOW}║ ║${NC}"
echo -e "${YELLOW}║ MySQL Root Password: ║${NC}"
echo -e "${YELLOW}║ ${DB_ROOT_PASSWORD} ║${NC}"
echo -e "${YELLOW}║ ║${NC}"
echo -e "${YELLOW}║ MySQL User Password: ║${NC}"
echo -e "${YELLOW}║ ${DB_PASSWORD} ║${NC}"
echo -e "${YELLOW}║ ║${NC}"
echo -e "${YELLOW}║ Laravel APP_KEY: ║${NC}"
echo -e "${YELLOW}║ ${APP_KEY} ║${NC}"
echo -e "${YELLOW}║ ║${NC}"
echo -e "${YELLOW}╚════════════════════════════════════════════════════════════════╝${NC}"
echo ""
print_warning "These credentials are also saved in the .env file"
echo ""
read -p "Press Enter after you have saved these credentials..."
# Display next steps
print_header "Setup Complete!"
echo -e "${GREEN}Configuration has been created successfully.${NC}"
echo ""
echo "Next steps:"
echo ""
echo "1. Start ArgusPAM:"
echo -e " ${BLUE}docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d${NC}"
echo ""
echo "2. Wait for containers to be healthy (~30 seconds), then run installation:"
echo -e " ${BLUE}docker exec -it arguspam-api php artisan pam:install${NC}"
echo ""
echo " This will:"
echo " • Set up your first organization"
echo " • Create your admin user"
echo " • Configure initial settings"
echo ""
echo "3. Check if all services are running:"
echo -e " ${BLUE}docker compose ps${NC}"
echo ""
echo "4. View logs:"
echo -e " ${BLUE}docker compose logs -f${NC}"
echo ""
echo "5. Access your application:"
if [ "$DOMAIN" = "localhost" ]; then
echo -e " Web: ${BLUE}http://localhost:3000${NC}"
echo -e " API: ${BLUE}http://localhost:8000${NC}"
else
echo -e " Web: ${BLUE}https://$DOMAIN${NC}"
echo -e " API: ${BLUE}https://api.$DOMAIN${NC}"
echo ""
print_warning "Note: You'll need to set up SSL/TLS certificates for HTTPS."
echo " See docs/DEPLOYMENT.md for SSL setup instructions."
fi
echo ""
echo "6. For more information, see:"
echo -e " ${BLUE}docs/DEPLOYMENT.md${NC} - Full deployment guide"
echo -e " ${BLUE}docs/QUICK_START.md${NC} - Quick reference commands"
echo ""
print_success "Setup complete! Run the commands above to start and install ArgusPAM."