#!/bin/bash set -e echo "===================================" echo "Webshop Scraper Installation Script" echo "===================================" echo "" # Check if running as root if [ "$EUID" -ne 0 ]; then echo "Error: Please run as root (use sudo)" exit 1 fi # Get the actual user who ran sudo ACTUAL_USER=${SUDO_USER:-$USER} ACTUAL_HOME=$(eval echo ~$ACTUAL_USER) # Installation directory INSTALL_DIR="/opt/webshop-scraper" SERVICE_NAME="webshop-scraper" echo "Installation directory: $INSTALL_DIR" echo "Service name: $SERVICE_NAME" echo "" # Prompt for API key echo "Please enter the API key for authentication:" read -s API_KEY echo "" if [ -z "$API_KEY" ]; then echo "Error: API key cannot be empty" exit 1 fi # Prompt for port (optional) echo "Enter the HTTP port (default: 3000):" read PORT PORT=${PORT:-3000} # Prompt for max concurrent jobs (optional) echo "Enter the maximum number of concurrent jobs (default: 3):" read MAX_CONCURRENT_JOBS MAX_CONCURRENT_JOBS=${MAX_CONCURRENT_JOBS:-3} echo "" echo "Configuration:" echo " Port: $PORT" echo " Max Concurrent Jobs: $MAX_CONCURRENT_JOBS" echo "" # Create installation directory echo "Creating installation directory..." mkdir -p "$INSTALL_DIR" # Copy application files echo "Copying application files..." cp -r package.json tsconfig.json src "$INSTALL_DIR/" # Change to installation directory cd "$INSTALL_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." exit 1 fi # Check if npm is installed if ! command -v npm &> /dev/null; then echo "Error: npm is not installed. Please install npm first." exit 1 fi # Install dependencies echo "Installing dependencies..." npm install --production # Build TypeScript echo "Building application..." npm run build # Create environment file echo "Creating environment file..." cat > "$INSTALL_DIR/.env" < "/etc/systemd/system/$SERVICE_NAME.service" <