Files
element_matrix_chat/scripts/setup.sh
T
2025-11-08 22:27:01 +01:00

121 lines
4.0 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Matrix + Element Setup Script
set -e
echo "🚀 Configurando Matrix + Element + Synapse Admin..."
# Colores para output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Verificar Docker
if ! command -v docker &> /dev/null; then
echo -e "${RED}❌ Docker no está instalado${NC}"
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
echo -e "${RED}❌ Docker Compose no está instalado${NC}"
exit 1
fi
# Verificar archivo .env
if [ ! -f .env ]; then
echo -e "${YELLOW}⚠️ Archivo .env no encontrado, copiando desde .env.example${NC}"
cp .env.example .env
echo -e "${RED}🔧 Por favor edita el archivo .env con tus configuraciones${NC}"
echo -e "${BLUE}💡 Especialmente cambia las contraseñas por defecto${NC}"
exit 1
fi
# Cargar variables de entorno
source .env
echo -e "${BLUE}📋 Verificando configuración...${NC}"
# Crear red Docker si no existe
echo -e "${BLUE}🌐 Creando red Docker...${NC}"
if ! docker network ls | grep -q matrix_net; then
docker network create --driver=bridge --subnet=${MATRIX_NETWORK_SUBNET} --gateway=${MATRIX_NETWORK_GATEWAY} matrix_net
echo -e "${GREEN}✅ Red matrix_net creada${NC}"
else
echo -e "${YELLOW}️ Red matrix_net ya existe${NC}"
fi
# Crear directorios necesarios
echo -e "${BLUE}📁 Creando directorios...${NC}"
mkdir -p synapse_data/appservices
mkdir -p backups
# Generar configuración de Synapse si no existe
if [ ! -f synapse_data/homeserver.yaml ]; then
echo -e "${BLUE}⚙️ Generando configuración de Synapse...${NC}"
# Generar configuración inicial
docker run --rm -v "$PWD/synapse_data:/data" \
-e SYNAPSE_SERVER_NAME=${MATRIX_SERVER_NAME} \
-e SYNAPSE_REPORT_STATS=${MATRIX_REPORT_STATS} \
--user root \
matrixdotorg/synapse:latest generate
# Cambiar permisos
docker run --rm -v "$PWD:/workdir" --user root alpine sh -c "chown -R $(id -u):$(id -g) /workdir/synapse_data"
echo -e "${GREEN}✅ Configuración base de Synapse generada${NC}"
echo -e "${YELLOW}🔧 Aplicando configuraciones personalizadas...${NC}"
# Aquí podrías aplicar modificaciones automáticas al homeserver.yaml
# Por ahora, usamos la configuración manual existente
fi
echo -e "${BLUE}🐳 Iniciando contenedores...${NC}"
docker-compose up -d
echo -e "${BLUE}⏳ Esperando que los servicios estén listos...${NC}"
sleep 20
# Verificar que todos los servicios estén funcionando
echo -e "${BLUE}🔍 Verificando servicios...${NC}"
services=("postgres:5432" "synapse:8008" "element:8081" "synapse-admin:8082")
for service in "${services[@]}"; do
name=${service%:*}
port=${service#*:}
if curl -s http://localhost:$port > /dev/null 2>&1; then
echo -e "${GREEN}$name (puerto $port) - OK${NC}"
else
echo -e "${RED}$name (puerto $port) - ERROR${NC}"
fi
done
# Crear usuario administrador si no existe
echo -e "${BLUE}👤 Creando usuario administrador...${NC}"
if docker exec element_matrix_chat-synapse-1 register_new_matrix_user \
-c /data/homeserver.yaml \
-u ${ADMIN_USERNAME} \
-p ${ADMIN_PASSWORD} \
-a \
http://localhost:8008 2>/dev/null; then
echo -e "${GREEN}✅ Usuario administrador creado: ${ADMIN_USERNAME}${NC}"
else
echo -e "${YELLOW}️ Usuario administrador ya existe o hubo un error${NC}"
fi
echo
echo -e "${GREEN}🎉 ¡Configuración completada!${NC}"
echo
echo -e "${BLUE}📍 Acceso a los servicios:${NC}"
echo -e " • Element Web: ${GREEN}http://localhost:${ELEMENT_PORT}${NC}"
echo -e " • Synapse Admin: ${GREEN}http://localhost:${SYNAPSE_ADMIN_PORT}${NC}"
echo -e " • API Matrix: ${GREEN}http://localhost:${SYNAPSE_PORT}${NC}"
echo
echo -e "${BLUE}🔐 Credenciales de administrador:${NC}"
echo -e " • Usuario: ${GREEN}${ADMIN_USERNAME}${NC}"
echo -e " • Contraseña: ${GREEN}${ADMIN_PASSWORD}${NC}"
echo
echo -e "${YELLOW}💡 Para crear más usuarios usa: ./scripts/create-user.sh${NC}"