Files
prosody-nodejs/setup.sh
2025-12-27 03:39:14 +01:00

168 líneas
4.2 KiB
Bash
Archivo Ejecutable

#!/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 <<EOF
[Unit]
Description=Prosody Node.js XMPP Server
After=network.target
[Service]
Type=simple
User=$CURRENT_USER
Group=$CURRENT_USER
WorkingDirectory=$CURRENT_DIR
Environment=NODE_ENV=production
ExecStart=$(which node) $CURRENT_DIR/src/index.js
Restart=always
RestartSec=10
StandardOutput=journal
StandardError=journal
SyslogIdentifier=prosody-nodejs
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
echo -e "${GREEN}✓ Systemd service installed${NC}"
echo ""
echo "To start the service:"
echo " sudo systemctl start prosody-nodejs"
echo ""
echo "To enable on boot:"
echo " sudo systemctl enable prosody-nodejs"
fi
fi
echo ""
# Summary
echo "========================================="
echo "Setup Complete!"
echo "========================================="
echo ""
echo "Next steps:"
echo ""
echo "1. Edit configuration:"
echo " nano .env"
echo " nano config/default.yaml"
echo ""
echo "2. Start the server:"
echo " npm start"
echo ""
echo " Or in development mode:"
echo " npm run dev"
echo ""
echo "3. Test the connection:"
echo " Use an XMPP client (Gajim, Pidgin, etc.)"
echo " Connect to localhost:5222"
echo ""
echo "4. View logs:"
echo " tail -f logs/prosody-nodejs.log"
echo ""
echo "Documentation:"
echo " - Quick Start: docs/QUICKSTART.md"
echo " - API Docs: docs/API.md"
echo " - Module Development: docs/MODULE_DEVELOPMENT.md"
echo " - Deployment: docs/DEPLOYMENT.md"
echo ""
echo -e "${GREEN}Happy chatting!${NC}"