#!/bin/bash # furt-lua/scripts/setup_env.sh # Add SMTP environment variables to existing .env (non-destructive) set -e # Colors for output GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # No Color echo -e "${GREEN}=== Furt SMTP Environment Setup ===${NC}" # Navigate to furt project root SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")" ENV_FILE="$PROJECT_ROOT/.env" echo -e "${YELLOW}Project root:${NC} $PROJECT_ROOT" echo -e "${YELLOW}Environment file:${NC} $ENV_FILE" # Check if .env exists if [ ! -f "$ENV_FILE" ]; then echo -e "${YELLOW}Creating new .env file...${NC}" cat > "$ENV_FILE" << 'EOF' # Dragons@Work Project Environment Variables # Furt SMTP Configuration for mail.dragons-at-work.de SMTP_HOST="mail.dragons-at-work.de" SMTP_PORT="465" SMTP_USERNAME="your_email@dragons-at-work.de" SMTP_PASSWORD="your_smtp_password" SMTP_FROM="noreply@dragons-at-work.de" SMTP_TO="michael@dragons-at-work.de" EOF echo -e "${GREEN}[OK] Created new .env file${NC}" echo -e "${YELLOW}[EDIT] Please edit:${NC} nano $ENV_FILE" exit 0 fi echo -e "${GREEN}[OK] Found existing .env file${NC}" # Check if SMTP variables already exist smtp_username_exists=$(grep -c "^SMTP_USERNAME=" "$ENV_FILE" 2>/dev/null || echo "0") smtp_password_exists=$(grep -c "^SMTP_PASSWORD=" "$ENV_FILE" 2>/dev/null || echo "0") if [ "$smtp_username_exists" -gt 0 ] && [ "$smtp_password_exists" -gt 0 ]; then echo -e "${GREEN}[OK] SMTP variables already configured${NC}" # Load and show current values source "$ENV_FILE" echo -e "${YELLOW}Current SMTP User:${NC} ${SMTP_USERNAME:-NOT_SET}" echo -e "${YELLOW}Current SMTP Password:${NC} ${SMTP_PASSWORD:+[CONFIGURED]}${SMTP_PASSWORD:-NOT_SET}" echo "" echo -e "${YELLOW}To update SMTP settings:${NC} nano $ENV_FILE" exit 0 fi # Add missing SMTP variables echo -e "${YELLOW}Adding SMTP configuration to existing .env...${NC}" # Add section header if not present if ! grep -q "SMTP_" "$ENV_FILE" 2>/dev/null; then echo "" >> "$ENV_FILE" echo "# Furt SMTP Configuration for mail.dragons-at-work.de" >> "$ENV_FILE" fi # Add username if missing if [ "$smtp_username_exists" -eq 0 ]; then echo "SMTP_HOST=\"mail.dragons-at-work.de\"" >> "$ENV_FILE" echo "SMTP_PORT=\"465\"" >> "$ENV_FILE" echo "SMTP_USERNAME=\"your_email@dragons-at-work.de\"" >> "$ENV_FILE" echo -e "${GREEN}[OK] Added SMTP_HOST, SMTP_PORT, SMTP_USERNAME${NC}" fi # Add password if missing if [ "$smtp_password_exists" -eq 0 ]; then echo "SMTP_PASSWORD=\"your_smtp_password\"" >> "$ENV_FILE" echo "SMTP_FROM=\"noreply@dragons-at-work.de\"" >> "$ENV_FILE" echo "SMTP_TO=\"michael@dragons-at-work.de\"" >> "$ENV_FILE" echo -e "${GREEN}[OK] Added SMTP_PASSWORD, SMTP_FROM, SMTP_TO${NC}" fi echo -e "${GREEN}[OK] SMTP configuration added to .env${NC}" echo "" echo -e "${YELLOW}Next steps:${NC}" echo "1. Edit SMTP credentials: nano $ENV_FILE" echo "2. Set your actual email@dragons-at-work.de in SMTP_USERNAME" echo "3. Set your actual SMTP password in SMTP_PASSWORD" echo "4. Test with: ./scripts/start.sh" echo "" echo -e "${YELLOW}Current .env content:${NC}" echo "===================" cat "$ENV_FILE" echo "===================" echo "" echo -e "${GREEN}Ready for SMTP testing!${NC}"