#!/bin/bash # Setup script for Prosody Node.js set -e echo "=========================================" echo "Prosody Node.js Setup Script" echo "=========================================" echo "" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check Node.js version echo "Checking Node.js version..." if ! command -v node &> /dev/null; then echo -e "${RED}Error: Node.js is not installed${NC}" echo "Please install Node.js 18 or higher" exit 1 fi NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) if [ "$NODE_VERSION" -lt 18 ]; then echo -e "${RED}Error: Node.js version must be 18 or higher${NC}" echo "Current version: $(node -v)" exit 1 fi echo -e "${GREEN}✓ Node.js $(node -v) detected${NC}" echo "" # Install dependencies echo "Installing dependencies..." npm install if [ $? -eq 0 ]; then echo -e "${GREEN}✓ Dependencies installed${NC}" else echo -e "${RED}✗ Failed to install dependencies${NC}" exit 1 fi echo "" # Create directories echo "Creating directories..." mkdir -p logs mkdir -p data mkdir -p certs mkdir -p uploads echo -e "${GREEN}✓ Directories created${NC}" echo "" # Create .env file if it doesn't exist if [ ! -f .env ]; then echo "Creating .env file..." cp .env.example .env echo -e "${GREEN}✓ .env file created${NC}" echo -e "${YELLOW}⚠ Please edit .env file with your configuration${NC}" else echo -e "${YELLOW}⚠ .env file already exists, skipping${NC}" fi echo "" # Ask about TLS certificates echo "Do you want to generate self-signed TLS certificates for development? (y/n)" read -r response if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then echo "Generating self-signed certificates..." if command -v openssl &> /dev/null; then cd certs openssl req -x509 -newkey rsa:4096 -keyout server.key -out server.crt -days 365 -nodes \ -subj "/C=US/ST=State/L=City/O=Organization/CN=localhost" cd .. echo -e "${GREEN}✓ Certificates generated in certs/${NC}" echo -e "${YELLOW}⚠ These are self-signed certificates for development only${NC}" else echo -e "${RED}✗ OpenSSL not found, skipping certificate generation${NC}" fi else echo "Skipping certificate generation" fi echo "" # Ask about systemd service if [[ "$OSTYPE" == "linux-gnu"* ]]; then echo "Do you want to install systemd service? (requires sudo) (y/n)" read -r response if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then echo "Creating systemd service..." SERVICE_FILE="/etc/systemd/system/prosody-nodejs.service" CURRENT_DIR=$(pwd) CURRENT_USER=$(whoami) sudo tee $SERVICE_FILE > /dev/null <