-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·141 lines (115 loc) · 3.67 KB
/
setup.sh
File metadata and controls
executable file
·141 lines (115 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# Matrix Server Setup Script
# Generiert Konfigurationsdateien aus Templates mit Werten aus .env
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# Farben
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_warn() { echo -e "${YELLOW}[WARN]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# .env prüfen
if [ ! -f .env ]; then
log_error ".env Datei nicht gefunden!"
log_info "Kopiere .env.example nach .env und passe die Werte an:"
echo " cp .env.example .env"
echo " nano .env"
exit 1
fi
# .env laden
set -a
source .env
set +a
# Prüfen ob alle Variablen gesetzt sind
REQUIRED_VARS=(
"DOMAIN"
"MATRIX_DOMAIN"
"ELEMENT_DOMAIN"
"POSTGRES_PASSWORD"
"SYNAPSE_REGISTRATION_SECRET"
"SYNAPSE_MACAROON_SECRET"
"SYNAPSE_FORM_SECRET"
"ADMIN_EMAIL"
"SMTP_HOST"
"SMTP_PORT"
"SMTP_USER"
"SMTP_PASS"
)
for var in "${REQUIRED_VARS[@]}"; do
if [ -z "${!var:-}" ] || [[ "${!var}" == *"CHANGE_ME"* ]]; then
log_error "Variable $var ist nicht gesetzt oder enthält Standardwert!"
exit 1
fi
done
log_info "Generiere Konfigurationsdateien..."
# Funktion zum Ersetzen von Variablen in Templates
render_template() {
local template="$1"
local output="$2"
envsubst < "$template" > "$output"
log_info "Erstellt: $output"
}
# Konfigurationsdateien generieren
render_template "templates/element-config.json.template" "element-config.json"
render_template "templates/Caddyfile.template" "Caddyfile"
# synapse-data Verzeichnis erstellen falls nicht vorhanden
mkdir -p synapse-data
# Prüfen ob Signing Key existiert
if [ ! -f "synapse-data/${MATRIX_DOMAIN}.signing.key" ]; then
log_info "Generiere Synapse Signing Key..."
docker run -it --rm \
-v "${SCRIPT_DIR}/synapse-data:/data" \
-e SYNAPSE_SERVER_NAME="${MATRIX_DOMAIN}" \
-e SYNAPSE_REPORT_STATS=no \
matrixdotorg/synapse:latest generate
# Berechtigungen setzen
sudo chown -R 991:991 synapse-data
sudo chmod -R 755 synapse-data
fi
# homeserver.yaml generieren (muss in synapse-data liegen)
log_info "Generiere homeserver.yaml..."
envsubst < "templates/homeserver.yaml.template" > "/tmp/homeserver.yaml.tmp"
# Log-Konfiguration erstellen falls nicht vorhanden
if [ ! -f "synapse-data/${MATRIX_DOMAIN}.log.config" ]; then
cat > "/tmp/log.config.tmp" << EOF
version: 1
formatters:
precise:
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'
handlers:
console:
class: logging.StreamHandler
formatter: precise
loggers:
synapse.storage.SQL:
level: WARNING
root:
level: INFO
handlers: [console]
disable_existing_loggers: false
EOF
docker run --rm -v "${SCRIPT_DIR}/synapse-data:/data" -v "/tmp/log.config.tmp:/tmp/log.config" alpine cp /tmp/log.config /data/${MATRIX_DOMAIN}.log.config
rm /tmp/log.config.tmp
fi
# homeserver.yaml in synapse-data kopieren (via Docker wegen Berechtigungen)
docker run --rm \
-v "${SCRIPT_DIR}/synapse-data:/data" \
-v "/tmp/homeserver.yaml.tmp:/tmp/homeserver.yaml" \
alpine cp /tmp/homeserver.yaml /data/homeserver.yaml
rm /tmp/homeserver.yaml.tmp
log_info "Setze Berechtigungen..."
sudo chown -R 991:991 synapse-data
sudo chmod -R 755 synapse-data
echo ""
log_info "Setup abgeschlossen!"
echo ""
echo "Nächste Schritte:"
echo " 1. Caddyfile auf Server kopieren: sudo cp Caddyfile /etc/caddy/Caddyfile"
echo " 2. Caddy neu laden: sudo systemctl reload caddy"
echo " 3. Container starten: docker compose up -d"
echo " 4. Admin erstellen: ./scripts/create-user.sh admin --admin"
echo ""