#!/bin/bash # Ferrero Automation Setup Script # Compatible with Python 3.6+ (server) and Python 3.10+ (local) set -e # Exit on error echo "==========================================" echo "Ferrero Content Scaling Automation Setup" echo "==========================================" echo "" # Detect Python version PYTHON_CMD="" if command -v python3.10 &> /dev/null; then PYTHON_CMD="python3.10" echo "✓ Found Python 3.10 (local development)" elif command -v python3.6 &> /dev/null; then PYTHON_CMD="python3.6" echo "✓ Found Python 3.6 (server compatible)" elif command -v python3 &> /dev/null; then PYTHON_VERSION=$(python3 --version | cut -d' ' -f2 | cut -d'.' -f1-2) PYTHON_CMD="python3" echo "✓ Found Python $PYTHON_VERSION" else echo "❌ Error: Python 3.6+ not found" exit 1 fi # Check Python version is >= 3.6 VERSION_CHECK=$($PYTHON_CMD -c 'import sys; print(1 if sys.version_info >= (3, 6) else 0)') if [ "$VERSION_CHECK" = "0" ]; then echo "❌ Error: Python 3.6 or higher required" exit 1 fi echo "" echo "Step 1: Creating virtual environment..." $PYTHON_CMD -m venv venv echo "Step 2: Activating virtual environment..." source venv/bin/activate echo "Step 3: Upgrading pip..." pip install --upgrade "pip<21.0" # Last version supporting Python 3.6 echo "Step 4: Installing dependencies..." pip install -r requirements.txt echo "Step 5: Creating directory structure..." mkdir -p logs mkdir -p temp/downloads mkdir -p config/environments echo "Step 6: Creating .env file..." if [ ! -f .env ]; then cat > .env << 'EOF' # Ferrero Automation Environment Variables # Copy this to .env and fill in your values # Environment (staging or production) ENV=staging # DAM Credentials DAM_BASE_URL=https://ppr.dam.ferrero.com/otmmapi DAM_AUTH_URL=https://ppr.dam.ferrero.com/otdsws/oauth2/token DAM_CLIENT_ID=otds-OLV DAM_CLIENT_SECRET=hs28LZ9ZzQ5I9rlW3P7Wwyw850OatlC1 # Box Credentials BOX_CLIENT_ID=l2atwxxq4xna7phcjr2uifm4mbah69qp BOX_CLIENT_SECRET=6XcuCQ6akpk9daE0UHaGSv3mSxWaER4l BOX_JWT_KEY_ID=n1izyn3l BOX_PASSPHRASE=971585f5fd6171428c14a7c8899af5ab BOX_ENTERPRISE_ID=43984435 # Database DB_HOST=localhost DB_PORT=5437 DB_USER=ferrero_user DB_PASSWORD=ferrero_pass_2025 # Mailgun (for email notifications) MAILGUN_API_KEY=your_mailgun_api_key MAILGUN_DOMAIN=mg.yourdomain.com # Webhook Configuration CAMPAIGN_STATUS_WEBHOOK_URL=https://your-system.com/api/campaign-status WEBHOOK_AUTH_TOKEN=your_webhook_auth_token BOX_WEBHOOK_PRIMARY_KEY=your_box_webhook_primary_key BOX_WEBHOOK_SECONDARY_KEY=your_box_webhook_secondary_key EOF echo "✓ Created .env file - PLEASE EDIT WITH YOUR CREDENTIALS" else echo "✓ .env already exists" fi echo "Step 7: Setting file permissions..." chmod +x scripts/*.py 2>/dev/null || true touch logs/a1_to_a2.log touch logs/a2_to_a3.log touch logs/errors.log echo "Step 8: Testing Python imports..." python -c "import sys; print('Python version:', sys.version)" echo "" echo "==========================================" echo "✅ Setup Complete!" echo "==========================================" echo "" echo "Next steps:" echo "1. Edit .env with your credentials" echo "2. Review config/config.yaml" echo "3. Activate venv: source venv/bin/activate" echo "4. Test DAM connection: python scripts/test_connection.py" echo "5. Run A1→A2 script: python scripts/a1_to_a2_download.py" echo ""