Quellcode durchsuchen

feat: simplify installer to require .env file in source directory

Completely streamlined the installation process - the installer now:
- REQUIRES a .env file in the project directory (no interactive prompts)
- Shows clear error if .env file is missing
- Automatically copies entire .env to installation directory
- Displays configuration preview before installation
- Shows Qdrant/OpenRouter status after installation

Benefits:
- Zero manual configuration needed
- Consistent deployments across environments
- All settings managed in source .env file
- No risk of missing environment variables
- Clear feedback about what's configured

Usage:
1. Clone repo on production server
2. Create/edit .env file in repo directory
3. Run: sudo ./scripts/install.sh
4. Done! All settings automatically configured

Example output:
  ✓ Found .env file in source directory
  ✓ API_KEY: Uq73P0WP... (configured)
  ✓ QDRANT_ENABLED: true
  ✓ QDRANT_API_URL: http://142.93.100.6:6333/
  ✓ OPENROUTER_API_KEY: sk-or-v1-f49... (configured)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fszontagh vor 8 Monaten
Ursprung
Commit
315e431700
1 geänderte Dateien mit 58 neuen und 163 gelöschten Zeilen
  1. 58 163
      scripts/install.sh

+ 58 - 163
scripts/install.sh

@@ -21,135 +21,54 @@ ACTUAL_HOME=$(eval echo ~$ACTUAL_USER)
 INSTALL_DIR="/opt/webshop-scraper"
 SERVICE_NAME="webshop-scraper"
 
+# Get the script directory and project directory
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
+SOURCE_ENV_FILE="$PROJECT_DIR/.env"
+
 echo "Installation directory: $INSTALL_DIR"
 echo "Service name: $SERVICE_NAME"
+echo "Source directory: $PROJECT_DIR"
 echo ""
 
-# Check if application is already installed
-EXISTING_INSTALLATION=false
-EXISTING_ENV_FILE="$INSTALL_DIR/.env"
-
-if [ -f "$EXISTING_ENV_FILE" ]; then
-    EXISTING_INSTALLATION=true
-    echo "Existing installation detected!"
-    echo "Found existing configuration at: $EXISTING_ENV_FILE"
+# Check for source .env file first
+if [ -f "$SOURCE_ENV_FILE" ]; then
+    echo "✓ Found .env file in source directory: $SOURCE_ENV_FILE"
+    echo "  Using configuration from source .env file"
+    echo "  All environment variables will be automatically configured"
     echo ""
 
-    # Load existing configuration
-    source "$EXISTING_ENV_FILE" 2>/dev/null || true
-
-    # Set defaults from existing config or fallback to hardcoded defaults
-    EXISTING_API_KEY="$API_KEY"
-    EXISTING_HOST="${HOST:-0.0.0.0}"
-    EXISTING_PORT="${PORT:-3000}"
-    EXISTING_MAX_CONCURRENT_JOBS="${MAX_CONCURRENT_JOBS:-3}"
-
-    echo "Current configuration:"
-    echo "  API Key: ${EXISTING_API_KEY:0:8}... (masked)"
-    echo "  Host: $EXISTING_HOST"
-    echo "  Port: $EXISTING_PORT"
-    echo "  Max Concurrent Jobs: $EXISTING_MAX_CONCURRENT_JOBS"
+    # Load the source .env to show summary
+    source "$SOURCE_ENV_FILE" 2>/dev/null || true
+
+    echo "Configuration preview:"
+    [ -n "$API_KEY" ] && echo "  ✓ API_KEY: ${API_KEY:0:8}... (configured)"
+    [ -n "$HOST" ] && echo "  ✓ HOST: $HOST"
+    [ -n "$PORT" ] && echo "  ✓ PORT: $PORT"
+    [ -n "$QDRANT_ENABLED" ] && echo "  ✓ QDRANT_ENABLED: $QDRANT_ENABLED"
+    [ -n "$QDRANT_API_URL" ] && echo "  ✓ QDRANT_API_URL: $QDRANT_API_URL"
+    [ -n "$OPENROUTER_API_KEY" ] && echo "  ✓ OPENROUTER_API_KEY: ${OPENROUTER_API_KEY:0:15}... (configured)"
+    [ -n "$MCP_ENABLED" ] && echo "  ✓ MCP_ENABLED: $MCP_ENABLED"
     echo ""
 
