Backup: 2025-06-07 19:48 - Script test

[Restore from backup: vip-coordinator-backup-2025-06-07-19-48-script-test]
This commit is contained in:
2025-06-07 19:48:00 +02:00
parent 8fb00ec041
commit dc4655cef4
103 changed files with 16396 additions and 6143 deletions

498
setup.sh Normal file
View File

@@ -0,0 +1,498 @@
#!/bin/bash
# VIP Coordinator - Interactive Setup Script
# This script collects configuration details and sets up everything for deployment
set -e
clear
echo "🚀 VIP Coordinator - Interactive Setup"
echo "======================================"
echo ""
echo "This script will help you set up VIP Coordinator by:"
echo " ✅ Collecting your configuration details"
echo " ✅ Generating .env file"
echo " ✅ Creating docker-compose.yml"
echo " ✅ Setting up deployment files"
echo " ✅ Providing Google OAuth setup instructions"
echo ""
# Function to prompt for input with default value
prompt_input() {
local prompt="$1"
local default="$2"
local var_name="$3"
if [ -n "$default" ]; then
read -p "$prompt [$default]: " input
if [ -z "$input" ]; then
input="$default"
fi
else
while [ -z "$input" ]; do
read -p "$prompt: " input
if [ -z "$input" ]; then
echo "This field is required. Please enter a value."
fi
done
fi
eval "$var_name='$input'"
}
# Function to generate random password
generate_password() {
openssl rand -base64 32 | tr -d "=+/" | cut -c1-25
}
echo "📋 Configuration Setup"
echo "====================="
echo ""
# Deployment type
echo "1. Deployment Type"
echo "------------------"
echo "Choose your deployment type:"
echo " 1) Local development (localhost)"
echo " 2) Production with custom domain"
echo ""
read -p "Select option [1-2]: " deployment_type
if [ "$deployment_type" = "2" ]; then
echo ""
echo "2. Domain Configuration"
echo "----------------------"
prompt_input "Enter your main domain (e.g., mycompany.com)" "" DOMAIN
prompt_input "Enter your API subdomain (e.g., api.mycompany.com)" "api.$DOMAIN" API_DOMAIN
FRONTEND_URL="https://$DOMAIN"
VITE_API_URL="https://$API_DOMAIN"
GOOGLE_REDIRECT_URI="https://$API_DOMAIN/auth/google/callback"
else
DOMAIN="localhost"
API_DOMAIN="localhost:3000"
FRONTEND_URL="http://localhost"
VITE_API_URL="http://localhost:3000"
GOOGLE_REDIRECT_URI="http://localhost:3000/auth/google/callback"
fi
echo ""
echo "3. Security Configuration"
echo "-------------------------"
DB_PASSWORD=$(generate_password)
ADMIN_PASSWORD=$(generate_password)
echo "Generated secure passwords:"
echo " Database Password: $DB_PASSWORD"
echo " Admin Password: $ADMIN_PASSWORD"
echo ""
read -p "Use these generated passwords? [Y/n]: " use_generated
if [[ $use_generated =~ ^[Nn]$ ]]; then
prompt_input "Enter database password" "" DB_PASSWORD
prompt_input "Enter admin password" "" ADMIN_PASSWORD
fi
echo ""
echo "4. Google OAuth Setup"
echo "--------------------"
echo "To set up Google OAuth:"
echo " 1. Go to https://console.cloud.google.com/"
echo " 2. Create a new project or select existing"
echo " 3. Enable Google+ API"
echo " 4. Go to Credentials → Create Credentials → OAuth 2.0 Client IDs"
echo " 5. Set application type to 'Web application'"
echo " 6. Add authorized redirect URI: $GOOGLE_REDIRECT_URI"
echo " 7. Copy the Client ID and Client Secret from Google"
echo ""
echo "⚠️ IMPORTANT: Enter the actual credentials from Google Cloud Console"
echo " - Client ID looks like: 123456789-abcdefg.apps.googleusercontent.com"
echo " - Client Secret looks like: GOCSPX-abcdefghijklmnopqrstuvwxyz"
echo ""
# Collect Google OAuth Client ID
while [ -z "$GOOGLE_CLIENT_ID" ]; do
read -p "Enter Google OAuth Client ID (from Google Cloud Console): " GOOGLE_CLIENT_ID
if [ -z "$GOOGLE_CLIENT_ID" ]; then
echo "This field is required. Please enter your Google OAuth Client ID."
fi
done
# Validate Client ID format
if [[ ! "$GOOGLE_CLIENT_ID" =~ \.apps\.googleusercontent\.com$ ]]; then
echo "⚠️ Warning: Client ID should end with '.apps.googleusercontent.com'"
echo " You entered: $GOOGLE_CLIENT_ID"
read -p "Continue anyway? [y/N]: " continue_anyway
if [[ ! $continue_anyway =~ ^[Yy]$ ]]; then
echo "Please re-run the script with the correct Google OAuth Client ID"
exit 1
fi
fi
# Collect Google OAuth Client Secret
while [ -z "$GOOGLE_CLIENT_SECRET" ]; do
read -p "Enter Google OAuth Client Secret (from Google Cloud Console): " GOOGLE_CLIENT_SECRET
if [ -z "$GOOGLE_CLIENT_SECRET" ]; then
echo "This field is required. Please enter your Google OAuth Client Secret."
fi
done
# Validate Client Secret format
if [[ ! "$GOOGLE_CLIENT_SECRET" =~ ^GOCSPX- ]]; then
echo "⚠️ Warning: Client Secret should start with 'GOCSPX-'"
echo " You entered: $GOOGLE_CLIENT_SECRET"
read -p "Continue anyway? [y/N]: " continue_anyway
if [[ ! $continue_anyway =~ ^[Yy]$ ]]; then
echo "Please re-run the script with the correct Google OAuth Client Secret"
exit 1
fi
fi
echo ""
echo "✅ OAuth credentials collected:"
echo " Client ID: $GOOGLE_CLIENT_ID"
echo " Client Secret: ${GOOGLE_CLIENT_SECRET:0:10}..."
echo ""
echo "5. Optional Configuration"
echo "------------------------"
prompt_input "Enter AviationStack API Key (optional, for flight data)" "optional" AVIATIONSTACK_API_KEY
if [ "$AVIATIONSTACK_API_KEY" = "optional" ]; then
AVIATIONSTACK_API_KEY=""
fi
# Generate .env file
echo ""
echo "📝 Generating configuration files..."
cat > .env << EOF
# VIP Coordinator Environment Configuration
# Generated by setup script on $(date)
# Database Configuration
DB_PASSWORD=$DB_PASSWORD
# Domain Configuration
DOMAIN=$DOMAIN
VITE_API_URL=$VITE_API_URL
# Google OAuth Configuration
GOOGLE_CLIENT_ID=$GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET=$GOOGLE_CLIENT_SECRET
GOOGLE_REDIRECT_URI=$GOOGLE_REDIRECT_URI
# Frontend URL
FRONTEND_URL=$FRONTEND_URL
# Admin Configuration
ADMIN_PASSWORD=$ADMIN_PASSWORD
# Flight API Configuration
AVIATIONSTACK_API_KEY=$AVIATIONSTACK_API_KEY
# Port Configuration
PORT=3000
EOF
# Generate docker-compose.yml
cat > docker-compose.yml << 'EOF'
version: '3.8'
services:
db:
image: postgres:15
environment:
POSTGRES_DB: vip_coordinator
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres-data:/var/lib/postgresql/data
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 30s
timeout: 10s
retries: 3
redis:
image: redis:7
restart: unless-stopped
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 30s
timeout: 10s
retries: 3
backend:
image: t72chevy/vip-coordinator:backend-latest
environment:
DATABASE_URL: postgresql://postgres:${DB_PASSWORD}@db:5432/vip_coordinator
REDIS_URL: redis://redis:6379
GOOGLE_CLIENT_ID: ${GOOGLE_CLIENT_ID}
GOOGLE_CLIENT_SECRET: ${GOOGLE_CLIENT_SECRET}
GOOGLE_REDIRECT_URI: ${GOOGLE_REDIRECT_URI}
FRONTEND_URL: ${FRONTEND_URL}
ADMIN_PASSWORD: ${ADMIN_PASSWORD}
PORT: 3000
ports:
- "3000:3000"
depends_on:
db:
condition: service_healthy
redis:
condition: service_healthy
restart: unless-stopped
frontend:
image: t72chevy/vip-coordinator:frontend-latest
ports:
- "80:80"
depends_on:
- backend
restart: unless-stopped
volumes:
postgres-data:
EOF
# Generate start script
cat > start.sh << 'EOF'
#!/bin/bash
echo "🚀 Starting VIP Coordinator..."
# Pull latest images
echo "📥 Pulling latest images..."
docker-compose pull
# Start services
echo "🔄 Starting services..."
docker-compose up -d
# Wait for services
echo "⏳ Waiting for services to start..."
sleep 15
# Check status
echo "📊 Service Status:"
docker-compose ps
echo ""
echo "🎉 VIP Coordinator is starting!"
echo "================================"
echo "Frontend: $FRONTEND_URL"
echo "Backend API: $VITE_API_URL"
echo ""
echo "The first user to log in will become the administrator."
EOF
chmod +x start.sh
# Generate stop script
cat > stop.sh << 'EOF'
#!/bin/bash
echo "🛑 Stopping VIP Coordinator..."
docker-compose down
echo "✅ VIP Coordinator stopped."
EOF
chmod +x stop.sh
# Generate update script
cat > update.sh << 'EOF'
#!/bin/bash
echo "🔄 Updating VIP Coordinator..."
# Pull latest images
echo "📥 Pulling latest images..."
docker-compose pull
# Restart with new images
echo "🔄 Restarting services..."
docker-compose up -d
echo "✅ VIP Coordinator updated!"
EOF
chmod +x update.sh
# Generate production nginx config if needed
if [ "$deployment_type" = "2" ]; then
cat > nginx.conf << EOF
# Nginx configuration for VIP Coordinator
# Place this in your nginx sites-available directory
# Redirect HTTP to HTTPS
server {
listen 80;
server_name $DOMAIN $API_DOMAIN;
return 301 https://\$server_name\$request_uri;
}
# Frontend
server {
listen 443 ssl http2;
server_name $DOMAIN;
# SSL configuration (update paths to your certificates)
ssl_certificate /path/to/your/cert.pem;
ssl_certificate_key /path/to/your/key.pem;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
location / {
proxy_pass http://localhost:80;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
# Backend API
server {
listen 443 ssl http2;
server_name $API_DOMAIN;
# SSL configuration (update paths to your certificates)
ssl_certificate /path/to/your/cert.pem;
ssl_certificate_key /path/to/your/key.pem;
# Security headers
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
}
}
EOF
fi
# Generate README
cat > README.md << EOF
# VIP Coordinator Deployment
This directory contains your configured VIP Coordinator deployment.
## Quick Start
\`\`\`bash
# Start the application
./start.sh
# Stop the application
./stop.sh
# Update to latest version
./update.sh
\`\`\`
## Configuration
Your configuration is stored in \`.env\`. Key details:
- **Frontend URL**: $FRONTEND_URL
- **Backend API**: $VITE_API_URL
- **Admin Password**: $ADMIN_PASSWORD
- **Database Password**: $DB_PASSWORD
## First Time Setup
1. Run \`./start.sh\` to start the application
2. Open $FRONTEND_URL in your browser
3. Click "Continue with Google" to set up your admin account
4. The first user to log in becomes the administrator
## Production Deployment
EOF
if [ "$deployment_type" = "2" ]; then
cat >> README.md << EOF
For production deployment:
1. Set up SSL certificates for your domain
2. Configure nginx using the provided \`nginx.conf\`
3. Update DNS records to point to your server
4. Ensure ports 80 and 443 are open
### SSL Setup with Let's Encrypt
\`\`\`bash
# Install certbot
sudo apt install certbot python3-certbot-nginx
# Get certificates
sudo certbot --nginx -d $DOMAIN -d $API_DOMAIN
\`\`\`
EOF
else
cat >> README.md << EOF
This is configured for local development. For production deployment, run the setup script again and choose option 2.
EOF
fi
cat >> README.md << EOF
## Management
- **View logs**: \`docker-compose logs\`
- **View specific service logs**: \`docker-compose logs backend\`
- **Check status**: \`docker-compose ps\`
- **Access database**: \`docker-compose exec db psql -U postgres vip_coordinator\`
## Support
If you encounter issues, check the logs and ensure all required ports are available.
EOF
echo ""
echo "✅ Setup completed successfully!"
echo "==============================="
echo ""
echo "Generated files:"
echo " 📄 .env - Environment configuration"
echo " 📄 docker-compose.yml - Docker services"
echo " 📄 start.sh - Start the application"
echo " 📄 stop.sh - Stop the application"
echo " 📄 update.sh - Update to latest version"
echo " 📄 README.md - Documentation"
if [ "$deployment_type" = "2" ]; then
echo " 📄 nginx.conf - Production nginx configuration"
fi
echo ""
echo "🚀 Next steps:"
echo " 1. Run: ./start.sh"
echo " 2. Open: $FRONTEND_URL"
echo " 3. Login with Google to set up your admin account"
echo ""
echo "💡 Important notes:"
echo " - Admin password: $ADMIN_PASSWORD"
echo " - Database password: $DB_PASSWORD"
echo " - Keep these passwords secure!"
echo ""
if [ "$deployment_type" = "2" ]; then
echo "🌐 Production deployment:"
echo " - Configure SSL certificates"
echo " - Set up nginx with the provided config"
echo " - Update DNS records"
echo " - See README.md for detailed instructions"
echo ""
fi
echo "🎉 VIP Coordinator is ready to deploy!"