2755 lines
84 KiB
Bash
2755 lines
84 KiB
Bash
#!/bin/bash
|
||
# MYP Installer Control Center - Vollständige Linux/Unix-Installation
|
||
# Zentrale Installationskonsole für die MYP-Plattform
|
||
# Version 4.0 - Granularer Installer mit Frontend/Backend-Trennung
|
||
|
||
# Farbdefinitionen
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[0;33m'
|
||
BLUE='\033[0;34m'
|
||
CYAN='\033[0;36m'
|
||
WHITE='\033[1;37m'
|
||
NC='\033[0m' # No Color
|
||
|
||
# Globale Variablen
|
||
PROJECT_DIR="$(pwd)"
|
||
BACKEND_DIR="$PROJECT_DIR/backend"
|
||
FRONTEND_DIR="$PROJECT_DIR/frontend"
|
||
APP_DIR="$BACKEND_DIR/app"
|
||
VENV_DIR="$BACKEND_DIR/venv"
|
||
|
||
# Überprüfen, ob das Skript als Root ausgeführt wird
|
||
is_root=0
|
||
if [ "$EUID" -eq 0 ]; then
|
||
is_root=1
|
||
fi
|
||
|
||
# Funktionen
|
||
|
||
# Alte Services entfernen
|
||
remove_old_services() {
|
||
local service_type="$1" # "backend" oder "kiosk" oder "all"
|
||
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Entferne alte MYP Services...${NC}"
|
||
|
||
# Backend Services
|
||
if [ "$service_type" = "backend" ] || [ "$service_type" = "all" ]; then
|
||
local backend_services=("myp.service" "myp-platform.service" "myp-backend.service" "myp-reservation.service")
|
||
for service in "${backend_services[@]}"; do
|
||
if systemctl is-enabled "$service" >/dev/null 2>&1; then
|
||
echo -e "${YELLOW}Stoppe und deaktiviere $service...${NC}"
|
||
systemctl stop "$service" 2>/dev/null || true
|
||
systemctl disable "$service" 2>/dev/null || true
|
||
echo -e "${GREEN}✓ $service entfernt${NC}"
|
||
fi
|
||
done
|
||
fi
|
||
|
||
# Kiosk Services
|
||
if [ "$service_type" = "kiosk" ] || [ "$service_type" = "all" ]; then
|
||
local kiosk_services=("myp-kiosk-browser.service" "myp-kiosk.service" "kiosk.service" "chromium-kiosk.service")
|
||
for service in "${kiosk_services[@]}"; do
|
||
if systemctl is-enabled "$service" >/dev/null 2>&1; then
|
||
echo -e "${YELLOW}Stoppe und deaktiviere $service...${NC}"
|
||
systemctl stop "$service" 2>/dev/null || true
|
||
systemctl disable "$service" 2>/dev/null || true
|
||
echo -e "${GREEN}✓ $service entfernt${NC}"
|
||
fi
|
||
done
|
||
fi
|
||
|
||
systemctl daemon-reload
|
||
echo -e "${GREEN}✓ Alte Services erfolgreich entfernt${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ Service-Entfernung übersprungen (keine Root-Rechte)${NC}"
|
||
echo -e "${BLUE}Manuell ausführen: sudo systemctl stop <service> && sudo systemctl disable <service>${NC}"
|
||
fi
|
||
}
|
||
|
||
# Backend Service mit Python 3.11 erstellen
|
||
create_backend_service() {
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Erstelle Backend-Service mit Python 3.11...${NC}"
|
||
|
||
cat > "/etc/systemd/system/myp.service" << EOF
|
||
[Unit]
|
||
Description=MYP Reservation Platform Backend (Python 3.11)
|
||
After=network.target
|
||
Wants=network.target
|
||
|
||
[Service]
|
||
Type=simple
|
||
User=$USER
|
||
Group=$USER
|
||
WorkingDirectory=$PROJECT_DIR/backend/app
|
||
Environment=PYTHONPATH=$PROJECT_DIR/backend/app
|
||
Environment=FLASK_ENV=production
|
||
Environment=FLASK_APP=app.py
|
||
Environment=PYTHONUNBUFFERED=1
|
||
ExecStart=$PROJECT_DIR/backend/venv/bin/python3.11 app.py --host 0.0.0.0 --port 443 --cert certs/backend.crt --key certs/backend.key
|
||
Restart=always
|
||
RestartSec=10
|
||
StandardOutput=journal
|
||
StandardError=journal
|
||
SyslogIdentifier=myp-backend
|
||
|
||
# Security settings
|
||
NoNewPrivileges=true
|
||
PrivateTmp=true
|
||
ProtectSystem=strict
|
||
ProtectHome=true
|
||
ReadWritePaths=$PROJECT_DIR/backend/app/logs
|
||
ReadWritePaths=$PROJECT_DIR/backend/app/database
|
||
|
||
[Install]
|
||
WantedBy=multi-user.target
|
||
EOF
|
||
|
||
systemctl daemon-reload
|
||
systemctl enable myp.service
|
||
echo -e "${GREEN}✓ Backend-Service mit Python 3.11 erstellt und aktiviert${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ Service-Erstellung übersprungen (keine Root-Rechte)${NC}"
|
||
echo -e "${BLUE}Manuell erstellen: Service-Datei mit Python 3.11 Pfad${NC}"
|
||
fi
|
||
}
|
||
|
||
# Kiosk-Browser Service erstellen
|
||
create_kiosk_service() {
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Erstelle Kiosk-Browser-Service...${NC}"
|
||
|
||
cat > "/etc/systemd/system/myp-kiosk-browser.service" << EOF
|
||
[Unit]
|
||
Description=MYP Kiosk Browser - 3D Printer Management Kiosk Interface (Python 3.11 Backend)
|
||
After=network.target graphical-session.target myp.service
|
||
Requires=myp.service
|
||
PartOf=myp.service
|
||
|
||
[Service]
|
||
Type=simple
|
||
User=$USER
|
||
Group=$USER
|
||
Environment=DISPLAY=:0
|
||
Environment=XAUTHORITY=/home/$USER/.Xauthority
|
||
ExecStartPre=/bin/bash -c 'until curl -k -s https://localhost:443/ > /dev/null; do sleep 2; done'
|
||
ExecStart=/usr/bin/chromium-browser --kiosk --disable-infobars --disable-session-crashed-bubble --disable-translate --no-first-run --disable-features=VizDisplayCompositor --start-fullscreen --autoplay-policy=no-user-gesture-required https://localhost:443/
|
||
Restart=always
|
||
RestartSec=10
|
||
KillMode=mixed
|
||
TimeoutStopSec=30
|
||
|
||
[Install]
|
||
WantedBy=graphical-session.target
|
||
EOF
|
||
|
||
systemctl daemon-reload
|
||
echo -e "${GREEN}✓ Kiosk-Browser-Service erstellt${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ Kiosk-Service-Erstellung übersprungen (keine Root-Rechte)${NC}"
|
||
fi
|
||
}
|
||
|
||
# Service-Management
|
||
manage_services() {
|
||
show_header "Service-Management"
|
||
|
||
echo -e "${WHITE}MYP Service-Management${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}1. Services starten${NC}"
|
||
echo -e "${WHITE}2. Services stoppen${NC}"
|
||
echo -e "${WHITE}3. Services neustarten${NC}"
|
||
echo -e "${WHITE}4. Service-Status anzeigen${NC}"
|
||
echo -e "${WHITE}5. Service-Logs anzeigen${NC}"
|
||
echo -e "${WHITE}6. Services aktivieren (Autostart)${NC}"
|
||
echo -e "${WHITE}7. Services deaktivieren${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}9. Zurück zum Hauptmenü${NC}"
|
||
echo ""
|
||
|
||
read -p "Wählen Sie eine Option (1-7, 9): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Starte MYP Services...${NC}"
|
||
systemctl start myp.service
|
||
systemctl start myp-kiosk-browser.service 2>/dev/null || true
|
||
echo -e "${GREEN}✓ Services gestartet${NC}"
|
||
else
|
||
echo -e "${RED}Root-Rechte erforderlich${NC}"
|
||
fi
|
||
;;
|
||
2)
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Stoppe MYP Services...${NC}"
|
||
systemctl stop myp-kiosk-browser.service 2>/dev/null || true
|
||
systemctl stop myp.service
|
||
echo -e "${GREEN}✓ Services gestoppt${NC}"
|
||
else
|
||
echo -e "${RED}Root-Rechte erforderlich${NC}"
|
||
fi
|
||
;;
|
||
3)
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Starte MYP Services neu...${NC}"
|
||
systemctl restart myp.service
|
||
systemctl restart myp-kiosk-browser.service 2>/dev/null || true
|
||
echo -e "${GREEN}✓ Services neu gestartet${NC}"
|
||
else
|
||
echo -e "${RED}Root-Rechte erforderlich${NC}"
|
||
fi
|
||
;;
|
||
4)
|
||
echo -e "${BLUE}Service-Status:${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}Backend Service (myp.service):${NC}"
|
||
systemctl status myp.service --no-pager -l || true
|
||
echo ""
|
||
echo -e "${WHITE}Kiosk Service (myp-kiosk-browser.service):${NC}"
|
||
systemctl status myp-kiosk-browser.service --no-pager -l 2>/dev/null || echo "Service nicht gefunden"
|
||
;;
|
||
5)
|
||
echo -e "${BLUE}Service-Logs:${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}Backend Logs (letzte 50 Zeilen):${NC}"
|
||
journalctl -u myp.service -n 50 --no-pager || true
|
||
echo ""
|
||
echo -e "${WHITE}Kiosk Logs (letzte 20 Zeilen):${NC}"
|
||
journalctl -u myp-kiosk-browser.service -n 20 --no-pager 2>/dev/null || echo "Keine Kiosk-Logs verfügbar"
|
||
;;
|
||
6)
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Aktiviere Services für Autostart...${NC}"
|
||
systemctl enable myp.service
|
||
read -p "Soll auch der Kiosk-Browser automatisch starten? (j/n): " enable_kiosk
|
||
if [ "$enable_kiosk" = "j" ]; then
|
||
systemctl enable myp-kiosk-browser.service 2>/dev/null || true
|
||
fi
|
||
echo -e "${GREEN}✓ Services für Autostart aktiviert${NC}"
|
||
else
|
||
echo -e "${RED}Root-Rechte erforderlich${NC}"
|
||
fi
|
||
;;
|
||
7)
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Deaktiviere Services...${NC}"
|
||
systemctl disable myp.service
|
||
systemctl disable myp-kiosk-browser.service 2>/dev/null || true
|
||
echo -e "${GREEN}✓ Services deaktiviert${NC}"
|
||
else
|
||
echo -e "${RED}Root-Rechte erforderlich${NC}"
|
||
fi
|
||
;;
|
||
9)
|
||
show_main_menu
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option${NC}"
|
||
;;
|
||
esac
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
manage_services
|
||
}
|
||
|
||
# Logs anzeigen
|
||
show_logs() {
|
||
show_header "Log-Anzeige"
|
||
|
||
echo -e "${WHITE}MYP Log-Anzeige${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}1. Backend Service Logs (systemd)${NC}"
|
||
echo -e "${WHITE}2. Kiosk Service Logs (systemd)${NC}"
|
||
echo -e "${WHITE}3. Backend Application Logs${NC}"
|
||
echo -e "${WHITE}4. Alle Logs (Live-Modus)${NC}"
|
||
echo -e "${WHITE}5. Fehler-Logs${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}9. Zurück zum Hauptmenü${NC}"
|
||
echo ""
|
||
|
||
read -p "Wählen Sie eine Option (1-5, 9): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
echo -e "${BLUE}Backend Service Logs:${NC}"
|
||
journalctl -u myp.service -f --no-pager
|
||
;;
|
||
2)
|
||
echo -e "${BLUE}Kiosk Service Logs:${NC}"
|
||
journalctl -u myp-kiosk-browser.service -f --no-pager 2>/dev/null || echo "Kiosk-Service nicht gefunden"
|
||
;;
|
||
3)
|
||
echo -e "${BLUE}Backend Application Logs:${NC}"
|
||
if [ -d "$APP_DIR/logs" ]; then
|
||
echo -e "${WHITE}Verfügbare Log-Dateien:${NC}"
|
||
find "$APP_DIR/logs" -name "*.log" -type f | head -10
|
||
echo ""
|
||
read -p "Welche Log-Datei möchten Sie anzeigen? (Pfad eingeben): " log_file
|
||
if [ -f "$log_file" ]; then
|
||
tail -f "$log_file"
|
||
else
|
||
echo -e "${RED}Log-Datei nicht gefunden${NC}"
|
||
fi
|
||
else
|
||
echo -e "${RED}Log-Verzeichnis nicht gefunden: $APP_DIR/logs${NC}"
|
||
fi
|
||
;;
|
||
4)
|
||
echo -e "${BLUE}Alle MYP Logs (Live-Modus):${NC}"
|
||
echo -e "${YELLOW}Drücken Sie Ctrl+C zum Beenden${NC}"
|
||
journalctl -u myp.service -u myp-kiosk-browser.service -f --no-pager
|
||
;;
|
||
5)
|
||
echo -e "${BLUE}Fehler-Logs:${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}Systemd Fehler:${NC}"
|
||
journalctl -u myp.service -p err --no-pager | tail -20
|
||
echo ""
|
||
if [ -d "$APP_DIR/logs/errors" ]; then
|
||
echo -e "${WHITE}Application Fehler:${NC}"
|
||
find "$APP_DIR/logs/errors" -name "*.log" -type f -exec tail -10 {} \; 2>/dev/null || echo "Keine Fehler-Logs gefunden"
|
||
fi
|
||
;;
|
||
9)
|
||
show_main_menu
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option${NC}"
|
||
;;
|
||
esac
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
show_logs
|
||
}
|
||
|
||
show_header() {
|
||
local title="$1"
|
||
clear
|
||
echo -e "${CYAN}=============================================================${NC}"
|
||
echo -e "${CYAN} MYP INSTALLER CONTROL CENTER ${NC}"
|
||
echo -e "${CYAN} Version 4.0 ${NC}"
|
||
echo -e "${CYAN} Granularer Installer mit Trennung ${NC}"
|
||
echo -e "${CYAN}=============================================================${NC}"
|
||
echo -e "${CYAN} $title${NC}"
|
||
echo -e "${CYAN}=============================================================${NC}"
|
||
|
||
if [ $is_root -eq 0 ]; then
|
||
echo -e "${YELLOW}HINWEIS: Dieses Skript läuft ohne Root-Rechte.${NC}"
|
||
echo -e "${YELLOW}Einige Funktionen sind möglicherweise eingeschränkt.${NC}"
|
||
echo -e "${CYAN}=============================================================${NC}"
|
||
fi
|
||
|
||
echo ""
|
||
}
|
||
|
||
check_command() {
|
||
command -v "$1" >/dev/null 2>&1
|
||
}
|
||
|
||
exec_command() {
|
||
local cmd="$1"
|
||
local description="$2"
|
||
local allow_fail="$3"
|
||
|
||
echo -e "${BLUE}> $description...${NC}"
|
||
|
||
eval $cmd
|
||
|
||
if [ $? -eq 0 ]; then
|
||
echo -e "${GREEN}✓ Erfolgreich abgeschlossen!${NC}"
|
||
return 0
|
||
else
|
||
if [ "$allow_fail" = "true" ]; then
|
||
echo -e "${YELLOW}⚠ Warnung: $description fehlgeschlagen, wird übersprungen.${NC}"
|
||
return 0
|
||
else
|
||
echo -e "${RED}✗ Fehler beim Ausführen des Befehls. Exit-Code: $?${NC}"
|
||
return 1
|
||
fi
|
||
fi
|
||
}
|
||
|
||
get_local_ip() {
|
||
local ip=$(hostname -I | awk '{print $1}')
|
||
if [ -z "$ip" ]; then
|
||
ip="127.0.0.1"
|
||
fi
|
||
echo "$ip"
|
||
}
|
||
|
||
# ========================================================
|
||
# PRODUKTIONS-INSTALLER (Integration from install.sh)
|
||
# ========================================================
|
||
|
||
# Produktions-Log-Funktionen
|
||
prod_log_info() {
|
||
echo -e "${BLUE}[INFO]${NC} $1"
|
||
}
|
||
|
||
prod_log_success() {
|
||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||
}
|
||
|
||
prod_log_warning() {
|
||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||
}
|
||
|
||
prod_log_error() {
|
||
echo -e "${RED}[ERROR]${NC} $1"
|
||
}
|
||
|
||
# Prüfung für Produktions-Abhängigkeiten
|
||
check_production_dependencies() {
|
||
local deps=("python3.11" "curl" "openssl")
|
||
|
||
for dep in "${deps[@]}"; do
|
||
if ! command -v "$dep" &> /dev/null; then
|
||
prod_log_error "Abhängigkeit '$dep' nicht gefunden!"
|
||
return 1
|
||
fi
|
||
done
|
||
return 0
|
||
}
|
||
|
||
# Produktions-Backend Installation
|
||
install_production_backend() {
|
||
prod_log_info "=== Produktions-Backend Installation ==="
|
||
|
||
cd "$PROJECT_DIR/backend"
|
||
|
||
# Python Virtual Environment erstellen
|
||
prod_log_info "Erstelle Python Virtual Environment..."
|
||
python3.11 -m venv venv
|
||
source venv/bin/activate
|
||
|
||
# Requirements installieren
|
||
prod_log_info "Installiere Python-Abhängigkeiten..."
|
||
pip install --upgrade pip
|
||
pip install -r requirements.txt
|
||
|
||
# Zertifikate kopieren
|
||
prod_log_info "Kopiere TLS-Zertifikate..."
|
||
mkdir -p app/certs
|
||
cp "$PROJECT_DIR/backend/app/certs/backend.crt" app/certs/
|
||
cp "$PROJECT_DIR/backend/app/certs/backend.key" app/certs/
|
||
chmod 600 app/certs/backend.key
|
||
chmod 644 app/certs/backend.crt
|
||
|
||
# Alte Services entfernen und neue systemd Services installieren
|
||
remove_old_services "backend"
|
||
create_backend_service
|
||
|
||
# Datenbank initialisieren
|
||
prod_log_info "Initialisiere Datenbank..."
|
||
cd app
|
||
python3.11 init_db.py
|
||
|
||
# Kiosk-Modus für Produktions-Backend automatisch konfigurieren
|
||
prod_log_info "Konfiguriere Backend für Kiosk-Web-Interface..."
|
||
|
||
# Kiosk-Konfiguration in settings.py hinzufügen
|
||
if [ -f "config/settings.py" ]; then
|
||
if ! grep -q "KIOSK_MODE" "config/settings.py"; then
|
||
# Backup erstellen
|
||
cp "config/settings.py" "config/settings.py.backup.production"
|
||
|
||
# Kiosk-Konfiguration hinzufügen
|
||
cat >> "config/settings.py" << 'EOF'
|
||
|
||
# Produktions-Kiosk-Konfiguration
|
||
KIOSK_MODE = True
|
||
KIOSK_AUTO_LOGIN = True
|
||
KIOSK_FULLSCREEN = True
|
||
KIOSK_HIDE_NAVIGATION = False
|
||
KIOSK_DEFAULT_USER = "kiosk@mercedes-benz.com"
|
||
KIOSK_WEB_INTERFACE = True
|
||
KIOSK_BROWSER_AUTO_START = True
|
||
|
||
# Produktions-spezifische Einstellungen
|
||
FLASK_DEBUG = False
|
||
FLASK_ENV = "production"
|
||
EOF
|
||
|
||
prod_log_success "Kiosk-Konfiguration hinzugefügt"
|
||
else
|
||
prod_log_info "Kiosk-Konfiguration bereits vorhanden"
|
||
fi
|
||
fi
|
||
|
||
# Kiosk-Browser-Service für Produktion
|
||
remove_old_services "kiosk"
|
||
create_kiosk_service
|
||
|
||
# Optional: Service automatisch aktivieren
|
||
if [ $is_root -eq 1 ]; then
|
||
read -p "Soll der Kiosk-Browser beim Boot automatisch starten? (j/n, Standard: j): " auto_kiosk
|
||
if [ "$auto_kiosk" != "n" ]; then
|
||
systemctl enable myp-kiosk-browser.service
|
||
prod_log_success "Kiosk-Browser automatisch aktiviert"
|
||
fi
|
||
fi
|
||
|
||
# Kiosk-Starter-Skript erstellen
|
||
cat > "start_kiosk.sh" << 'EOF'
|
||
#!/bin/bash
|
||
# MYP Production Kiosk Starter
|
||
|
||
echo "🏭 Starte MYP Produktions-Kiosk..."
|
||
|
||
# Warte bis Backend verfügbar ist
|
||
echo "⏳ Warte auf Backend..."
|
||
timeout=60
|
||
counter=0
|
||
while [ $counter -lt $timeout ]; do
|
||
if curl -k -s https://localhost:443/ > /dev/null 2>&1; then
|
||
echo "✅ Backend ist verfügbar!"
|
||
break
|
||
fi
|
||
sleep 2
|
||
counter=$((counter + 2))
|
||
echo " Warte... ($counter/$timeout Sekunden)"
|
||
done
|
||
|
||
if [ $counter -ge $timeout ]; then
|
||
echo "❌ Backend nicht verfügbar nach $timeout Sekunden"
|
||
exit 1
|
||
fi
|
||
|
||
# Browser im Produktions-Kiosk-Modus starten
|
||
echo "🌐 Starte Produktions-Kiosk..."
|
||
exec chromium-browser \
|
||
--kiosk \
|
||
--disable-infobars \
|
||
--disable-session-crashed-bubble \
|
||
--disable-translate \
|
||
--no-first-run \
|
||
--start-fullscreen \
|
||
--disable-features=VizDisplayCompositor \
|
||
--autoplay-policy=no-user-gesture-required \
|
||
--disable-background-timer-throttling \
|
||
--disable-renderer-backgrounding \
|
||
https://localhost:443/
|
||
EOF
|
||
|
||
chmod +x "start_kiosk.sh"
|
||
prod_log_success "Kiosk-Starter-Skript erstellt"
|
||
|
||
prod_log_success "Produktions-Backend Installation abgeschlossen!"
|
||
prod_log_info "Das Backend läuft als Web-Interface + API parallel"
|
||
if [ $is_root -eq 1 ]; then
|
||
prod_log_info "Service starten mit: sudo systemctl start myp.service"
|
||
if [ "$auto_kiosk" != "n" ]; then
|
||
prod_log_info "Kiosk startet automatisch beim nächsten Neustart"
|
||
else
|
||
prod_log_info "Kiosk starten mit: sudo systemctl start myp-kiosk-browser"
|
||
fi
|
||
fi
|
||
}
|
||
|
||
# Produktions-Frontend Installation
|
||
install_production_frontend() {
|
||
prod_log_info "=== Produktions-Frontend Installation ==="
|
||
|
||
cd "$PROJECT_DIR/frontend"
|
||
|
||
# Docker prüfen
|
||
if ! command -v docker &> /dev/null; then
|
||
prod_log_error "Docker ist nicht installiert!"
|
||
return 1
|
||
fi
|
||
|
||
if ! command -v docker-compose &> /dev/null; then
|
||
prod_log_error "Docker Compose ist nicht installiert!"
|
||
return 1
|
||
fi
|
||
|
||
# Zertifikate kopieren
|
||
prod_log_info "Kopiere TLS-Zertifikate..."
|
||
mkdir -p certs
|
||
cp "$PROJECT_DIR/frontend/certs/frontend.crt" certs/
|
||
cp "$PROJECT_DIR/frontend/certs/frontend.key" certs/
|
||
chmod 600 certs/frontend.key
|
||
chmod 644 certs/frontend.crt
|
||
|
||
# Caddyfile Symlink erstellen
|
||
prod_log_info "Erstelle Caddyfile Symlink..."
|
||
mkdir -p docker/caddy
|
||
if [[ ! -L docker/caddy/Caddyfile ]]; then
|
||
ln -sf "$PROJECT_DIR/frontend/docker/caddy/Caddyfile" docker/caddy/Caddyfile
|
||
fi
|
||
|
||
# Docker Images bauen
|
||
prod_log_info "Baue Docker Images..."
|
||
docker-compose build
|
||
|
||
# Services starten
|
||
prod_log_info "Starte Frontend Services..."
|
||
docker-compose up -d
|
||
|
||
prod_log_success "Produktions-Frontend Installation abgeschlossen!"
|
||
prod_log_info "Frontend verfügbar unter: https://m040tbaraspi001.de040.corpintra.net"
|
||
}
|
||
|
||
# Backend Health Check
|
||
production_health_check_backend() {
|
||
prod_log_info "=== Backend Health Check ==="
|
||
|
||
local max_attempts=30
|
||
local attempt=1
|
||
|
||
while [[ $attempt -le $max_attempts ]]; do
|
||
prod_log_info "Versuche Backend-Verbindung (Versuch $attempt/$max_attempts)..."
|
||
|
||
if curl -k -s --max-time 5 https://raspberrypi/api/test > /dev/null 2>&1; then
|
||
prod_log_success "Backend ist erreichbar!"
|
||
return 0
|
||
fi
|
||
|
||
sleep 2
|
||
((attempt++))
|
||
done
|
||
|
||
prod_log_error "Backend Health Check fehlgeschlagen!"
|
||
return 1
|
||
}
|
||
|
||
# Frontend Health Check
|
||
production_health_check_frontend() {
|
||
prod_log_info "=== Frontend Health Check ==="
|
||
|
||
local max_attempts=30
|
||
local attempt=1
|
||
|
||
while [[ $attempt -le $max_attempts ]]; do
|
||
prod_log_info "Versuche Frontend-Verbindung (Versuch $attempt/$max_attempts)..."
|
||
|
||
if curl -k -s --max-time 5 https://m040tbaraspi001.de040.corpintra.net/ > /dev/null 2>&1; then
|
||
prod_log_success "Frontend ist erreichbar!"
|
||
return 0
|
||
fi
|
||
|
||
sleep 2
|
||
((attempt++))
|
||
done
|
||
|
||
prod_log_error "Frontend Health Check fehlgeschlagen!"
|
||
return 1
|
||
}
|
||
|
||
# Produktions-Installer Menü
|
||
show_production_installer_menu() {
|
||
show_header "🚀 Produktions-Installer (v3.2 Integration)"
|
||
|
||
echo -e "${WHITE}Schnelle Produktions-Installation (von install.sh)${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}1. Backend installieren (Raspberry Pi)${NC}"
|
||
echo -e "${WHITE}2. Frontend installieren (Docker)${NC}"
|
||
echo -e "${WHITE}3. Backend + Health Check${NC}"
|
||
echo -e "${WHITE}4. Frontend + Health Check${NC}"
|
||
echo -e "${WHITE}5. Beide Komponenten + Health Check${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}9. Zurück zum Hauptmenü${NC}"
|
||
echo -e "${WHITE}0. Beenden${NC}"
|
||
echo ""
|
||
|
||
read -p "Wählen Sie eine Option (0-5, 9): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
if check_production_dependencies; then
|
||
install_production_backend
|
||
else
|
||
prod_log_error "Abhängigkeiten fehlen!"
|
||
fi
|
||
show_production_installer_menu
|
||
;;
|
||
2)
|
||
if check_production_dependencies; then
|
||
install_production_frontend
|
||
else
|
||
prod_log_error "Abhängigkeiten fehlen!"
|
||
fi
|
||
show_production_installer_menu
|
||
;;
|
||
3)
|
||
if check_production_dependencies; then
|
||
install_production_backend
|
||
production_health_check_backend
|
||
else
|
||
prod_log_error "Abhängigkeiten fehlen!"
|
||
fi
|
||
show_production_installer_menu
|
||
;;
|
||
4)
|
||
if check_production_dependencies; then
|
||
install_production_frontend
|
||
production_health_check_frontend
|
||
else
|
||
prod_log_error "Abhängigkeiten fehlen!"
|
||
fi
|
||
show_production_installer_menu
|
||
;;
|
||
5)
|
||
if check_production_dependencies; then
|
||
install_production_backend
|
||
production_health_check_backend
|
||
install_production_frontend
|
||
production_health_check_frontend
|
||
prod_log_success "Vollständige Produktions-Installation abgeschlossen!"
|
||
else
|
||
prod_log_error "Abhängigkeiten fehlen!"
|
||
fi
|
||
show_production_installer_menu
|
||
;;
|
||
9)
|
||
show_main_menu
|
||
;;
|
||
0)
|
||
echo -e "${GREEN}Auf Wiedersehen!${NC}"
|
||
exit 0
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option. Bitte versuchen Sie es erneut.${NC}"
|
||
sleep 2
|
||
show_production_installer_menu
|
||
;;
|
||
esac
|
||
}
|
||
|
||
# ========================================================
|
||
# ENDE PRODUKTIONS-INSTALLER
|
||
# ========================================================
|
||
|
||
# System-Abhängigkeiten installieren
|
||
install_system_dependencies() {
|
||
show_header "System-Abhängigkeiten installieren"
|
||
|
||
if [ $is_root -eq 0 ]; then
|
||
echo -e "${RED}Diese Funktion erfordert Root-Rechte.${NC}"
|
||
echo -e "${YELLOW}Bitte starten Sie das Skript mit sudo oder führen Sie folgende Befehle manuell aus:${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}# Debian/Ubuntu/Raspberry Pi OS:${NC}"
|
||
echo -e "${WHITE}sudo apt update${NC}"
|
||
echo -e "${WHITE}sudo apt install -y python3 python3-pip python3-venv nodejs npm git curl wget sqlite3 openssl${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}# RHEL/CentOS/Fedora:${NC}"
|
||
echo -e "${WHITE}sudo dnf install -y python3 python3-pip nodejs npm git curl wget sqlite openssl${NC}"
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
echo -e "${BLUE}Erkenne Betriebssystem...${NC}"
|
||
|
||
if [ -f /etc/debian_version ]; then
|
||
echo -e "${GREEN}Debian/Ubuntu/Raspberry Pi OS erkannt${NC}"
|
||
|
||
echo -e "${BLUE}Aktualisiere Paketlisten...${NC}"
|
||
apt update
|
||
|
||
echo -e "${BLUE}Installiere System-Pakete...${NC}"
|
||
apt install -y \
|
||
python3 \
|
||
python3-pip \
|
||
python3-venv \
|
||
python3-dev \
|
||
build-essential \
|
||
libssl-dev \
|
||
libffi-dev \
|
||
libsqlite3-dev \
|
||
nodejs \
|
||
npm \
|
||
git \
|
||
curl \
|
||
wget \
|
||
sqlite3 \
|
||
openssl \
|
||
ca-certificates \
|
||
nginx \
|
||
supervisor \
|
||
ufw \
|
||
net-tools \
|
||
htop \
|
||
vim \
|
||
nano \
|
||
chromium-browser
|
||
|
||
elif [ -f /etc/redhat-release ]; then
|
||
echo -e "${GREEN}RHEL/CentOS/Fedora erkannt${NC}"
|
||
|
||
echo -e "${BLUE}Installiere System-Pakete...${NC}"
|
||
if check_command dnf; then
|
||
dnf install -y \
|
||
python3 \
|
||
python3-pip \
|
||
python3-devel \
|
||
gcc \
|
||
openssl-devel \
|
||
libffi-devel \
|
||
sqlite-devel \
|
||
nodejs \
|
||
npm \
|
||
git \
|
||
curl \
|
||
wget \
|
||
sqlite \
|
||
openssl \
|
||
ca-certificates \
|
||
nginx \
|
||
supervisor \
|
||
chromium
|
||
else
|
||
yum install -y \
|
||
python3 \
|
||
python3-pip \
|
||
python3-devel \
|
||
gcc \
|
||
openssl-devel \
|
||
libffi-devel \
|
||
sqlite-devel \
|
||
nodejs \
|
||
npm \
|
||
git \
|
||
curl \
|
||
wget \
|
||
sqlite \
|
||
openssl \
|
||
ca-certificates \
|
||
nginx \
|
||
supervisor \
|
||
chromium
|
||
fi
|
||
|
||
else
|
||
echo -e "${YELLOW}Unbekanntes Betriebssystem. Bitte installieren Sie manuell:${NC}"
|
||
echo -e "${WHITE}- Python 3.8+${NC}"
|
||
echo -e "${WHITE}- Node.js 16+${NC}"
|
||
echo -e "${WHITE}- Git, curl, wget, sqlite3, openssl${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
echo -e "${GREEN}✓ System-Abhängigkeiten erfolgreich installiert!${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# Python & Node.js Umgebung einrichten
|
||
setup_python_node_environment() {
|
||
show_header "Python & Node.js Umgebung einrichten"
|
||
|
||
echo -e "${BLUE}1. Python-Umgebung prüfen...${NC}"
|
||
|
||
# Python 3.11 prüfen (erforderlich für MYP Backend)
|
||
python_cmd=""
|
||
if check_command python3.11; then
|
||
python_cmd="python3.11"
|
||
python_version=$(python3.11 --version 2>&1)
|
||
echo -e "${GREEN}✓ $python_version${NC}"
|
||
elif check_command python3; then
|
||
python_cmd="python3"
|
||
python_version=$(python3 --version 2>&1)
|
||
echo -e "${YELLOW}⚠ $python_version gefunden, aber Python 3.11 wird empfohlen${NC}"
|
||
elif check_command python; then
|
||
python_cmd="python"
|
||
python_version=$(python --version 2>&1)
|
||
echo -e "${YELLOW}⚠ $python_version gefunden, aber Python 3.11 wird empfohlen${NC}"
|
||
else
|
||
echo -e "${RED}✗ Python nicht gefunden. Bitte installieren Sie Python 3.11${NC}"
|
||
return 1
|
||
fi
|
||
|
||
# Pip prüfen
|
||
if check_command pip3; then
|
||
echo -e "${GREEN}✓ pip3 gefunden${NC}"
|
||
elif check_command pip; then
|
||
echo -e "${GREEN}✓ pip gefunden${NC}"
|
||
else
|
||
echo -e "${RED}✗ pip nicht gefunden${NC}"
|
||
return 1
|
||
fi
|
||
|
||
echo -e "${BLUE}2. Node.js-Umgebung prüfen...${NC}"
|
||
|
||
# Node.js prüfen
|
||
if check_command node; then
|
||
node_version=$(node --version)
|
||
echo -e "${GREEN}✓ Node.js $node_version${NC}"
|
||
else
|
||
echo -e "${RED}✗ Node.js nicht gefunden${NC}"
|
||
return 1
|
||
fi
|
||
|
||
# npm prüfen
|
||
if check_command npm; then
|
||
npm_version=$(npm --version)
|
||
echo -e "${GREEN}✓ npm $npm_version${NC}"
|
||
else
|
||
echo -e "${RED}✗ npm nicht gefunden${NC}"
|
||
return 1
|
||
fi
|
||
|
||
echo -e "${BLUE}3. Globale npm-Pakete aktualisieren...${NC}"
|
||
exec_command "npm update -g" "npm global update" true
|
||
|
||
echo -e "${GREEN}✓ Python & Node.js Umgebung bereit!${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# Backend installieren
|
||
install_backend() {
|
||
show_header "Backend Installation"
|
||
|
||
echo -e "${BLUE}MYP Backend (Flask API + Web Interface) installieren${NC}"
|
||
echo ""
|
||
|
||
# Python 3.11 prüfen (erforderlich für MYP Backend)
|
||
python_cmd=""
|
||
if check_command python3.11; then
|
||
python_cmd="python3.11"
|
||
echo -e "${GREEN}✓ Python 3.11 gefunden${NC}"
|
||
elif check_command python3; then
|
||
python_cmd="python3"
|
||
echo -e "${YELLOW}⚠ Python 3 gefunden, aber Python 3.11 wird empfohlen${NC}"
|
||
elif check_command python; then
|
||
python_cmd="python"
|
||
echo -e "${YELLOW}⚠ Python gefunden, aber Python 3.11 wird empfohlen${NC}"
|
||
else
|
||
echo -e "${RED}✗ Python nicht gefunden. Bitte installieren Sie Python 3.11${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
# Pip prüfen
|
||
pip_cmd=""
|
||
if check_command pip3; then
|
||
pip_cmd="pip3"
|
||
elif check_command pip; then
|
||
pip_cmd="pip"
|
||
else
|
||
echo -e "${RED}✗ pip nicht gefunden. Bitte installieren Sie pip${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
# Virtual Environment mit Python 3.11 erstellen
|
||
echo -e "${BLUE}1. Virtual Environment mit Python 3.11 erstellen...${NC}"
|
||
if [ ! -d "$VENV_DIR" ]; then
|
||
# Explizit Python 3.11 verwenden
|
||
exec_command "python3.11 -m venv $VENV_DIR" "Erstelle Virtual Environment mit Python 3.11"
|
||
else
|
||
echo -e "${YELLOW}Virtual Environment existiert bereits${NC}"
|
||
# Prüfen ob es Python 3.11 verwendet
|
||
if [ -f "$VENV_DIR/bin/python3.11" ]; then
|
||
echo -e "${GREEN}✓ Virtual Environment verwendet bereits Python 3.11${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ Virtual Environment verwendet nicht Python 3.11. Wird neu erstellt...${NC}"
|
||
rm -rf "$VENV_DIR"
|
||
exec_command "python3.11 -m venv $VENV_DIR" "Erstelle neues Virtual Environment mit Python 3.11"
|
||
fi
|
||
fi
|
||
|
||
# Virtual Environment aktivieren
|
||
echo -e "${BLUE}2. Virtual Environment aktivieren...${NC}"
|
||
source "$VENV_DIR/bin/activate"
|
||
|
||
# Pip upgraden
|
||
echo -e "${BLUE}3. Pip upgraden...${NC}"
|
||
exec_command "pip install --upgrade pip setuptools wheel" "Pip upgraden"
|
||
|
||
# Requirements installieren
|
||
echo -e "${BLUE}4. Backend-Abhängigkeiten installieren...${NC}"
|
||
if [ -f "$BACKEND_DIR/requirements.txt" ]; then
|
||
exec_command "pip install -r $BACKEND_DIR/requirements.txt" "Backend-Abhängigkeiten installieren"
|
||
else
|
||
echo -e "${RED}✗ requirements.txt nicht gefunden in $BACKEND_DIR${NC}"
|
||
return 1
|
||
fi
|
||
|
||
# Verzeichnisse erstellen
|
||
echo -e "${BLUE}5. Backend-Verzeichnisse erstellen...${NC}"
|
||
mkdir -p "$APP_DIR/database"
|
||
mkdir -p "$APP_DIR/logs/app"
|
||
mkdir -p "$APP_DIR/logs/auth"
|
||
mkdir -p "$APP_DIR/logs/jobs"
|
||
mkdir -p "$APP_DIR/logs/printers"
|
||
mkdir -p "$APP_DIR/logs/scheduler"
|
||
mkdir -p "$APP_DIR/logs/errors"
|
||
mkdir -p "$APP_DIR/certs"
|
||
|
||
echo -e "${GREEN}✓ Backend-Verzeichnisse erstellt${NC}"
|
||
|
||
# Datenbank initialisieren
|
||
echo -e "${BLUE}6. Datenbank initialisieren...${NC}"
|
||
cd "$APP_DIR"
|
||
if [ ! -f "database/myp.db" ]; then
|
||
# Explizit Python 3.11 für Datenbank-Initialisierung verwenden
|
||
exec_command "python3.11 -c 'from models import init_database, create_initial_admin; init_database(); create_initial_admin()'" "Datenbank mit Python 3.11 initialisieren"
|
||
else
|
||
echo -e "${YELLOW}Datenbank existiert bereits${NC}"
|
||
fi
|
||
|
||
# SSL-Zertifikate erstellen
|
||
echo -e "${BLUE}7. SSL-Zertifikate erstellen...${NC}"
|
||
read -p "Möchten Sie SSL-Zertifikate erstellen? (j/n, Standard: j): " create_ssl
|
||
if [ "$create_ssl" != "n" ]; then
|
||
create_ssl_certificates
|
||
fi
|
||
|
||
# Alte Services entfernen
|
||
echo -e "${BLUE}8. Alte Services entfernen...${NC}"
|
||
remove_old_services "all"
|
||
|
||
# Backend-Service erstellen
|
||
echo -e "${BLUE}9. Backend-Service erstellen...${NC}"
|
||
create_backend_service
|
||
|
||
# Kiosk-Konfiguration fragen
|
||
echo -e "${BLUE}10. Kiosk-Modus konfigurieren...${NC}"
|
||
read -p "Soll das Backend auch als Kiosk-Web-Interface konfiguriert werden? (j/n, Standard: j): " enable_kiosk
|
||
if [ "$enable_kiosk" != "n" ]; then
|
||
configure_backend_for_kiosk
|
||
fi
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Backend-Installation abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Backend starten:${NC}"
|
||
echo -e "${WHITE}cd $APP_DIR && $python_cmd app.py${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Backend-URLs:${NC}"
|
||
echo -e "${WHITE}- HTTPS Web Interface: https://localhost:443${NC}"
|
||
echo -e "${WHITE}- HTTP Fallback: http://localhost:5000${NC}"
|
||
echo -e "${WHITE}- API Basis: https://localhost:443/api${NC}"
|
||
|
||
if [ "$enable_kiosk" != "n" ]; then
|
||
echo ""
|
||
echo -e "${BLUE}Kiosk-Modus:${NC}"
|
||
echo -e "${WHITE}- Web Interface läuft parallel zur API${NC}"
|
||
echo -e "${WHITE}- Automatischer Browser-Start konfiguriert${NC}"
|
||
echo -e "${WHITE}- Kiosk-Service kann mit 'sudo systemctl start myp-kiosk' gestartet werden${NC}"
|
||
fi
|
||
|
||
deactivate
|
||
cd "$PROJECT_DIR"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# Backend für Kiosk-Modus konfigurieren
|
||
configure_backend_for_kiosk() {
|
||
echo -e "${BLUE}Konfiguriere Backend für Kiosk-Modus...${NC}"
|
||
|
||
# Sicherstellen, dass wir im App-Verzeichnis sind
|
||
cd "$APP_DIR"
|
||
|
||
# Kiosk-Konfiguration in settings.py hinzufügen (falls noch nicht vorhanden)
|
||
if [ -f "config/settings.py" ]; then
|
||
# Prüfen ob Kiosk-Konfiguration bereits vorhanden ist
|
||
if ! grep -q "KIOSK_MODE" "config/settings.py"; then
|
||
# Backup erstellen
|
||
cp "config/settings.py" "config/settings.py.backup.$(date +%Y%m%d_%H%M%S)"
|
||
|
||
# Kiosk-Modus aktivieren
|
||
cat >> "config/settings.py" << 'EOF'
|
||
|
||
# Kiosk-Modus Konfiguration
|
||
KIOSK_MODE = True
|
||
KIOSK_AUTO_LOGIN = True
|
||
KIOSK_FULLSCREEN = True
|
||
KIOSK_HIDE_NAVIGATION = False
|
||
KIOSK_DEFAULT_USER = "kiosk@mercedes-benz.com"
|
||
|
||
# Kiosk-spezifische Flask-Konfiguration
|
||
KIOSK_WEB_INTERFACE = True
|
||
KIOSK_BROWSER_AUTO_START = True
|
||
EOF
|
||
|
||
echo -e "${GREEN}✓ Kiosk-Konfiguration zu settings.py hinzugefügt${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ Kiosk-Konfiguration bereits in settings.py vorhanden${NC}"
|
||
fi
|
||
fi
|
||
|
||
# Systemd Service für Kiosk-Browser erstellen (falls Root)
|
||
remove_old_services "kiosk"
|
||
create_kiosk_service
|
||
|
||
if [ $is_root -eq 1 ]; then
|
||
echo -e "${BLUE}Service wird nicht automatisch gestartet. Verwenden Sie: sudo systemctl enable myp-kiosk-browser${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ Kiosk-Service übersprungen (keine Root-Rechte)${NC}"
|
||
fi
|
||
|
||
# Browser-Autostart für Desktop-Umgebung (alternative Methode)
|
||
echo -e "${BLUE}Konfiguriere Browser-Autostart...${NC}"
|
||
|
||
autostart_dir="$HOME/.config/autostart"
|
||
mkdir -p "$autostart_dir"
|
||
|
||
cat > "$autostart_dir/myp-kiosk.desktop" << EOF
|
||
[Desktop Entry]
|
||
Type=Application
|
||
Name=MYP Kiosk
|
||
Comment=MYP 3D Printer Management Kiosk Interface
|
||
Exec=/bin/bash -c 'sleep 10 && chromium-browser --kiosk --disable-infobars --disable-session-crashed-bubble --disable-translate --no-first-run --start-fullscreen https://localhost:443/'
|
||
X-GNOME-Autostart-enabled=true
|
||
Hidden=false
|
||
NoDisplay=false
|
||
Categories=System;
|
||
StartupNotify=false
|
||
EOF
|
||
|
||
echo -e "${GREEN}✓ Browser-Autostart für Desktop-Umgebung konfiguriert${NC}"
|
||
|
||
# Kiosk-Helper-Skript erstellen
|
||
cat > "$APP_DIR/start_kiosk.sh" << 'EOF'
|
||
#!/bin/bash
|
||
# MYP Kiosk Starter Script
|
||
|
||
echo "🖥️ Starte MYP Kiosk-Modus..."
|
||
|
||
# Warte bis Backend verfügbar ist
|
||
echo "⏳ Warte auf Backend..."
|
||
timeout=60
|
||
counter=0
|
||
while [ $counter -lt $timeout ]; do
|
||
if curl -k -s https://localhost:443/ > /dev/null 2>&1; then
|
||
echo "✅ Backend ist verfügbar!"
|
||
break
|
||
fi
|
||
sleep 2
|
||
counter=$((counter + 2))
|
||
echo " Warte... ($counter/$timeout Sekunden)"
|
||
done
|
||
|
||
if [ $counter -ge $timeout ]; then
|
||
echo "❌ Backend nicht verfügbar nach $timeout Sekunden"
|
||
exit 1
|
||
fi
|
||
|
||
# Browser im Kiosk-Modus starten
|
||
echo "🌐 Starte Browser im Kiosk-Modus..."
|
||
exec chromium-browser \
|
||
--kiosk \
|
||
--disable-infobars \
|
||
--disable-session-crashed-bubble \
|
||
--disable-translate \
|
||
--no-first-run \
|
||
--start-fullscreen \
|
||
--disable-features=VizDisplayCompositor \
|
||
https://localhost:443/
|
||
EOF
|
||
|
||
chmod +x "$APP_DIR/start_kiosk.sh"
|
||
echo -e "${GREEN}✓ Kiosk-Helper-Skript erstellt: $APP_DIR/start_kiosk.sh${NC}"
|
||
|
||
echo -e "${GREEN}✓ Backend für Kiosk-Modus konfiguriert${NC}"
|
||
}
|
||
|
||
# Kiosk-Modus installieren (Einfache Version ohne venv/nginx)
|
||
install_kiosk_mode() {
|
||
show_header "Kiosk-Modus Installation"
|
||
|
||
echo -e "${BLUE}MYP Kiosk-Modus - Einfache Installation${NC}"
|
||
echo ""
|
||
echo -e "${YELLOW}Installiert Backend + Chromium Kiosk ohne venv oder nginx${NC}"
|
||
echo -e "${YELLOW}Backend läuft auf 192.168.0.105:80, automatischer Login als 'user'${NC}"
|
||
echo ""
|
||
|
||
# Prüfe Root-Rechte
|
||
if [ $is_root -ne 1 ]; then
|
||
echo -e "${RED}✗ Root-Rechte erforderlich für Kiosk-Installation${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
# Führe das einfache Kiosk-Installationsskript aus
|
||
echo -e "${BLUE}Starte einfache Kiosk-Installation...${NC}"
|
||
cd "$PROJECT_DIR/backend/install"
|
||
|
||
if [ ! -f "install-kiosk.sh" ]; then
|
||
echo -e "${RED}✗ Kiosk-Installationsskript nicht gefunden${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
# Setze Berechtigungen nur für vorhandene Dateien
|
||
echo -e "${BLUE}Setze Berechtigungen...${NC}"
|
||
chmod +x install-kiosk.sh
|
||
|
||
# Prüfe und setze Berechtigungen nur für existierende Dateien
|
||
[ -f "myp-backend.service" ] && chmod 644 myp-backend.service
|
||
[ -f "myp-kiosk.service" ] && chmod 644 myp-kiosk.service
|
||
[ -f "requirements.txt" ] && chmod 644 requirements.txt
|
||
[ -f "README.md" ] && chmod 644 README.md
|
||
|
||
./install-kiosk.sh
|
||
|
||
# Das Skript startet automatisch neu, daher wird dieser Code nicht erreicht
|
||
echo -e "${GREEN}✓ Kiosk-Installation abgeschlossen${NC}"
|
||
}
|
||
|
||
# Frontend installieren
|
||
install_frontend() {
|
||
show_header "Frontend Installation"
|
||
|
||
echo -e "${BLUE}MYP Frontend (Next.js React App) installieren${NC}"
|
||
echo ""
|
||
|
||
# Node.js prüfen
|
||
if ! check_command node; then
|
||
echo -e "${RED}✗ Node.js nicht gefunden. Bitte installieren Sie Node.js 16+${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
node_version=$(node --version)
|
||
echo -e "${GREEN}✓ Node.js gefunden: $node_version${NC}"
|
||
|
||
# npm prüfen
|
||
if ! check_command npm; then
|
||
echo -e "${RED}✗ npm nicht gefunden. Bitte installieren Sie npm${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
npm_version=$(npm --version)
|
||
echo -e "${GREEN}✓ npm gefunden: $npm_version${NC}"
|
||
|
||
# Frontend-Verzeichnis prüfen
|
||
if [ ! -d "$FRONTEND_DIR" ]; then
|
||
echo -e "${RED}✗ Frontend-Verzeichnis nicht gefunden: $FRONTEND_DIR${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
cd "$FRONTEND_DIR"
|
||
|
||
# Dependencies installieren
|
||
echo -e "${BLUE}1. Frontend-Abhängigkeiten installieren...${NC}"
|
||
exec_command "npm install" "Frontend-Abhängigkeiten installieren"
|
||
|
||
# SSL-Verzeichnis erstellen
|
||
echo -e "${BLUE}2. SSL-Verzeichnis erstellen...${NC}"
|
||
mkdir -p "$FRONTEND_DIR/ssl"
|
||
|
||
# .env.local konfigurieren
|
||
echo -e "${BLUE}3. Frontend-Konfiguration erstellen...${NC}"
|
||
setup_frontend_config
|
||
|
||
# Build erstellen (optional)
|
||
read -p "Möchten Sie das Frontend für Produktion builden? (j/n, Standard: n): " build_frontend
|
||
if [ "$build_frontend" = "j" ]; then
|
||
echo -e "${BLUE}4. Frontend für Produktion builden...${NC}"
|
||
exec_command "npm run build" "Frontend builden"
|
||
fi
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Frontend-Installation abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Frontend starten:${NC}"
|
||
echo -e "${WHITE}cd $FRONTEND_DIR && npm run dev${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Frontend-URLs:${NC}"
|
||
echo -e "${WHITE}- Development: http://localhost:3000${NC}"
|
||
echo -e "${WHITE}- Production: http://localhost:3000${NC}"
|
||
|
||
cd "$PROJECT_DIR"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# Frontend Produktions-Deployment
|
||
deploy_frontend_production() {
|
||
show_header "Frontend Produktions-Deployment (m040tbaraspi001)"
|
||
|
||
echo -e "${BLUE}Starte Frontend-Produktions-Deployment...${NC}"
|
||
echo -e "${YELLOW}Backend-Verbindung: https://raspberrypi${NC}"
|
||
echo ""
|
||
|
||
cd "$FRONTEND_DIR"
|
||
|
||
# Docker-Compose prüfen
|
||
if ! check_command docker-compose; then
|
||
echo -e "${RED}✗ Docker-Compose nicht gefunden${NC}"
|
||
echo -e "${BLUE}Installiere Docker-Compose...${NC}"
|
||
if [ $is_root -eq 1 ]; then
|
||
curl -L "https://github.com/docker/compose/releases/download/v2.20.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
||
chmod +x /usr/local/bin/docker-compose
|
||
else
|
||
echo -e "${RED}Root-Rechte erforderlich für Docker-Compose Installation${NC}"
|
||
return 1
|
||
fi
|
||
fi
|
||
|
||
# Frontend-Konfiguration für Zwei-Server-Setup
|
||
echo -e "${BLUE}1. Frontend-Konfiguration für Zwei-Server-Setup...${NC}"
|
||
setup_frontend_config_two_server
|
||
|
||
# SSL-Zertifikate prüfen/generieren
|
||
echo -e "${BLUE}2. SSL-Zertifikate prüfen...${NC}"
|
||
if [ ! -f "certs/frontend.crt" ] || [ ! -f "certs/frontend.key" ]; then
|
||
echo -e "${YELLOW}SSL-Zertifikate nicht gefunden. Generiere neue...${NC}"
|
||
mkdir -p certs
|
||
|
||
# Frontend-Zertifikat generieren
|
||
openssl req -x509 -newkey rsa:2048 -keyout certs/frontend.key -out certs/frontend.crt -days 365 -nodes \
|
||
-subj "/C=DE/ST=NRW/L=Duesseldorf/O=MYP/OU=Frontend/CN=m040tbaraspi001.de040.corpintra.net"
|
||
|
||
echo -e "${GREEN}✓ SSL-Zertifikate generiert${NC}"
|
||
else
|
||
echo -e "${GREEN}✓ SSL-Zertifikate vorhanden${NC}"
|
||
fi
|
||
|
||
# Docker-Images bauen
|
||
echo -e "${BLUE}3. Docker-Images bauen...${NC}"
|
||
exec_command "docker-compose build --no-cache" "Docker-Images bauen"
|
||
|
||
# Frontend-Container starten
|
||
echo -e "${BLUE}4. Frontend-Container starten...${NC}"
|
||
exec_command "docker-compose up -d" "Frontend-Container starten"
|
||
|
||
# Health-Check
|
||
echo -e "${BLUE}5. Health-Check...${NC}"
|
||
sleep 10
|
||
|
||
if curl -k -s https://localhost:443 > /dev/null; then
|
||
echo -e "${GREEN}✓ Frontend läuft erfolgreich${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ Frontend möglicherweise noch nicht bereit${NC}"
|
||
fi
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Frontend Produktions-Deployment abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🌐 Frontend-URLs:${NC}"
|
||
echo -e "${WHITE}- Extern: https://m040tbaraspi001.de040.corpintra.net${NC}"
|
||
echo -e "${WHITE}- Lokal: https://localhost${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🔗 Backend-Verbindung:${NC}"
|
||
echo -e "${WHITE}- API: https://raspberrypi/api${NC}"
|
||
echo -e "${WHITE}- Backend Web Interface: https://raspberrypi${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🛠️ Management:${NC}"
|
||
echo -e "${WHITE}- Container stoppen: docker-compose down${NC}"
|
||
echo -e "${WHITE}- Logs anzeigen: docker-compose logs -f${NC}"
|
||
echo -e "${WHITE}- Container neustarten: docker-compose restart${NC}"
|
||
|
||
cd "$PROJECT_DIR"
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# Frontend-Konfiguration erstellen
|
||
setup_frontend_config() {
|
||
echo -e "${BLUE}Backend-URL für Frontend konfigurieren:${NC}"
|
||
echo -e "${WHITE}1. Lokale Entwicklung (https://localhost:443)${NC}"
|
||
echo -e "${WHITE}2. Raspberry Pi (https://raspberrypi:443)${NC}"
|
||
echo -e "${WHITE}3. Benutzerdefinierte URL${NC}"
|
||
|
||
read -p "Wählen Sie eine Option (1-3, Standard: 1): " choice
|
||
|
||
backend_url="https://localhost:443"
|
||
|
||
case $choice in
|
||
2)
|
||
backend_url="https://raspberrypi:443"
|
||
;;
|
||
3)
|
||
read -p "Backend-URL eingeben: " backend_url
|
||
;;
|
||
*)
|
||
backend_url="https://localhost:443"
|
||
;;
|
||
esac
|
||
|
||
# .env.local erstellen
|
||
cat > "$FRONTEND_DIR/.env.local" << EOF
|
||
# Backend API Konfiguration
|
||
NEXT_PUBLIC_API_URL=$backend_url
|
||
|
||
# Frontend-URL
|
||
NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000
|
||
|
||
# OAuth Konfiguration
|
||
NEXT_PUBLIC_OAUTH_CALLBACK_URL=http://localhost:3000/auth/login/callback
|
||
|
||
# GitHub OAuth
|
||
GITHUB_CLIENT_ID=7c5d8bef1a5519ec1fdc
|
||
GITHUB_CLIENT_SECRET=5f1e586204358fbd53cf5fb7d418b3f06ccab8fd
|
||
|
||
# Entwicklungsumgebung
|
||
NODE_ENV=development
|
||
DEBUG=true
|
||
NEXT_DEBUG=true
|
||
|
||
# Backend Host
|
||
NEXT_PUBLIC_BACKEND_HOST=$(echo "$backend_url" | sed -E 's|https?://([^:/]+).*|\1|')
|
||
NEXT_PUBLIC_BACKEND_PROTOCOL=$(echo "$backend_url" | sed -E 's|^(https?)://.*|\1|')
|
||
EOF
|
||
|
||
echo -e "${GREEN}✓ Frontend-Konfiguration erstellt: $backend_url${NC}"
|
||
}
|
||
|
||
# Vollinstallationen
|
||
install_everything() {
|
||
show_header "Vollständige Installation (Backend + Frontend)"
|
||
|
||
echo -e "${BLUE}Installiere komplette MYP-Platform...${NC}"
|
||
echo ""
|
||
|
||
# System-Abhängigkeiten (falls Root)
|
||
if [ $is_root -eq 1 ]; then
|
||
install_system_dependencies
|
||
else
|
||
echo -e "${YELLOW}System-Abhängigkeiten übersprungen (keine Root-Rechte)${NC}"
|
||
fi
|
||
|
||
# Backend installieren
|
||
install_backend
|
||
|
||
# Frontend installieren
|
||
install_frontend
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Vollständige Installation abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Nächste Schritte:${NC}"
|
||
echo -e "${WHITE}1. Backend starten: cd $APP_DIR && python app.py${NC}"
|
||
echo -e "${WHITE}2. Frontend starten: cd $FRONTEND_DIR && npm run dev${NC}"
|
||
echo -e "${WHITE}3. Anwendung öffnen: https://localhost:443 (Backend) + http://localhost:3000 (Frontend)${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
install_production_setup() {
|
||
show_header "Produktions-Setup (Backend + Kiosk)"
|
||
|
||
echo -e "${BLUE}Installiere Produktions-Setup für Raspberry Pi...${NC}"
|
||
echo ""
|
||
|
||
# System-Abhängigkeiten (falls Root)
|
||
if [ $is_root -eq 1 ]; then
|
||
install_system_dependencies
|
||
else
|
||
echo -e "${YELLOW}System-Abhängigkeiten übersprungen (keine Root-Rechte)${NC}"
|
||
fi
|
||
|
||
# Backend installieren
|
||
install_backend
|
||
|
||
# Kiosk-Modus installieren
|
||
install_kiosk_mode
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Produktions-Setup abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}System für Produktion konfiguriert:${NC}"
|
||
echo -e "${WHITE}- Backend läuft als Service${NC}"
|
||
echo -e "${WHITE}- Kiosk-Modus aktiviert${NC}"
|
||
echo -e "${WHITE}- Browser startet automatisch${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
install_development_setup() {
|
||
show_header "Entwicklungs-Setup (Backend + Frontend + Tools)"
|
||
|
||
echo -e "${BLUE}Installiere Entwicklungs-Setup...${NC}"
|
||
echo ""
|
||
|
||
# System-Abhängigkeiten (falls Root)
|
||
if [ $is_root -eq 1 ]; then
|
||
install_system_dependencies
|
||
else
|
||
echo -e "${YELLOW}System-Abhängigkeiten übersprungen (keine Root-Rechte)${NC}"
|
||
fi
|
||
|
||
# Backend installieren
|
||
install_backend
|
||
|
||
# Frontend installieren
|
||
install_frontend
|
||
|
||
# Entwicklungstools konfigurieren
|
||
echo -e "${BLUE}Entwicklungstools konfigurieren...${NC}"
|
||
|
||
# Git Hooks (optional)
|
||
if [ -d ".git" ]; then
|
||
echo -e "${BLUE}Git-Repository erkannt${NC}"
|
||
# Hier könnten Git-Hooks konfiguriert werden
|
||
fi
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Entwicklungs-Setup abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Entwicklungsumgebung bereit:${NC}"
|
||
echo -e "${WHITE}- Backend mit Debug-Modus${NC}"
|
||
echo -e "${WHITE}- Frontend mit Hot-Reload${NC}"
|
||
echo -e "${WHITE}- SSL-Zertifikate für HTTPS${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
test_dependencies() {
|
||
show_header "Systemvoraussetzungen prüfen"
|
||
|
||
echo -e "${BLUE}Prüfe Abhängigkeiten...${NC}"
|
||
|
||
local all_installed=1
|
||
|
||
# Python
|
||
if check_command python3; then
|
||
echo -e "${GREEN}✓ Python 3 gefunden${NC}"
|
||
python_version=$(python3 --version 2>&1)
|
||
echo -e "${WHITE} Version: $python_version${NC}"
|
||
elif check_command python; then
|
||
echo -e "${GREEN}✓ Python gefunden${NC}"
|
||
python_version=$(python --version 2>&1)
|
||
echo -e "${WHITE} Version: $python_version${NC}"
|
||
else
|
||
echo -e "${RED}✗ Python nicht gefunden${NC}"
|
||
all_installed=0
|
||
fi
|
||
|
||
# Pip
|
||
if check_command pip3; then
|
||
echo -e "${GREEN}✓ Python Package Manager (pip3) gefunden${NC}"
|
||
elif check_command pip; then
|
||
echo -e "${GREEN}✓ Python Package Manager (pip) gefunden${NC}"
|
||
else
|
||
echo -e "${RED}✗ Python Package Manager (pip) nicht gefunden${NC}"
|
||
all_installed=0
|
||
fi
|
||
|
||
# Node.js
|
||
if check_command node; then
|
||
echo -e "${GREEN}✓ Node.js gefunden${NC}"
|
||
node_version=$(node --version 2>&1)
|
||
echo -e "${WHITE} Version: $node_version${NC}"
|
||
else
|
||
echo -e "${RED}✗ Node.js nicht gefunden${NC}"
|
||
all_installed=0
|
||
fi
|
||
|
||
# npm
|
||
if check_command npm; then
|
||
echo -e "${GREEN}✓ Node Package Manager (npm) gefunden${NC}"
|
||
else
|
||
echo -e "${RED}✗ Node Package Manager (npm) nicht gefunden${NC}"
|
||
all_installed=0
|
||
fi
|
||
|
||
# Git
|
||
if check_command git; then
|
||
echo -e "${GREEN}✓ Git gefunden${NC}"
|
||
else
|
||
echo -e "${RED}✗ Git nicht gefunden${NC}"
|
||
all_installed=0
|
||
fi
|
||
|
||
# OpenSSL
|
||
if check_command openssl; then
|
||
echo -e "${GREEN}✓ OpenSSL gefunden${NC}"
|
||
else
|
||
echo -e "${RED}✗ OpenSSL nicht gefunden${NC}"
|
||
all_installed=0
|
||
fi
|
||
|
||
# SQLite
|
||
if check_command sqlite3; then
|
||
echo -e "${GREEN}✓ SQLite3 gefunden${NC}"
|
||
else
|
||
echo -e "${RED}✗ SQLite3 nicht gefunden${NC}"
|
||
all_installed=0
|
||
fi
|
||
|
||
echo ""
|
||
if [ $all_installed -eq 1 ]; then
|
||
echo -e "${GREEN}✓ Alle Abhängigkeiten sind installiert!${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ Einige Abhängigkeiten fehlen. Nutzen Sie 'System-Abhängigkeiten installieren'.${NC}"
|
||
fi
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
setup_hosts() {
|
||
show_header "Host-Konfiguration"
|
||
|
||
if [ $is_root -eq 0 ]; then
|
||
echo -e "${RED}Diese Funktion erfordert Root-Rechte.${NC}"
|
||
echo -e "${YELLOW}Bitte starten Sie das Skript mit sudo oder als Root neu.${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
local_ip=$(get_local_ip)
|
||
echo -e "${GREEN}Lokale IP-Adresse: $local_ip${NC}"
|
||
|
||
hosts_file="/etc/hosts"
|
||
echo -e "${BLUE}Hosts-Datei: $hosts_file${NC}"
|
||
|
||
# Prüfen, ob die Einträge bereits existieren
|
||
frontend_entry=$(grep "m040tbaraspi001.de040.corpintra.net" $hosts_file)
|
||
backend_entry=$(grep "raspberrypi" $hosts_file)
|
||
|
||
# Einträge in die Hosts-Datei schreiben
|
||
echo -e "${BLUE}Aktualisiere Hosts-Datei...${NC}"
|
||
|
||
if [ -z "$frontend_entry" ]; then
|
||
echo "" >> $hosts_file
|
||
echo "# MYP Frontend Host" >> $hosts_file
|
||
echo "$local_ip m040tbaraspi001.de040.corpintra.net m040tbaraspi001" >> $hosts_file
|
||
echo -e "${GREEN}Frontend-Hostname hinzugefügt${NC}"
|
||
else
|
||
echo -e "${YELLOW}Frontend-Hostname ist bereits konfiguriert${NC}"
|
||
fi
|
||
|
||
if [ -z "$backend_entry" ]; then
|
||
echo "" >> $hosts_file
|
||
echo "# MYP Backend Host" >> $hosts_file
|
||
echo "$local_ip raspberrypi" >> $hosts_file
|
||
echo -e "${GREEN}Backend-Hostname hinzugefügt${NC}"
|
||
else
|
||
echo -e "${YELLOW}Backend-Hostname ist bereits konfiguriert${NC}"
|
||
fi
|
||
|
||
echo -e "${GREEN}Konfiguration abgeschlossen!${NC}"
|
||
|
||
echo ""
|
||
echo -e "${BLUE}Folgende Hostnamen sind jetzt konfiguriert:${NC}"
|
||
echo -e "${WHITE} - Frontend: m040tbaraspi001.de040.corpintra.net${NC}"
|
||
echo -e "${WHITE} - Backend: raspberrypi${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
test_backend_connection() {
|
||
show_header "Backend-Verbindung prüfen"
|
||
|
||
echo -e "${BLUE}Welches Backend möchten Sie testen?${NC}"
|
||
echo -e "${WHITE}1. Lokales Backend (localhost:443)${NC}"
|
||
echo -e "${WHITE}2. Raspberry Pi Backend (raspberrypi:443)${NC}"
|
||
echo -e "${WHITE}3. Benutzerdefinierte URL${NC}"
|
||
|
||
read -p "Wählen Sie eine Option (1-3, Standard: 1): " choice
|
||
|
||
backend_url="https://localhost:443"
|
||
backend_host="localhost"
|
||
|
||
case $choice in
|
||
2)
|
||
backend_url="https://raspberrypi:443"
|
||
backend_host="raspberrypi"
|
||
;;
|
||
3)
|
||
read -p "Backend-URL eingeben (z.B. https://raspberrypi:443): " backend_url
|
||
backend_host=$(echo "$backend_url" | sed -E 's|https?://([^:/]+).*|\1|')
|
||
;;
|
||
*)
|
||
backend_url="https://localhost:443"
|
||
backend_host="localhost"
|
||
;;
|
||
esac
|
||
|
||
echo ""
|
||
echo -e "${BLUE}Teste Backend: $backend_url${NC}"
|
||
echo ""
|
||
|
||
# 1. Netzwerk-Konnektivität prüfen
|
||
echo -e "${BLUE}1. Prüfe Netzwerk-Konnektivität zu $backend_host...${NC}"
|
||
if ping -c 1 -W 3 "$backend_host" >/dev/null 2>&1; then
|
||
echo -e "${GREEN}✓ Ping zu $backend_host erfolgreich${NC}"
|
||
else
|
||
echo -e "${RED}✗ Ping zu $backend_host fehlgeschlagen${NC}"
|
||
fi
|
||
|
||
# 2. Backend-Service prüfen
|
||
echo -e "${BLUE}2. Prüfe Backend-Service...${NC}"
|
||
health_url="$backend_url/health"
|
||
if curl -f --connect-timeout 5 "$health_url" >/dev/null 2>&1; then
|
||
echo -e "${GREEN}✓ Backend-Health-Check erfolgreich${NC}"
|
||
elif curl -f --connect-timeout 5 "$backend_url" >/dev/null 2>&1; then
|
||
echo -e "${YELLOW}⚠ Backend erreichbar, aber kein Health-Endpoint${NC}"
|
||
else
|
||
echo -e "${RED}✗ Backend-Service nicht erreichbar${NC}"
|
||
fi
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
setup_backend_url() {
|
||
local backend_url="$1"
|
||
|
||
show_header "Backend-URL konfigurieren"
|
||
|
||
if [ -z "$backend_url" ]; then
|
||
echo -e "${BLUE}Verfügbare Backend-Konfigurationen:${NC}"
|
||
echo -e "${WHITE}1. Lokale Entwicklung (https://localhost:443)${NC}"
|
||
echo -e "${WHITE}2. Raspberry Pi (https://raspberrypi:443)${NC}"
|
||
echo -e "${WHITE}3. Benutzerdefinierte URL${NC}"
|
||
|
||
read -p "Wählen Sie eine Option (1-3, Standard: 1): " choice
|
||
|
||
case $choice in
|
||
2)
|
||
backend_url="https://raspberrypi:443"
|
||
;;
|
||
3)
|
||
read -p "Backend-URL eingeben (z.B. https://raspberrypi:443): " backend_url
|
||
;;
|
||
*)
|
||
backend_url="https://localhost:443"
|
||
;;
|
||
esac
|
||
fi
|
||
|
||
echo -e "${BLUE}Konfiguriere Frontend für Backend: $backend_url${NC}"
|
||
|
||
# .env.local erstellen/aktualisieren
|
||
env_local_path="frontend/.env.local"
|
||
backend_host=$(echo "$backend_url" | sed -E 's|https?://([^:/]+).*|\1|')
|
||
backend_protocol=$(echo "$backend_url" | sed -E 's|^(https?)://.*|\1|')
|
||
|
||
cat > "$env_local_path" << EOF
|
||
# Backend API Konfiguration
|
||
NEXT_PUBLIC_API_URL=$backend_url
|
||
|
||
# Frontend-URL
|
||
NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000
|
||
|
||
# OAuth Konfiguration
|
||
NEXT_PUBLIC_OAUTH_CALLBACK_URL=http://localhost:3000/auth/login/callback
|
||
|
||
# GitHub OAuth (hardcodiert)
|
||
GITHUB_CLIENT_ID=7c5d8bef1a5519ec1fdc
|
||
GITHUB_CLIENT_SECRET=5f1e586204358fbd53cf5fb7d418b3f06ccab8fd
|
||
|
||
# Entwicklungsumgebung
|
||
NODE_ENV=development
|
||
DEBUG=true
|
||
NEXT_DEBUG=true
|
||
|
||
# Backend Host
|
||
NEXT_PUBLIC_BACKEND_HOST=$backend_host
|
||
NEXT_PUBLIC_BACKEND_PROTOCOL=$backend_protocol
|
||
EOF
|
||
|
||
if [ $? -eq 0 ]; then
|
||
echo -e "${GREEN}✓ .env.local erfolgreich erstellt/aktualisiert${NC}"
|
||
else
|
||
echo -e "${RED}✗ Fehler beim Erstellen der .env.local${NC}"
|
||
fi
|
||
|
||
echo ""
|
||
echo -e "${GREEN}Frontend-Konfiguration abgeschlossen!${NC}"
|
||
echo -e "${WHITE}Backend: $backend_url${NC}"
|
||
echo -e "${WHITE}Frontend: http://localhost:3000${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
start_application() {
|
||
show_header "Anwendung starten"
|
||
|
||
echo -e "${BLUE}Welche Komponente möchten Sie starten?${NC}"
|
||
echo -e "${WHITE}1. Backend-Server starten (Flask API)${NC}"
|
||
echo -e "${WHITE}2. Frontend-Server starten (Next.js)${NC}"
|
||
echo -e "${WHITE}3. Kiosk-Modus starten (Backend Web Interface)${NC}"
|
||
echo -e "${WHITE}4. Beide Server starten (Backend + Frontend)${NC}"
|
||
echo -e "${WHITE}5. Frontend Produktions-Deployment (Port 80/443 mit SSL)${NC}"
|
||
echo -e "${WHITE}6. Debug-Server starten${NC}"
|
||
echo -e "${WHITE}7. Zurück zum Hauptmenü${NC}"
|
||
|
||
read -p "Wählen Sie eine Option (1-7): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
echo -e "${BLUE}Starte Backend-Server...${NC}"
|
||
if [ -d "$VENV_DIR" ]; then
|
||
cd "$APP_DIR"
|
||
source "$VENV_DIR/bin/activate"
|
||
python3.11 app.py &
|
||
echo -e "${GREEN}Backend-Server gestartet: https://localhost:443${NC}"
|
||
deactivate
|
||
cd "$PROJECT_DIR"
|
||
else
|
||
echo -e "${RED}Backend nicht installiert. Bitte installieren Sie zuerst das Backend.${NC}"
|
||
fi
|
||
;;
|
||
2)
|
||
echo -e "${BLUE}Starte Frontend-Server...${NC}"
|
||
if [ -d "$FRONTEND_DIR/node_modules" ]; then
|
||
cd "$FRONTEND_DIR"
|
||
npm run dev &
|
||
echo -e "${GREEN}Frontend-Server gestartet: http://localhost:3000${NC}"
|
||
cd "$PROJECT_DIR"
|
||
else
|
||
echo -e "${RED}Frontend nicht installiert. Bitte installieren Sie zuerst das Frontend.${NC}"
|
||
fi
|
||
;;
|
||
3)
|
||
echo -e "${BLUE}Starte Kiosk-Modus...${NC}"
|
||
if [ $is_root -eq 1 ]; then
|
||
systemctl start myp-kiosk
|
||
echo -e "${GREEN}Kiosk-Modus gestartet${NC}"
|
||
else
|
||
echo -e "${RED}Root-Rechte erforderlich für Kiosk-Service${NC}"
|
||
fi
|
||
;;
|
||
4)
|
||
echo -e "${BLUE}Starte Backend und Frontend...${NC}"
|
||
# Backend starten
|
||
if [ -d "$VENV_DIR" ]; then
|
||
cd "$APP_DIR"
|
||
source "$VENV_DIR/bin/activate"
|
||
python3.11 app.py &
|
||
echo -e "${GREEN}Backend gestartet: https://localhost:443${NC}"
|
||
deactivate
|
||
cd "$PROJECT_DIR"
|
||
fi
|
||
# Frontend starten
|
||
if [ -d "$FRONTEND_DIR/node_modules" ]; then
|
||
cd "$FRONTEND_DIR"
|
||
npm run dev &
|
||
echo -e "${GREEN}Frontend gestartet: http://localhost:3000${NC}"
|
||
cd "$PROJECT_DIR"
|
||
fi
|
||
;;
|
||
5)
|
||
deploy_frontend_production
|
||
;;
|
||
6)
|
||
start_debug_server
|
||
;;
|
||
7)
|
||
show_main_menu
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option.${NC}"
|
||
;;
|
||
esac
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
start_debug_server() {
|
||
show_header "Debug-Server starten"
|
||
|
||
echo -e "${BLUE}Welchen Debug-Server möchten Sie starten?${NC}"
|
||
echo -e "${WHITE}1. Frontend Debug-Server (Next.js Development)${NC}"
|
||
echo -e "${WHITE}2. Backend Debug-Server (Flask Debug Mode)${NC}"
|
||
echo -e "${WHITE}3. Einfacher HTTP-Server (Debug-Server Verzeichnis)${NC}"
|
||
|
||
read -p "Wählen Sie eine Option (1-3): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
if [ -d "$FRONTEND_DIR" ]; then
|
||
cd "$FRONTEND_DIR"
|
||
npm run dev
|
||
cd "$PROJECT_DIR"
|
||
else
|
||
echo -e "${RED}Frontend-Verzeichnis nicht gefunden${NC}"
|
||
fi
|
||
;;
|
||
2)
|
||
if [ -d "$VENV_DIR" ]; then
|
||
cd "$APP_DIR"
|
||
source "$VENV_DIR/bin/activate"
|
||
python3.11 app.py --debug
|
||
deactivate
|
||
cd "$PROJECT_DIR"
|
||
else
|
||
echo -e "${RED}Backend nicht installiert${NC}"
|
||
fi
|
||
;;
|
||
3)
|
||
debug_dir="$FRONTEND_DIR/debug-server"
|
||
if [ -d "$debug_dir" ]; then
|
||
cd "$debug_dir"
|
||
if check_command node; then
|
||
node src/app.js
|
||
else
|
||
echo -e "${RED}Node.js nicht gefunden${NC}"
|
||
fi
|
||
cd "$PROJECT_DIR"
|
||
else
|
||
echo -e "${RED}Debug-Server-Verzeichnis nicht gefunden${NC}"
|
||
fi
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option${NC}"
|
||
;;
|
||
esac
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
show_ssl_status() {
|
||
show_header "SSL-Zertifikat-Status"
|
||
|
||
cert_paths=(
|
||
"backend/app/certs/myp.crt"
|
||
"backend/app/certs/myp.key"
|
||
"frontend/ssl/myp.crt"
|
||
"frontend/ssl/myp.key"
|
||
)
|
||
|
||
echo -e "${BLUE}Prüfe SSL-Zertifikate...${NC}"
|
||
echo ""
|
||
|
||
for cert_path in "${cert_paths[@]}"; do
|
||
if [ -f "$cert_path" ]; then
|
||
echo -e "${GREEN}✓ Gefunden: $cert_path${NC}"
|
||
|
||
# Zertifikatsinformationen anzeigen (falls OpenSSL verfügbar)
|
||
if check_command openssl && [[ "$cert_path" == *.crt ]]; then
|
||
cert_info=$(openssl x509 -in "$cert_path" -noout -subject -dates 2>/dev/null)
|
||
if [ -n "$cert_info" ]; then
|
||
echo -e "${WHITE} $cert_info${NC}"
|
||
fi
|
||
fi
|
||
else
|
||
echo -e "${RED}✗ Fehlt: $cert_path${NC}"
|
||
fi
|
||
done
|
||
|
||
echo ""
|
||
echo -e "${BLUE}SSL-Konfiguration in settings.py:${NC}"
|
||
settings_path="backend/app/config/settings.py"
|
||
if [ -f "$settings_path" ]; then
|
||
if grep -q "SSL_ENABLED.*=.*True" "$settings_path"; then
|
||
echo -e "${GREEN}✓ SSL ist aktiviert${NC}"
|
||
else
|
||
echo -e "${YELLOW}⚠ SSL ist deaktiviert${NC}"
|
||
fi
|
||
else
|
||
echo -e "${RED}✗ settings.py nicht gefunden${NC}"
|
||
fi
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
create_ssl_certificates() {
|
||
show_header "SSL-Zertifikat-Generator"
|
||
|
||
# Parameter definieren
|
||
cert_dir="./backend/app/certs"
|
||
backend_cert_file="$cert_dir/myp.crt"
|
||
backend_key_file="$cert_dir/myp.key"
|
||
frontend_cert_file="$cert_dir/frontend.crt"
|
||
frontend_key_file="$cert_dir/frontend.key"
|
||
|
||
echo -e "${BLUE}Zertifikate werden für folgende Hostnamen erstellt:${NC}"
|
||
|
||
# Hostname-Auswahl
|
||
echo -e "${WHITE}1. Für lokale Entwicklung (localhost)${NC}"
|
||
echo -e "${WHITE}2. Für Raspberry Pi Deployment (raspberrypi)${NC}"
|
||
echo -e "${WHITE}3. Für Unternehmens-Setup (m040tbaraspi001.de040.corpintra.net)${NC}"
|
||
|
||
read -p "Wählen Sie eine Option (1-3, Standard: 1): " choice
|
||
|
||
backend_hostname="localhost"
|
||
frontend_hostname="localhost"
|
||
|
||
case $choice in
|
||
2)
|
||
backend_hostname="raspberrypi"
|
||
frontend_hostname="raspberrypi"
|
||
;;
|
||
3)
|
||
backend_hostname="raspberrypi"
|
||
frontend_hostname="m040tbaraspi001.de040.corpintra.net"
|
||
;;
|
||
*)
|
||
backend_hostname="localhost"
|
||
frontend_hostname="localhost"
|
||
;;
|
||
esac
|
||
|
||
echo -e "${BLUE}Backend-Hostname: $backend_hostname${NC}"
|
||
echo -e "${BLUE}Frontend-Hostname: $frontend_hostname${NC}"
|
||
echo ""
|
||
|
||
# Verzeichnis erstellen, falls es nicht existiert
|
||
if [ ! -d "$cert_dir" ]; then
|
||
echo -e "${BLUE}Erstelle Verzeichnis $cert_dir...${NC}"
|
||
mkdir -p "$cert_dir"
|
||
fi
|
||
|
||
# SSL-Zertifikate mit Python und cryptography erstellen
|
||
echo -e "${BLUE}Erstelle SSL-Zertifikate mit Python...${NC}"
|
||
|
||
# Überprüfen, ob Python verfügbar ist (bevorzugt Python 3.11)
|
||
python_cmd=""
|
||
if check_command python3.11; then
|
||
python_cmd="python3.11"
|
||
elif check_command python3; then
|
||
python_cmd="python3"
|
||
elif check_command python; then
|
||
python_cmd="python"
|
||
else
|
||
echo -e "${RED}Python nicht gefunden. SSL-Zertifikate können nicht erstellt werden.${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
# Python-Skript zur Zertifikatserstellung erstellen
|
||
cat > temp_cert_script.py << EOL
|
||
#!/usr/bin/env python3
|
||
import os
|
||
import datetime
|
||
import sys
|
||
|
||
try:
|
||
from cryptography import x509
|
||
from cryptography.x509.oid import NameOID
|
||
from cryptography.hazmat.primitives import hashes
|
||
from cryptography.hazmat.primitives.asymmetric import rsa
|
||
from cryptography.hazmat.primitives.serialization import Encoding, PrivateFormat, NoEncryption
|
||
import ipaddress
|
||
except ImportError as e:
|
||
print(f"Fehler: Paket nicht gefunden: {e}")
|
||
print("Bitte installieren Sie es mit: pip install cryptography")
|
||
sys.exit(1)
|
||
|
||
def create_self_signed_cert(cert_path, key_path, hostname="localhost"):
|
||
# Verzeichnis erstellen, falls es nicht existiert
|
||
cert_dir = os.path.dirname(cert_path)
|
||
if cert_dir and not os.path.exists(cert_dir):
|
||
os.makedirs(cert_dir, exist_ok=True)
|
||
|
||
# Privaten Schlüssel generieren
|
||
private_key = rsa.generate_private_key(
|
||
public_exponent=65537,
|
||
key_size=4096,
|
||
)
|
||
|
||
# Schlüsseldatei schreiben
|
||
with open(key_path, "wb") as key_file:
|
||
key_file.write(private_key.private_bytes(
|
||
encoding=Encoding.PEM,
|
||
format=PrivateFormat.TraditionalOpenSSL,
|
||
encryption_algorithm=NoEncryption()
|
||
))
|
||
|
||
# Aktuelles Datum und Ablaufdatum berechnen
|
||
now = datetime.datetime.now()
|
||
valid_until = now + datetime.timedelta(days=3650) # 10 Jahre gültig
|
||
|
||
# Name für das Zertifikat erstellen
|
||
subject = issuer = x509.Name([
|
||
x509.NameAttribute(NameOID.COMMON_NAME, hostname),
|
||
x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Mercedes-Benz AG"),
|
||
x509.NameAttribute(NameOID.ORGANIZATIONAL_UNIT_NAME, "Werk 040 Berlin"),
|
||
x509.NameAttribute(NameOID.COUNTRY_NAME, "DE"),
|
||
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Berlin"),
|
||
x509.NameAttribute(NameOID.LOCALITY_NAME, "Berlin")
|
||
])
|
||
|
||
# Zertifikat erstellen
|
||
cert = x509.CertificateBuilder().subject_name(
|
||
subject
|
||
).issuer_name(
|
||
issuer
|
||
).public_key(
|
||
private_key.public_key()
|
||
).serial_number(
|
||
x509.random_serial_number()
|
||
).not_valid_before(
|
||
now
|
||
).not_valid_after(
|
||
valid_until
|
||
).add_extension(
|
||
x509.SubjectAlternativeName([
|
||
x509.DNSName(hostname),
|
||
x509.DNSName("localhost"),
|
||
x509.IPAddress(ipaddress.IPv4Address("127.0.0.1"))
|
||
]),
|
||
critical=False,
|
||
).add_extension(
|
||
x509.BasicConstraints(ca=True, path_length=None), critical=True
|
||
).add_extension(
|
||
x509.KeyUsage(
|
||
digital_signature=True,
|
||
content_commitment=False,
|
||
key_encipherment=True,
|
||
data_encipherment=False,
|
||
key_agreement=False,
|
||
key_cert_sign=True,
|
||
crl_sign=True,
|
||
encipher_only=False,
|
||
decipher_only=False
|
||
), critical=True
|
||
).add_extension(
|
||
x509.ExtendedKeyUsage([
|
||
x509.oid.ExtendedKeyUsageOID.SERVER_AUTH,
|
||
x509.oid.ExtendedKeyUsageOID.CLIENT_AUTH
|
||
]), critical=False
|
||
).sign(private_key, hashes.SHA256())
|
||
|
||
# Zertifikatsdatei schreiben
|
||
with open(cert_path, "wb") as cert_file:
|
||
cert_file.write(cert.public_bytes(Encoding.PEM))
|
||
|
||
print(f"SSL-Zertifikat für '{hostname}' erstellt:")
|
||
print(f"Zertifikat: {cert_path}")
|
||
print(f"Schlüssel: {key_path}")
|
||
|
||
# Backend-Zertifikat erstellen
|
||
create_self_signed_cert('$backend_cert_file', '$backend_key_file', '$backend_hostname')
|
||
|
||
# Frontend SSL-Verzeichnis
|
||
frontend_ssl_dir = './frontend/ssl'
|
||
os.makedirs(frontend_ssl_dir, exist_ok=True)
|
||
|
||
# Frontend-Zertifikat erstellen (Kopie des Backend-Zertifikats)
|
||
import shutil
|
||
shutil.copy('$backend_cert_file', './frontend/ssl/myp.crt')
|
||
shutil.copy('$backend_key_file', './frontend/ssl/myp.key')
|
||
|
||
print("SSL-Zertifikate erfolgreich erstellt!")
|
||
EOL
|
||
|
||
# Python-Skript ausführen
|
||
if $python_cmd temp_cert_script.py; then
|
||
echo -e "${GREEN}SSL-Zertifikate erfolgreich erstellt!${NC}"
|
||
else
|
||
echo -e "${RED}Fehler beim Erstellen der SSL-Zertifikate.${NC}"
|
||
fi
|
||
|
||
# Temporäres Skript löschen
|
||
rm -f temp_cert_script.py
|
||
|
||
echo ""
|
||
echo -e "${BLUE}SSL-Zertifikate wurden erstellt:${NC}"
|
||
echo -e "${WHITE}- Backend: $backend_cert_file${NC}"
|
||
echo -e "${WHITE}- Frontend: frontend/ssl/myp.crt${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
show_project_info() {
|
||
show_header "Projekt-Informationen"
|
||
|
||
echo -e "${CYAN}MYP (Mercedes-Benz Yard Printing) Platform${NC}"
|
||
echo -e "${BLUE}Version 4.0${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Beschreibung:${NC}"
|
||
echo -e "${WHITE}Eine vollständige 3D-Drucker-Management-Plattform für Mercedes-Benz Werk 040 Berlin.${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Komponenten:${NC}"
|
||
echo -e "${WHITE}- Backend: Flask-basierte REST API${NC}"
|
||
echo -e "${WHITE}- Frontend: Next.js React-Anwendung${NC}"
|
||
echo -e "${WHITE}- Kiosk-Modus: Backend Web Interface${NC}"
|
||
echo -e "${WHITE}- Datenbank: SQLite${NC}"
|
||
echo -e "${WHITE}- Authentifizierung: GitHub OAuth + lokale Benutzer${NC}"
|
||
echo -e "${WHITE}- SSL/TLS: Selbstsignierte Zertifikate${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Standard-Zugangsdaten:${NC}"
|
||
echo -e "${WHITE}- Admin E-Mail: admin@mercedes-benz.com${NC}"
|
||
echo -e "${WHITE}- Admin Passwort: 744563017196A${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}URLs:${NC}"
|
||
echo -e "${WHITE}- Backend API: https://localhost:443${NC}"
|
||
echo -e "${WHITE}- Frontend: http://localhost:3000${NC}"
|
||
echo -e "${WHITE}- Kiosk-Modus: https://localhost:443 (Vollbild)${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}Deployment-Modi:${NC}"
|
||
echo -e "${WHITE}- Entwicklung: Backend + Frontend getrennt${NC}"
|
||
echo -e "${WHITE}- Produktion: Backend + Kiosk-Modus${NC}"
|
||
echo -e "${WHITE}- Vollständig: Alle Komponenten${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
clean_old_files() {
|
||
show_header "Alte Dateien bereinigen"
|
||
|
||
read -p "Möchten Sie alte Skriptdateien und temporäre Dateien löschen? (j/n): " clean_files
|
||
|
||
if [ "$clean_files" = "j" ]; then
|
||
files_to_delete=(
|
||
"setup_hosts.sh"
|
||
"setup_ssl.sh"
|
||
"generate_ssl_certs.sh"
|
||
"temp_cert_script.py"
|
||
"frontend/cleanup.sh"
|
||
"frontend/install.sh"
|
||
"frontend/https-setup.sh"
|
||
"frontend/start-debug-server.sh"
|
||
"frontend/start-frontend-server.sh"
|
||
"frontend/check-backend-connection.sh"
|
||
"frontend/setup-backend-url.sh"
|
||
"frontend/start-debug-server.bat"
|
||
"backend/setup_myp.sh"
|
||
"backend/install/create_ssl_cert.sh"
|
||
"backend/install/ssl_check.sh"
|
||
)
|
||
|
||
for file in "${files_to_delete[@]}"; do
|
||
if [ -f "$file" ]; then
|
||
rm -f "$file"
|
||
echo -e "${GREEN}✓ Gelöscht: $file${NC}"
|
||
fi
|
||
done
|
||
|
||
echo -e "${GREEN}Bereinigung abgeschlossen!${NC}"
|
||
else
|
||
echo -e "${BLUE}Bereinigung übersprungen.${NC}"
|
||
fi
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# Installationsmenü anzeigen
|
||
show_installation_menu() {
|
||
show_header "Installations-Menü"
|
||
|
||
echo -e "${WHITE}📦 SYSTEM-KOMPONENTEN:${NC}"
|
||
echo -e "${WHITE}1. System-Abhängigkeiten installieren${NC}"
|
||
echo -e "${WHITE}2. Python & Node.js Umgebung einrichten${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}🔧 HAUPT-KOMPONENTEN:${NC}"
|
||
echo -e "${WHITE}3. Backend installieren (Flask API + Web Interface)${NC}"
|
||
echo -e "${WHITE}4. Frontend installieren (Next.js React)${NC}"
|
||
echo -e "${WHITE}5. Kiosk-Modus installieren (Backend Web Interface + Browser)${NC}"
|
||
echo -e "${WHITE}6. Frontend Produktions-Deployment (Port 80/443 mit SSL)${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}🎯 VOLLINSTALLATIONEN:${NC}"
|
||
echo -e "${WHITE}7. Alles installieren (Backend + Frontend)${NC}"
|
||
echo -e "${WHITE}8. Produktions-Setup (Backend + Kiosk Web Interface)${NC}"
|
||
echo -e "${WHITE}9. Entwicklungs-Setup (Backend + Frontend + Tools)${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}⚙️ KONFIGURATION:${NC}"
|
||
echo -e "${WHITE}10. SSL-Zertifikate erstellen${NC}"
|
||
echo -e "${WHITE}11. Host-Konfiguration einrichten${NC}"
|
||
echo -e "${WHITE}12. Backend-URL konfigurieren${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}🔍 SYSTEM & TESTS:${NC}"
|
||
echo -e "${WHITE}13. Systemvoraussetzungen prüfen${NC}"
|
||
echo -e "${WHITE}14. Backend-Verbindung testen${NC}"
|
||
echo -e "${WHITE}15. SSL-Status anzeigen${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}🚀 ANWENDUNG STARTEN:${NC}"
|
||
echo -e "${WHITE}16. Server starten (Backend/Frontend/Kiosk)${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}ℹ️ SONSTIGES:${NC}"
|
||
echo -e "${WHITE}17. Projekt-Informationen${NC}"
|
||
echo -e "${WHITE}18. Alte Dateien bereinigen${NC}"
|
||
echo -e "${WHITE}19. Zurück zum Hauptmenü${NC}"
|
||
echo -e "${WHITE}0. Beenden${NC}"
|
||
echo ""
|
||
|
||
read -p "Wählen Sie eine Option (0-19): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
install_system_dependencies
|
||
show_installation_menu
|
||
;;
|
||
2)
|
||
setup_python_node_environment
|
||
show_installation_menu
|
||
;;
|
||
3)
|
||
install_backend
|
||
show_installation_menu
|
||
;;
|
||
4)
|
||
install_frontend
|
||
show_installation_menu
|
||
;;
|
||
5)
|
||
install_kiosk_mode
|
||
show_installation_menu
|
||
;;
|
||
6)
|
||
deploy_frontend_production
|
||
show_installation_menu
|
||
;;
|
||
7)
|
||
install_everything
|
||
show_installation_menu
|
||
;;
|
||
8)
|
||
install_production_setup
|
||
show_installation_menu
|
||
;;
|
||
9)
|
||
install_development_setup
|
||
show_installation_menu
|
||
;;
|
||
10)
|
||
install_development_setup
|
||
show_installation_menu
|
||
;;
|
||
11)
|
||
setup_hosts
|
||
show_installation_menu
|
||
;;
|
||
12)
|
||
setup_backend_url
|
||
show_installation_menu
|
||
;;
|
||
13)
|
||
test_dependencies
|
||
show_installation_menu
|
||
;;
|
||
14)
|
||
test_backend_connection
|
||
show_installation_menu
|
||
;;
|
||
15)
|
||
show_ssl_status
|
||
show_installation_menu
|
||
;;
|
||
16)
|
||
start_application
|
||
;;
|
||
17)
|
||
show_project_info
|
||
show_installation_menu
|
||
;;
|
||
18)
|
||
clean_old_files
|
||
show_installation_menu
|
||
;;
|
||
19)
|
||
show_main_menu
|
||
;;
|
||
0)
|
||
echo -e "${GREEN}Auf Wiedersehen!${NC}"
|
||
exit 0
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option. Bitte versuchen Sie es erneut.${NC}"
|
||
sleep 2
|
||
show_installation_menu
|
||
;;
|
||
esac
|
||
}
|
||
|
||
# Hauptmenü anzeigen
|
||
show_main_menu() {
|
||
show_header "🎯 MYP Control Center - Hauptmenü"
|
||
|
||
echo -e "${WHITE}🚀 Schnell-Installation:${NC}"
|
||
echo -e "${WHITE}1. 🖥️ Kiosk-Modus installieren (Einfach - Backend + Chromium)${NC}"
|
||
echo -e "${WHITE}2. 🔧 Vollständige Installation (Backend + Frontend)${NC}"
|
||
echo -e "${WHITE}3. 🥧 Backend-Only Installation${NC}"
|
||
echo -e "${WHITE}4. 🌐 Frontend-Only Installation${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}⚙️ Granulare Installation:${NC}"
|
||
echo -e "${WHITE}5. Backend installieren (Flask API + Web Interface)${NC}"
|
||
echo -e "${WHITE}6. Frontend installieren (Next.js)${NC}"
|
||
echo -e "${WHITE}7. System-Abhängigkeiten installieren${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}🛠️ Entwicklung & Wartung:${NC}"
|
||
echo -e "${WHITE}8. Entwicklungs-Setup${NC}"
|
||
echo -e "${WHITE}9. SSL-Zertifikate generieren${NC}"
|
||
echo -e "${WHITE}10. Logs anzeigen${NC}"
|
||
echo -e "${WHITE}11. Services verwalten${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}0. Beenden${NC}"
|
||
echo ""
|
||
|
||
read -p "Wählen Sie eine Option (0-11): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
install_kiosk_mode
|
||
;;
|
||
2)
|
||
install_full_setup
|
||
;;
|
||
3)
|
||
install_backend_only
|
||
;;
|
||
4)
|
||
install_frontend_only
|
||
;;
|
||
5)
|
||
install_backend
|
||
;;
|
||
6)
|
||
install_frontend
|
||
;;
|
||
7)
|
||
install_system_dependencies
|
||
;;
|
||
8)
|
||
install_development_setup
|
||
;;
|
||
9)
|
||
generate_ssl_certificates
|
||
;;
|
||
10)
|
||
show_logs
|
||
;;
|
||
11)
|
||
manage_services
|
||
;;
|
||
0)
|
||
echo -e "${GREEN}Auf Wiedersehen!${NC}"
|
||
exit 0
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option${NC}"
|
||
sleep 2
|
||
show_main_menu
|
||
;;
|
||
esac
|
||
}
|
||
|
||
# ========================================================
|
||
# SERVER-DETECTION & ZWEI-SERVER-SETUP
|
||
# ========================================================
|
||
|
||
# Server-Typ erkennen
|
||
detect_server_type() {
|
||
local hostname=$(hostname)
|
||
local hostname_fqdn=$(hostname -f 2>/dev/null || echo "$hostname")
|
||
|
||
echo -e "${BLUE}Erkenne Server-Typ...${NC}"
|
||
echo -e "${WHITE}Hostname: $hostname${NC}"
|
||
echo -e "${WHITE}FQDN: $hostname_fqdn${NC}"
|
||
|
||
# Frontend-Server erkennen
|
||
if [[ "$hostname" == *"m040tbaraspi001"* ]] || [[ "$hostname_fqdn" == *"m040tbaraspi001"* ]]; then
|
||
echo "frontend"
|
||
return
|
||
fi
|
||
|
||
# Backend-Server (Raspberry Pi) erkennen
|
||
if [[ "$hostname" == *"raspberrypi"* ]] || [[ "$hostname_fqdn" == *"raspberrypi"* ]]; then
|
||
echo "backend"
|
||
return
|
||
fi
|
||
|
||
# Unbekannter Server - Benutzer fragen
|
||
echo "unknown"
|
||
}
|
||
|
||
# Server-spezifische Installation
|
||
show_server_specific_menu() {
|
||
local server_type=$(detect_server_type)
|
||
|
||
show_header "🖥️ Server-spezifische Installation"
|
||
|
||
case $server_type in
|
||
"frontend")
|
||
echo -e "${GREEN}✅ Frontend-Server erkannt: $(hostname)${NC}"
|
||
echo -e "${BLUE}Dieser Server ist für das MYP Frontend konfiguriert.${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}🎯 Verfügbare Installationen:${NC}"
|
||
echo -e "${WHITE}1. Frontend installieren (Next.js + Docker)${NC}"
|
||
echo -e "${WHITE}2. Frontend Produktions-Deployment (Port 443 mit SSL)${NC}"
|
||
echo -e "${WHITE}3. Nur Docker & Dependencies installieren${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}9. Zurück zum Hauptmenü${NC}"
|
||
echo -e "${WHITE}0. Beenden${NC}"
|
||
echo ""
|
||
|
||
read -p "Wählen Sie eine Option (0-3, 9): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
install_frontend_only
|
||
;;
|
||
2)
|
||
deploy_frontend_production
|
||
;;
|
||
3)
|
||
install_system_dependencies
|
||
;;
|
||
9)
|
||
show_main_menu
|
||
;;
|
||
0)
|
||
echo -e "${GREEN}Auf Wiedersehen!${NC}"
|
||
exit 0
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option${NC}"
|
||
sleep 2
|
||
show_server_specific_menu
|
||
;;
|
||
esac
|
||
;;
|
||
|
||
"backend")
|
||
echo -e "${GREEN}✅ Backend-Server erkannt: $(hostname)${NC}"
|
||
echo -e "${BLUE}Dieser Server ist für das MYP Backend + Kiosk konfiguriert.${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}🎯 Verfügbare Installationen:${NC}"
|
||
echo -e "${WHITE}1. Backend installieren (Flask API + Web Interface)${NC}"
|
||
echo -e "${WHITE}2. Kiosk-Modus installieren (Touch-Interface)${NC}"
|
||
echo -e "${WHITE}3. Produktions-Setup (Backend + Kiosk + Services)${NC}"
|
||
echo -e "${WHITE}4. Nur Python & Dependencies installieren${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}9. Zurück zum Hauptmenü${NC}"
|
||
echo -e "${WHITE}0. Beenden${NC}"
|
||
echo ""
|
||
|
||
read -p "Wählen Sie eine Option (0-4, 9): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
install_backend_only
|
||
;;
|
||
2)
|
||
install_kiosk_mode
|
||
;;
|
||
3)
|
||
install_production_backend_with_kiosk
|
||
;;
|
||
4)
|
||
install_system_dependencies
|
||
setup_python_node_environment
|
||
;;
|
||
9)
|
||
show_main_menu
|
||
;;
|
||
0)
|
||
echo -e "${GREEN}Auf Wiedersehen!${NC}"
|
||
exit 0
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option${NC}"
|
||
sleep 2
|
||
show_server_specific_menu
|
||
;;
|
||
esac
|
||
;;
|
||
|
||
"unknown")
|
||
echo -e "${YELLOW}⚠ Unbekannter Server-Typ: $(hostname)${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}Bitte wählen Sie den Server-Typ:${NC}"
|
||
echo -e "${WHITE}1. 🖥️ Frontend-Server (m040tbaraspi001)${NC}"
|
||
echo -e "${WHITE}2. 🥧 Backend-Server (Raspberry Pi)${NC}"
|
||
echo -e "${WHITE}3. 💻 Entwicklungs-Server (Beide Komponenten)${NC}"
|
||
echo ""
|
||
echo -e "${WHITE}9. Zurück zum Hauptmenü${NC}"
|
||
echo ""
|
||
|
||
read -p "Wählen Sie den Server-Typ (1-3, 9): " choice
|
||
|
||
case $choice in
|
||
1)
|
||
echo -e "${BLUE}Frontend-Server-Modus aktiviert${NC}"
|
||
export MYP_SERVER_TYPE="frontend"
|
||
install_frontend_only
|
||
;;
|
||
2)
|
||
echo -e "${BLUE}Backend-Server-Modus aktiviert${NC}"
|
||
export MYP_SERVER_TYPE="backend"
|
||
install_backend_only
|
||
;;
|
||
3)
|
||
echo -e "${BLUE}Entwicklungs-Modus aktiviert${NC}"
|
||
export MYP_SERVER_TYPE="development"
|
||
install_development_setup
|
||
;;
|
||
9)
|
||
show_main_menu
|
||
;;
|
||
*)
|
||
echo -e "${RED}Ungültige Option${NC}"
|
||
sleep 2
|
||
show_server_specific_menu
|
||
;;
|
||
esac
|
||
;;
|
||
esac
|
||
}
|
||
|
||
# Frontend-Only Installation (für m040tbaraspi001)
|
||
install_frontend_only() {
|
||
show_header "Frontend-Only Installation (m040tbaraspi001)"
|
||
|
||
echo -e "${BLUE}Installiere Frontend für separaten Server...${NC}"
|
||
echo -e "${YELLOW}Backend-Verbindung: https://raspberrypi (separater Server)${NC}"
|
||
echo ""
|
||
|
||
# Node.js prüfen
|
||
if ! check_command node; then
|
||
echo -e "${RED}✗ Node.js nicht gefunden. Bitte installieren Sie Node.js 16+${NC}"
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
return 1
|
||
fi
|
||
|
||
# Docker für Produktion prüfen
|
||
if ! check_command docker; then
|
||
echo -e "${YELLOW}⚠ Docker nicht gefunden. Für Produktions-Deployment wird Docker benötigt.${NC}"
|
||
fi
|
||
|
||
cd "$FRONTEND_DIR"
|
||
|
||
# Frontend-Dependencies installieren
|
||
echo -e "${BLUE}1. Frontend-Abhängigkeiten installieren...${NC}"
|
||
exec_command "npm install" "Frontend-Abhängigkeiten installieren"
|
||
|
||
# SSL-Verzeichnis erstellen
|
||
echo -e "${BLUE}2. SSL-Verzeichnis erstellen...${NC}"
|
||
mkdir -p certs
|
||
|
||
# Frontend-Konfiguration für Zwei-Server-Setup
|
||
echo -e "${BLUE}3. Frontend-Konfiguration für Zwei-Server-Setup...${NC}"
|
||
setup_frontend_config_two_server
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Frontend-Only Installation abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🌐 Frontend-Server (m040tbaraspi001):${NC}"
|
||
echo -e "${WHITE}- Development: cd $FRONTEND_DIR && npm run dev${NC}"
|
||
echo -e "${WHITE}- Production: cd $FRONTEND_DIR && docker-compose up -d${NC}"
|
||
echo -e "${WHITE}- URL: https://m040tbaraspi001.de040.corpintra.net${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🔗 Backend-Verbindung:${NC}"
|
||
echo -e "${WHITE}- API: https://raspberrypi/api${NC}"
|
||
echo -e "${WHITE}- Backend muss separat auf Raspberry Pi installiert werden${NC}"
|
||
|
||
cd "$PROJECT_DIR"
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# Backend-Only Installation (für Raspberry Pi)
|
||
install_backend_only() {
|
||
show_header "Backend-Only Installation (Raspberry Pi)"
|
||
|
||
echo -e "${BLUE}Installiere Backend für separaten Server...${NC}"
|
||
echo -e "${YELLOW}Frontend läuft auf: https://m040tbaraspi001.de040.corpintra.net${NC}"
|
||
echo ""
|
||
|
||
# Backend-Installation ausführen
|
||
install_backend
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Backend-Only Installation abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🥧 Backend-Server (Raspberry Pi):${NC}"
|
||
echo -e "${WHITE}- API: https://raspberrypi/api${NC}"
|
||
echo -e "${WHITE}- Web Interface: https://raspberrypi${NC}"
|
||
echo -e "${WHITE}- Kiosk-Modus verfügbar${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🔗 Frontend-Verbindung:${NC}"
|
||
echo -e "${WHITE}- Frontend: https://m040tbaraspi001.de040.corpintra.net${NC}"
|
||
echo -e "${WHITE}- Frontend muss separat auf m040tbaraspi001 installiert werden${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# Frontend-Konfiguration für Zwei-Server-Setup
|
||
setup_frontend_config_two_server() {
|
||
echo -e "${BLUE}Konfiguriere Frontend für Zwei-Server-Setup...${NC}"
|
||
|
||
# .env.local für Frontend-Server erstellen
|
||
cat > "$FRONTEND_DIR/.env.local" << EOF
|
||
# Zwei-Server-Setup Konfiguration
|
||
# Frontend-Server: m040tbaraspi001.de040.corpintra.net
|
||
# Backend-Server: raspberrypi
|
||
|
||
# Backend API (Raspberry Pi)
|
||
NEXT_PUBLIC_API_URL=https://raspberrypi
|
||
NEXT_PUBLIC_BACKEND_HOST=raspberrypi
|
||
NEXT_PUBLIC_BACKEND_PROTOCOL=https
|
||
|
||
# Frontend (aktueller Server)
|
||
NEXT_PUBLIC_FRONTEND_URL=https://m040tbaraspi001.de040.corpintra.net
|
||
NEXTAUTH_URL=https://m040tbaraspi001.de040.corpintra.net
|
||
|
||
# OAuth Konfiguration
|
||
NEXT_PUBLIC_OAUTH_CALLBACK_URL=https://m040tbaraspi001.de040.corpintra.net/auth/login/callback
|
||
|
||
# GitHub OAuth (hardcodiert)
|
||
GITHUB_CLIENT_ID=7c5d8bef1a5519ec1fdc
|
||
GITHUB_CLIENT_SECRET=5f1e586204358fbd53cf5fb7d418b3f06ccab8fd
|
||
|
||
# Produktionsumgebung
|
||
NODE_ENV=production
|
||
DEBUG=false
|
||
|
||
# Zwei-Server-Setup
|
||
MYP_SERVER_TYPE=frontend
|
||
MYP_BACKEND_SERVER=raspberrypi
|
||
MYP_FRONTEND_SERVER=m040tbaraspi001.de040.corpintra.net
|
||
EOF
|
||
|
||
echo -e "${GREEN}✓ Frontend-Konfiguration für Zwei-Server-Setup erstellt${NC}"
|
||
echo -e "${BLUE}Backend-Verbindung: https://raspberrypi${NC}"
|
||
echo -e "${BLUE}Frontend-URL: https://m040tbaraspi001.de040.corpintra.net${NC}"
|
||
}
|
||
|
||
# Produktions-Backend mit Kiosk
|
||
install_production_backend_with_kiosk() {
|
||
show_header "Produktions-Backend mit Kiosk (Raspberry Pi)"
|
||
|
||
echo -e "${BLUE}Installiere komplettes Backend-System mit Kiosk...${NC}"
|
||
echo ""
|
||
|
||
# System-Abhängigkeiten installieren
|
||
if [ $is_root -eq 1 ]; then
|
||
install_system_dependencies
|
||
else
|
||
echo -e "${YELLOW}System-Abhängigkeiten übersprungen (keine Root-Rechte)${NC}"
|
||
fi
|
||
|
||
# Backend installieren
|
||
install_backend
|
||
|
||
# Kiosk-Modus installieren
|
||
install_kiosk_mode
|
||
|
||
echo ""
|
||
echo -e "${GREEN}✓ Produktions-Backend mit Kiosk abgeschlossen!${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🥧 Raspberry Pi (Backend + Kiosk):${NC}"
|
||
echo -e "${WHITE}- API: https://raspberrypi/api${NC}"
|
||
echo -e "${WHITE}- Web Interface: https://raspberrypi${NC}"
|
||
echo -e "${WHITE}- Kiosk-Modus: Vollbild-Touch-Interface${NC}"
|
||
echo -e "${WHITE}- Services: myp.service + myp-kiosk-browser.service${NC}"
|
||
echo ""
|
||
echo -e "${BLUE}🖥️ Frontend-Server:${NC}"
|
||
echo -e "${WHITE}- Frontend muss separat auf m040tbaraspi001 installiert werden${NC}"
|
||
echo -e "${WHITE}- URL: https://m040tbaraspi001.de040.corpintra.net${NC}"
|
||
|
||
echo ""
|
||
read -p "Drücken Sie ENTER, um fortzufahren..."
|
||
}
|
||
|
||
# ========================================================
|
||
# ENDE SERVER-DETECTION
|
||
# ========================================================
|
||
|
||
# Skript starten
|
||
show_main_menu |