-    # Ask if user wants to keep existing configuration
-    echo "Do you want to keep the existing configuration? [Y/n]:"
-    read KEEP_CONFIG
-    KEEP_CONFIG=${KEEP_CONFIG:-Y}
-
-    if [[ "$KEEP_CONFIG" =~ ^[Yy]([Ee][Ss])?$ ]]; then
-        echo "Using existing configuration..."
-        API_KEY="$EXISTING_API_KEY"
-        HOST="$EXISTING_HOST"
-        PORT="$EXISTING_PORT"
-        MAX_CONCURRENT_JOBS="$EXISTING_MAX_CONCURRENT_JOBS"
-        SKIP_CONFIG_PROMPTS=true
-    else
-        echo "Will prompt for new configuration..."
-        SKIP_CONFIG_PROMPTS=false
-    fi
-    echo ""
+    USE_SOURCE_ENV=true
+    SKIP_CONFIG_PROMPTS=true
 else
-    echo "No existing installation found. Starting fresh installation..."
+    echo "⚠ No .env file found in source directory"
+    echo "  Expected location: $SOURCE_ENV_FILE"
     echo ""
-    SKIP_CONFIG_PROMPTS=false
-fi
-
-# Configuration prompts (skip if using existing config)
-if [ "$SKIP_CONFIG_PROMPTS" != "true" ]; then
-    # Prompt for API key
-    if [ "$EXISTING_INSTALLATION" = "true" ]; then
-        echo "Enter new API key for authentication (current: ${EXISTING_API_KEY:0:8}...):"
-        echo "Press Enter to keep current API key, or enter new one:"
-        read -s NEW_API_KEY
-        if [ -n "$NEW_API_KEY" ]; then
-            API_KEY="$NEW_API_KEY"
-        else
-            API_KEY="$EXISTING_API_KEY"
-        fi
-    else
-        echo "Please enter the API key for authentication:"
-        read -s API_KEY
-    fi
+    echo "Please create a .env file in the project directory before running the installer."
+    echo "You can copy .env.example and configure it:"
+    echo "  cp .env.example .env"
+    echo "  nano .env"
     echo ""
-
-    if [ -z "$API_KEY" ]; then
-        echo "Error: API key cannot be empty"
-        exit 1
-    fi
-
-    # Prompt for host/IP address
-    echo "Enter the host/IP address to listen on:"
-    echo "  - 0.0.0.0 for all interfaces (accessible from anywhere)"
-    echo "  - 127.0.0.1 for localhost only (accessible only from this machine)"
-    echo "  - or enter a specific IP address"
-    if [ "$EXISTING_INSTALLATION" = "true" ]; then
-        echo "Current: $EXISTING_HOST, Default: $EXISTING_HOST"
-        read HOST
-        HOST=${HOST:-$EXISTING_HOST}
-    else
-        echo "Default: 0.0.0.0"
-        read HOST
-        HOST=${HOST:-0.0.0.0}
-    fi
-
-    # Prompt for port (optional)
-    if [ "$EXISTING_INSTALLATION" = "true" ]; then
-        echo "Enter the HTTP port (current: $EXISTING_PORT):"
-        read PORT
-        PORT=${PORT:-$EXISTING_PORT}
-    else
-        echo "Enter the HTTP port (default: 3000):"
-        read PORT
-        PORT=${PORT:-3000}
-    fi
-
-    # Prompt for max concurrent jobs (optional)
-    if [ "$EXISTING_INSTALLATION" = "true" ]; then
-        echo "Enter the maximum number of concurrent jobs (current: $EXISTING_MAX_CONCURRENT_JOBS):"
-        read MAX_CONCURRENT_JOBS
-        MAX_CONCURRENT_JOBS=${MAX_CONCURRENT_JOBS:-$EXISTING_MAX_CONCURRENT_JOBS}
-    else
-        echo "Enter the maximum number of concurrent jobs (default: 3):"
-        read MAX_CONCURRENT_JOBS
-        MAX_CONCURRENT_JOBS=${MAX_CONCURRENT_JOBS:-3}
-    fi
+    exit 1
 fi
 
-echo ""
-echo "Configuration:"
-echo "  Host: $HOST"
-echo "  Port: $PORT"
-echo "  Max Concurrent Jobs: $MAX_CONCURRENT_JOBS"
-echo ""
-
 # Create installation directory
 echo "Creating installation directory..."
 mkdir -p "$INSTALL_DIR"
 
-# Get the script directory (where install.sh is located)
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
-
 # Check if Node.js is installed
 if ! command -v node &> /dev/null; then
     echo "Error: Node.js is not installed. Please install Node.js first."
@@ -192,36 +111,10 @@ cd "$INSTALL_DIR"
 echo "Installing production dependencies..."
 npm install --production
 
