- Implementiere eine Überprüfung in den Skripten `install.sh` und `update_config.sh`, um sicherzustellen, dass die Konfigurationsdatei an dem richtigen Ort liegt. Falls nicht, wird die Datei verschoben und die Berechtigungen sowie der Eigentümer entsprechend angepasst.
95 lines
2.7 KiB
Bash
Executable File
95 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# YourChat Installations Script
|
|
# Installiert die Anwendung als Systemdienst
|
|
|
|
set -e # Beende bei Fehlern
|
|
|
|
echo "=== YourChat - Installation Script ==="
|
|
|
|
# Prüfe ob Build existiert
|
|
if [ ! -f "build/yourchat" ]; then
|
|
echo "Fehler: Build nicht gefunden. Bitte zuerst ./deploy/build.sh ausführen."
|
|
exit 1
|
|
fi
|
|
|
|
# Installationsverzeichnis erstellen
|
|
echo "=== Installationsverzeichnis erstellen ==="
|
|
sudo mkdir -p /opt/yourchat
|
|
sudo mkdir -p /opt/yourchat/config
|
|
sudo mkdir -p /opt/yourchat/logs
|
|
|
|
# Anwendung installieren
|
|
echo "=== Anwendung installieren ==="
|
|
sudo cp build/yourchat /opt/yourchat/
|
|
sudo cp build/ws_probe /opt/yourchat/
|
|
sudo chmod +x /opt/yourchat/yourchat
|
|
sudo chmod +x /opt/yourchat/ws_probe
|
|
|
|
# Konfiguration installieren (nur wenn nicht vorhanden)
|
|
echo "=== Konfiguration installieren ==="
|
|
if [ ! -f "/opt/yourchat/config/chatconfig.json" ]; then
|
|
sudo cp config/chatconfig.json /opt/yourchat/config/
|
|
echo "Konfigurationsdatei installiert."
|
|
else
|
|
echo "Konfigurationsdatei existiert bereits - wird nicht überschrieben."
|
|
fi
|
|
|
|
# Korrigiere falls die Datei am falschen Ort liegt
|
|
if [ -f "/opt/yourchat/chatconfig.json" ] && [ ! -f "/opt/yourchat/config/chatconfig.json" ]; then
|
|
echo "Korrigiere Konfigurationsdatei-Pfad..."
|
|
sudo mv /opt/yourchat/chatconfig.json /opt/yourchat/config/
|
|
sudo chown yourchat:yourchat /opt/yourchat/config/chatconfig.json
|
|
sudo chmod 644 /opt/yourchat/config/chatconfig.json
|
|
fi
|
|
|
|
# Systemd Service erstellen
|
|
echo "=== Systemd Service erstellen ==="
|
|
sudo tee /etc/systemd/system/yourchat.service > /dev/null <<EOF
|
|
[Unit]
|
|
Description=YourChat Server
|
|
After=network.target postgresql.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=yourchat
|
|
Group=yourchat
|
|
WorkingDirectory=/opt/yourchat
|
|
ExecStart=/opt/yourchat/yourchat
|
|
Restart=always
|
|
RestartSec=10
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
# Benutzer erstellen
|
|
echo "=== Benutzer erstellen ==="
|
|
if ! id "yourchat" &>/dev/null; then
|
|
sudo useradd -r -s /bin/false -d /opt/yourchat yourchat
|
|
echo "Benutzer 'yourchat' erstellt."
|
|
else
|
|
echo "Benutzer 'yourchat' existiert bereits."
|
|
fi
|
|
|
|
# Berechtigungen setzen
|
|
echo "=== Berechtigungen setzen ==="
|
|
sudo chown -R yourchat:yourchat /opt/yourchat
|
|
sudo chmod 755 /opt/yourchat
|
|
sudo chmod 644 /opt/yourchat/config/chatconfig.json
|
|
|
|
# Systemd Service aktivieren
|
|
echo "=== Systemd Service aktivieren ==="
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable yourchat.service
|
|
|
|
echo "=== Installation abgeschlossen! ==="
|
|
echo ""
|
|
echo "Nächste Schritte:"
|
|
echo "1. Konfiguration anpassen: sudo nano /opt/yourchat/config/chatconfig.json"
|
|
echo "2. Service starten: sudo systemctl start yourchat"
|
|
echo "3. Status prüfen: sudo systemctl status yourchat"
|
|
echo "4. Logs anzeigen: sudo journalctl -u yourchat -f"
|