-# Create environment file
-echo "Creating environment file..."
-
-# Check if source .env file exists
-SOURCE_ENV_FILE="$PROJECT_DIR/.env"
-
-if [ -f "$SOURCE_ENV_FILE" ]; then
-    echo "Found .env file in source directory, using it..."
-    # Copy the entire .env file from source
-    cp "$SOURCE_ENV_FILE" "$INSTALL_DIR/.env"
-    echo ".env file copied from source directory"
-else
-    # Fallback to creating from prompted values
-    cat > "$INSTALL_DIR/.env" <<EOF
-API_KEY=$API_KEY
-HOST=$HOST
-PORT=$PORT
-MAX_CONCURRENT_JOBS=$MAX_CONCURRENT_JOBS
-EOF
-    echo ".env file created with basic configuration"
-    echo ""
-    echo "NOTE: For Qdrant and OpenRouter integration, please add these variables to $INSTALL_DIR/.env:"
-    echo "  QDRANT_ENABLED=true"
-    echo "  QDRANT_API_URL=http://your-qdrant-server:6333"
-    echo "  QDRANT_API_KEY=your-qdrant-api-key"
-    echo "  OPENROUTER_API_KEY=your-openrouter-api-key"
-    echo "  MCP_ENABLED=true"
-    echo "  MCP_PORT=3001"
-    echo ""
-fi
+# Copy environment file from source
+echo "Copying environment file..."
+cp "$SOURCE_ENV_FILE" "$INSTALL_DIR/.env"
+echo "✓ Environment file copied from source to $INSTALL_DIR/.env"
 
 # Set permissions
 chmod 600 "$INSTALL_DIR/.env"
@@ -264,18 +157,11 @@ systemctl daemon-reload
 echo "Enabling service..."
 systemctl enable "$SERVICE_NAME"
 
-# Handle service startup based on existing installation
-if [ "$EXISTING_INSTALLATION" = "true" ]; then
-    # Check if service is already running
-    if systemctl is-active --quiet "$SERVICE_NAME"; then
-        echo "Service is currently running. Restarting with new configuration..."
-        systemctl restart "$SERVICE_NAME"
-    else
-        echo "Starting service..."
-        systemctl start "$SERVICE_NAME"
-    fi
+# Handle service startup
+if systemctl is-active --quiet "$SERVICE_NAME"; then
+    echo "Service is currently running. Restarting with new configuration..."
+    systemctl restart "$SERVICE_NAME"
 else
-    # Fresh installation - start service
     echo "Starting service..."
     systemctl start "$SERVICE_NAME"
 fi
@@ -283,11 +169,7 @@ fi
 # Check status
 echo ""
 echo "==================================="
-if [ "$EXISTING_INSTALLATION" = "true" ]; then
-    echo "Update completed successfully!"
-else
-    echo "Installation completed successfully!"
-fi
+echo "Installation completed successfully!"
 echo "==================================="
 echo ""
 echo "Service status:"
@@ -300,13 +182,26 @@ echo "  Restart service: sudo systemctl restart $SERVICE_NAME"
 echo "  View logs:       sudo journalctl -u $SERVICE_NAME -f"
 echo "  Check status:    sudo systemctl status $SERVICE_NAME"
 echo ""
+
+# Load .env to get actual values for display
+source "$INSTALL_DIR/.env" 2>/dev/null || true
+
 # Display appropriate URL based on host configuration
-if [ "$HOST" = "0.0.0.0" ]; then
+DISPLAY_HOST="${HOST:-localhost}"
+if [ "$DISPLAY_HOST" = "0.0.0.0" ]; then
     DISPLAY_HOST="localhost"
-else
-    DISPLAY_HOST="$HOST"
 fi
 
-echo "API is available at: http://$DISPLAY_HOST:$PORT"
-echo "Health check: http://$DISPLAY_HOST:$PORT/health"
+echo "Configuration loaded from: $SOURCE_ENV_FILE"
+echo "API is available at: http://$DISPLAY_HOST:${PORT:-3000}"
+echo "Health check: http://$DISPLAY_HOST:${PORT:-3000}/health"
+
+# Show Qdrant status if enabled
+if [ "$QDRANT_ENABLED" = "true" ]; then
+    echo ""
+    echo "Qdrant Integration: ENABLED"
+    echo "  Qdrant URL: $QDRANT_API_URL"
+    echo "  OpenRouter: ${OPENROUTER_API_KEY:+CONFIGURED}"
+    echo "  MCP Server: ${MCP_ENABLED}"
+fi
 echo ""