From 1b829b2ed285c62f861cfe7e63ad76cede197846 Mon Sep 17 00:00:00 2001 From: Till Tomczak Date: Mon, 26 May 2025 22:23:48 +0200 Subject: [PATCH] MYP Control Center Integration: install.sh integriert, legacy Skripte markiert, README aktualisiert --- .../myp_installer_legacy.ps1 | 0 archiv/myp_installer_legacy.sh | 1756 +++++++++++++++++ ...rry_pi.sh => legacy_setup_raspberry_pi.sh} | 0 docs/README.md | 132 +- .../docker/{deploy.sh => legacy_deploy.sh} | 0 install.sh | 218 -- myp_installer.sh | 280 ++- ...rate_certs.sh => legacy_generate_certs.sh} | 0 8 files changed, 2102 insertions(+), 284 deletions(-) rename myp_installer.ps1 => archiv/myp_installer_legacy.ps1 (100%) create mode 100644 archiv/myp_installer_legacy.sh rename backend/{setup_raspberry_pi.sh => legacy_setup_raspberry_pi.sh} (100%) rename frontend/docker/{deploy.sh => legacy_deploy.sh} (100%) delete mode 100755 install.sh rename scripts/{generate_certs.sh => legacy_generate_certs.sh} (100%) diff --git a/myp_installer.ps1 b/archiv/myp_installer_legacy.ps1 similarity index 100% rename from myp_installer.ps1 rename to archiv/myp_installer_legacy.ps1 diff --git a/archiv/myp_installer_legacy.sh b/archiv/myp_installer_legacy.sh new file mode 100644 index 00000000..7ab0d78c --- /dev/null +++ b/archiv/myp_installer_legacy.sh @@ -0,0 +1,1756 @@ +#!/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 +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" +} + +# 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 prüfen + python_cmd="" + if check_command python3; then + python_cmd="python3" + python_version=$(python3 --version 2>&1) + echo -e "${GREEN}✓ $python_version${NC}" + elif check_command python; then + python_cmd="python" + python_version=$(python --version 2>&1) + echo -e "${GREEN}✓ $python_version${NC}" + else + echo -e "${RED}✗ Python nicht gefunden${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) installieren${NC}" + echo "" + + # Python prüfen + python_cmd="" + if check_command python3; then + python_cmd="python3" + echo -e "${GREEN}✓ Python 3 gefunden${NC}" + elif check_command python; then + python_cmd="python" + echo -e "${GREEN}✓ Python gefunden${NC}" + else + echo -e "${RED}✗ Python nicht gefunden. Bitte installieren Sie Python 3.8+${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 erstellen + echo -e "${BLUE}1. Virtual Environment erstellen...${NC}" + if [ ! -d "$VENV_DIR" ]; then + exec_command "$python_cmd -m venv $VENV_DIR" "Erstelle Virtual Environment" + else + echo -e "${YELLOW}Virtual Environment existiert bereits${NC}" + 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 + exec_command "$python_cmd -c 'from models import init_database, create_initial_admin; init_database(); create_initial_admin()'" "Datenbank 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 + + 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: https://localhost:443${NC}" + echo -e "${WHITE}- HTTP: http://localhost:5000${NC}" + + deactivate + cd "$PROJECT_DIR" + + echo "" + read -p "Drücken Sie ENTER, um fortzufahren..." +} + +# 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" + + echo -e "${BLUE}MYP Frontend für Produktion deployen (Port 80/443 mit SSL)${NC}" + echo "" + + # Docker prüfen + if ! check_command docker; then + echo -e "${RED}✗ Docker nicht gefunden. Bitte installieren Sie Docker${NC}" + read -p "Drücken Sie ENTER, um fortzufahren..." + return 1 + fi + + if ! check_command docker-compose; then + echo -e "${RED}✗ Docker Compose nicht gefunden. Bitte installieren Sie Docker Compose${NC}" + read -p "Drücken Sie ENTER, um fortzufahren..." + return 1 + fi + + echo -e "${GREEN}✓ Docker gefunden${NC}" + echo -e "${GREEN}✓ Docker Compose gefunden${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" + + # Produktions-Konfiguration prüfen + if [ ! -f "docker-compose.production.yml" ]; then + echo -e "${RED}✗ Produktions-Konfiguration nicht gefunden: docker-compose.production.yml${NC}" + echo -e "${YELLOW}Bitte stellen Sie sicher, dass die Produktions-Konfiguration vorhanden ist.${NC}" + read -p "Drücken Sie ENTER, um fortzufahren..." + return 1 + fi + + echo -e "${GREEN}✓ Produktions-Konfiguration gefunden${NC}" + + # SSL-Zertifikate-Verzeichnis erstellen + echo -e "${BLUE}1. SSL-Zertifikate-Verzeichnis erstellen...${NC}" + mkdir -p "./certs" + echo -e "${GREEN}✓ Zertifikate-Verzeichnis erstellt${NC}" + + # Alte Container stoppen + echo -e "${BLUE}2. Alte Container stoppen...${NC}" + exec_command "docker-compose -f docker-compose.production.yml down" "Alte Container stoppen" "true" + + # Backend-URL konfigurieren + echo -e "${BLUE}3. Backend-URL konfigurieren...${NC}" + echo -e "${WHITE}Aktuelle Backend-URLs:${NC}" + echo -e "${WHITE}1. Raspberry Pi (raspberrypi:443) [Standard]${NC}" + echo -e "${WHITE}2. Lokales Backend (localhost:443)${NC}" + echo -e "${WHITE}3. Benutzerdefinierte URL${NC}" + + read -p "Wählen Sie eine Option (1-3, Standard: 1): " backend_choice + + backend_url="https://raspberrypi:443" + + case $backend_choice in + 2) + backend_url="https://localhost:443" + ;; + 3) + read -p "Geben Sie die Backend-URL ein (z.B. https://192.168.1.100:443): " custom_url + if [ -n "$custom_url" ]; then + backend_url="$custom_url" + fi + ;; + *) + backend_url="https://raspberrypi:443" + ;; + esac + + echo -e "${GREEN}✓ Backend-URL konfiguriert: $backend_url${NC}" + + # Container bauen und starten + echo -e "${BLUE}4. Frontend-Container bauen und starten...${NC}" + echo -e "${YELLOW}Dies kann einige Minuten dauern...${NC}" + + # Environment-Variablen für Backend-URL setzen + export NEXT_PUBLIC_API_URL="$backend_url" + export NEXT_PUBLIC_BACKEND_HOST="${backend_url#https://}" + + exec_command "docker-compose -f docker-compose.production.yml up --build -d" "Frontend-Container starten" + + if [ $? -eq 0 ]; then + # Kurz warten und Status prüfen + echo -e "${BLUE}5. Container-Status prüfen...${NC}" + sleep 5 + + container_status=$(docker-compose -f docker-compose.production.yml ps --services --filter "status=running") + + if [ -n "$container_status" ]; then + echo -e "${GREEN}✓ Container erfolgreich gestartet!${NC}" + + # Container-Details anzeigen + echo "" + echo -e "${BLUE}Container Status:${NC}" + docker-compose -f docker-compose.production.yml ps + + echo "" + echo -e "${GREEN}✅ Frontend Produktions-Deployment erfolgreich abgeschlossen!${NC}" + echo "" + echo -e "${BLUE}🌐 Frontend ist verfügbar unter:${NC}" + echo -e "${WHITE} - HTTP: http://localhost:80${NC}" + echo -e "${WHITE} - HTTPS: https://localhost:443${NC}" + echo "" + echo -e "${BLUE}🔧 Backend-Verbindung:${NC}" + echo -e "${WHITE} - Backend: $backend_url${NC}" + echo "" + echo -e "${BLUE}📋 Nützliche Befehle:${NC}" + echo -e "${WHITE} - Logs anzeigen: docker-compose -f docker-compose.production.yml logs -f${NC}" + echo -e "${WHITE} - Container stoppen: docker-compose -f docker-compose.production.yml down${NC}" + echo -e "${WHITE} - Container neustarten: docker-compose -f docker-compose.production.yml restart${NC}" + echo "" + echo -e "${BLUE}🔒 SSL-Hinweise:${NC}" + echo -e "${WHITE} - Caddy generiert automatisch selbstsignierte Zertifikate${NC}" + echo -e "${WHITE} - Zertifikate werden in ./certs/ gespeichert${NC}" + echo -e "${WHITE} - Für Produktion: Browser-Warnung bei selbstsignierten Zertifikaten acceptieren${NC}" + + else + echo -e "${RED}✗ Container konnten nicht gestartet werden${NC}" + echo -e "${YELLOW}Logs anzeigen:${NC}" + docker-compose -f docker-compose.production.yml logs + return 1 + fi + else + echo -e "${RED}✗ Fehler beim Starten der Container${NC}" + return 1 + fi + + cd "$PROJECT_DIR" + + echo "" + read -p "Drücken Sie ENTER, um fortzufahren..." +} + +# Kiosk-Modus installieren +install_kiosk_mode() { + show_header "Kiosk-Modus Installation" + + echo -e "${BLUE}MYP Kiosk-Modus (Backend Web Interface) installieren${NC}" + echo "" + echo -e "${YELLOW}Der Kiosk-Modus nutzt das Backend Flask Web Interface${NC}" + echo -e "${YELLOW}als Ersatz für das separate Frontend.${NC}" + echo "" + + # Backend muss installiert sein + if [ ! -d "$VENV_DIR" ]; then + echo -e "${RED}✗ Backend ist nicht installiert. Bitte installieren Sie zuerst das Backend.${NC}" + read -p "Drücken Sie ENTER, um fortzufahren..." + return 1 + fi + + # Kiosk-spezifische Konfiguration + echo -e "${BLUE}1. Kiosk-Konfiguration erstellen...${NC}" + + # Virtual Environment aktivieren + source "$VENV_DIR/bin/activate" + + cd "$APP_DIR" + + # Kiosk-Konfiguration in settings.py setzen + if [ -f "config/settings.py" ]; then + # Backup erstellen + cp "config/settings.py" "config/settings.py.backup" + + # 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" +EOF + + echo -e "${GREEN}✓ Kiosk-Konfiguration hinzugefügt${NC}" + fi + + # Systemd Service für Kiosk erstellen (falls Root) + if [ $is_root -eq 1 ]; then + echo -e "${BLUE}2. Kiosk-Service erstellen...${NC}" + + cat > "/etc/systemd/system/myp-kiosk.service" << EOF +[Unit] +Description=MYP Kiosk Mode - 3D Printer Management Kiosk +After=network.target graphical-session.target + +[Service] +Type=simple +User=$USER +Group=$USER +WorkingDirectory=$APP_DIR +Environment=PATH=$VENV_DIR/bin +Environment=DISPLAY=:0 +ExecStart=$VENV_DIR/bin/python app.py --kiosk +Restart=always +RestartSec=10 + +[Install] +WantedBy=graphical-session.target +EOF + + systemctl daemon-reload + systemctl enable myp-kiosk.service + + echo -e "${GREEN}✓ Kiosk-Service erstellt und aktiviert${NC}" + fi + + # Browser-Autostart für Kiosk (Raspberry Pi) + echo -e "${BLUE}3. Browser-Autostart konfigurieren...${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 +Exec=chromium-browser --kiosk --disable-infobars --disable-session-crashed-bubble --disable-translate --no-first-run https://localhost:443 +X-GNOME-Autostart-enabled=true +Hidden=false +NoDisplay=false +EOF + + echo -e "${GREEN}✓ Browser-Autostart konfiguriert${NC}" + + deactivate + cd "$PROJECT_DIR" + + echo "" + echo -e "${GREEN}✓ Kiosk-Modus Installation abgeschlossen!${NC}" + echo "" + echo -e "${BLUE}Kiosk-Modus starten:${NC}" + echo -e "${WHITE}sudo systemctl start myp-kiosk${NC}" + echo "" + echo -e "${BLUE}Kiosk-URLs:${NC}" + echo -e "${WHITE}- Vollbild: https://localhost:443${NC}" + echo -e "${WHITE}- Normal: https://localhost:443${NC}" + echo "" + echo -e "${YELLOW}Hinweise:${NC}" + echo -e "${WHITE}- Der Kiosk-Modus startet automatisch beim Boot${NC}" + echo -e "${WHITE}- Browser öffnet im Vollbildmodus${NC}" + echo -e "${WHITE}- Nutzt das Backend Web Interface${NC}" + + 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 für OAuth Callback +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" + python 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" + python 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) + return + ;; + *) + 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" + python 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 + python_cmd="" + if 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)${NC}" + echo -e "${WHITE}4. Frontend installieren (Next.js React)${NC}" + echo -e "${WHITE}5. Kiosk-Modus installieren (Backend Web Interface)${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)${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 "Hauptmenü" + + echo -e "${WHITE}🚀 SCHNELLSTART:${NC}" + echo -e "${WHITE}1. Vollständige Installation (Alle Komponenten)${NC}" + echo -e "${WHITE}2. Backend-Only Installation (Kiosk-ready)${NC}" + echo -e "${WHITE}3. Entwicklungs-Setup (Backend + Frontend)${NC}" + echo "" + echo -e "${WHITE}⚙️ GRANULARE INSTALLATION:${NC}" + echo -e "${WHITE}4. Granulare Installation & Konfiguration${NC}" + echo "" + echo -e "${WHITE}🔧 SYSTEM & WARTUNG:${NC}" + echo -e "${WHITE}5. Systemvoraussetzungen prüfen${NC}" + echo -e "${WHITE}6. Anwendung starten${NC}" + echo -e "${WHITE}7. Projekt-Informationen${NC}" + echo "" + echo -e "${WHITE}0. Beenden${NC}" + echo "" + + read -p "Wählen Sie eine Option (0-7): " choice + + case $choice in + 1) + install_everything + show_main_menu + ;; + 2) + install_production_setup + show_main_menu + ;; + 3) + install_development_setup + show_main_menu + ;; + 4) + show_installation_menu + ;; + 5) + test_dependencies + show_main_menu + ;; + 6) + start_application + show_main_menu + ;; + 7) + show_project_info + 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_main_menu + ;; + esac +} + +# Skript starten +show_main_menu \ No newline at end of file diff --git a/backend/setup_raspberry_pi.sh b/backend/legacy_setup_raspberry_pi.sh similarity index 100% rename from backend/setup_raspberry_pi.sh rename to backend/legacy_setup_raspberry_pi.sh diff --git a/docs/README.md b/docs/README.md index d43562ba..981df56e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,50 +4,41 @@ Mercedes-Benz Werk 040 Berlin - 3D-Drucker Reservierungsplattform ## 🚀 Schnellstart +### MYP Control Center (Empfohlen) + +Das zentrale Installationssystem für alle Komponenten: + +```bash +# Repository klonen +git clone +cd Projektarbeit-MYP + +# MYP Control Center starten +./myp_installer.sh +``` + +Das MYP Control Center bietet: +- **Schnellstart-Installationen** (Vollständig, Backend-Only, Entwicklung) +- **Produktions-Installer** (Integration der v3.2 install.sh Funktionalität) +- **Granulare Installation** (Einzelne Komponenten) +- **System & Wartung** (Tests, Status, Informationen) + +### Direkter Produktions-Installer + +Für schnelle Produktions-Deployments direkt im MYP Control Center → Option 4: + +```bash +./myp_installer.sh +# → Wähle Option 4: Produktions-Installer +# → Backend installieren (Raspberry Pi) +# → Frontend installieren (Docker) +``` + ### Voraussetzungen - **Backend (Raspberry Pi)**: Python 3.11, systemd - **Frontend (m040tbaraspi001)**: Docker, Docker Compose -### Installation - -#### Backend Installation (Raspberry Pi) - -```bash -# Repository klonen -git clone -cd Projektarbeit-MYP - -# Backend installieren -./install.sh backend -``` - -#### Frontend Installation (m040tbaraspi001) - -```bash -# Repository klonen -git clone -cd Projektarbeit-MYP - -# Frontend installieren -./install.sh frontend -``` - -### Services starten - -#### Backend -```bash -sudo systemctl start myp.service -sudo systemctl status myp.service -``` - -#### Frontend -```bash -cd frontend -docker-compose up -d -docker-compose logs -f -``` - ## 🌐 Zugriff - **Frontend**: https://m040tbaraspi001.de040.corpintra.net @@ -80,13 +71,21 @@ curl -k https://m040tbaraspi001.de040.corpintra.net/health ## 🛠️ Entwicklung -### Backend Debug-Modus +### MYP Control Center (Entwicklungs-Setup) +```bash +./myp_installer.sh +# → Option 3: Entwicklungs-Setup +``` + +### Manuelle Installation + +#### Backend Debug-Modus ```bash cd backend/app python3.11 app.py --debug ``` -### Frontend Development +#### Frontend Development ```bash cd frontend npm run dev @@ -96,26 +95,39 @@ npm run dev ``` Projektarbeit-MYP/ +├── myp_installer.sh # 🎯 HAUPT-INSTALLER (Control Center) ├── backend/ │ ├── app/ -│ │ ├── certs/ # TLS-Zertifikate -│ │ ├── database/ # SQLite-Datenbank -│ │ ├── logs/ # Anwendungslogs -│ │ └── app.py # Hauptanwendung -│ ├── myp.service # systemd Service -│ └── requirements.txt # Python-Abhängigkeiten +│ │ ├── certs/ # TLS-Zertifikate +│ │ ├── database/ # SQLite-Datenbank +│ │ ├── logs/ # Anwendungslogs +│ │ └── app.py # Hauptanwendung +│ ├── myp.service # systemd Service +│ ├── requirements.txt # Python-Abhängigkeiten +│ └── legacy_setup_raspberry_pi.sh # Legacy Skript ├── frontend/ -│ ├── certs/ # TLS-Zertifikate +│ ├── certs/ # TLS-Zertifikate │ ├── docker/ -│ │ └── caddy/ -│ │ └── Caddyfile # Reverse Proxy Konfiguration -│ ├── src/ # Next.js Anwendung +│ │ ├── caddy/ +│ │ │ └── Caddyfile # Reverse Proxy Konfiguration +│ │ └── legacy_deploy.sh # Legacy Skript +│ ├── src/ # Next.js Anwendung │ └── docker-compose.yml -├── docs/ # Dokumentation -├── scripts/ # Hilfsskripte -└── install.sh # Zentraler Installer +├── scripts/ +│ └── legacy_generate_certs.sh # Legacy Skript +├── archiv/ +│ └── myp_installer_legacy.sh # Archivierte Version +└── docs/ # Dokumentation ``` +### Script-Status + +| Skript | Status | Verwendung | +|--------|--------|------------| +| `myp_installer.sh` | ✅ **AKTIV** | Haupt-Control-Center | +| `*legacy_*.sh` | 📦 Legacy | Historische Versionen | +| `archiv/myp_installer_legacy.sh` | 📦 Archiv | Alte Version 4.0 | + ## 🔒 Sicherheit - HTTPS-only (Port 443) @@ -145,6 +157,13 @@ docker-compose logs caddy ## 🆘 Troubleshooting +### MYP Control Center verwenden +```bash +./myp_installer.sh +# → Option 6: Systemvoraussetzungen prüfen +# → Option 7: Anwendung starten +``` + ### Backend startet nicht ```bash # Service Status prüfen @@ -182,10 +201,11 @@ netstat -tlnp | grep :443 ## 📋 Version - **Version**: 3.2-final +- **Control Center**: v4.0 mit v3.2 Integration - **Build**: Production -- **Datum**: $(date) +- **Installer**: MYP Control Center ## 👥 Support -Bei Problemen wenden Sie sich an das IT-Team des Mercedes-Benz Werk 040 Berlin. +Bei Problemen verwenden Sie das MYP Control Center oder wenden Sie sich an das IT-Team des Mercedes-Benz Werk 040 Berlin. diff --git a/frontend/docker/deploy.sh b/frontend/docker/legacy_deploy.sh similarity index 100% rename from frontend/docker/deploy.sh rename to frontend/docker/legacy_deploy.sh diff --git a/install.sh b/install.sh deleted file mode 100755 index 80c16363..00000000 --- a/install.sh +++ /dev/null @@ -1,218 +0,0 @@ -#!/bin/bash - -# MYP Reservation Platform - Zentraler Installer -# Unterstützt Backend und Frontend Installation - -set -e - -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -PROJECT_ROOT="$SCRIPT_DIR" - -# Farben für Output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -BLUE='\033[0;34m' -NC='\033[0m' # No Color - -# Logging -log_info() { - echo -e "${BLUE}[INFO]${NC} $1" -} - -log_success() { - echo -e "${GREEN}[SUCCESS]${NC} $1" -} - -log_warning() { - echo -e "${YELLOW}[WARNING]${NC} $1" -} - -log_error() { - echo -e "${RED}[ERROR]${NC} $1" -} - -# Hilfsfunktionen -check_root() { - if [[ $EUID -eq 0 ]]; then - log_error "Dieses Skript sollte nicht als root ausgeführt werden!" - exit 1 - fi -} - -check_dependencies() { - local deps=("python3.11" "curl" "openssl") - - for dep in "${deps[@]}"; do - if ! command -v "$dep" &> /dev/null; then - log_error "Abhängigkeit '$dep' nicht gefunden!" - exit 1 - fi - done -} - -install_backend() { - log_info "=== Backend Installation ===" - - cd "$PROJECT_ROOT/backend" - - # Python Virtual Environment erstellen - log_info "Erstelle Python Virtual Environment..." - python3.11 -m venv venv - source venv/bin/activate - - # Requirements installieren - log_info "Installiere Python-Abhängigkeiten..." - pip install --upgrade pip - pip install -r requirements.txt - - # Zertifikate kopieren - log_info "Kopiere TLS-Zertifikate..." - mkdir -p app/certs - cp "$PROJECT_ROOT/backend/app/certs/backend.crt" app/certs/ - cp "$PROJECT_ROOT/backend/app/certs/backend.key" app/certs/ - chmod 600 app/certs/backend.key - chmod 644 app/certs/backend.crt - - # Systemd Service installieren - log_info "Installiere systemd Service..." - sudo cp myp.service /etc/systemd/system/ - sudo systemctl daemon-reload - sudo systemctl enable myp.service - - # Datenbank initialisieren - log_info "Initialisiere Datenbank..." - cd app - python3.11 init_db.py - - log_success "Backend Installation abgeschlossen!" - log_info "Service starten mit: sudo systemctl start myp.service" -} - -install_frontend() { - log_info "=== Frontend Installation ===" - - cd "$PROJECT_ROOT/frontend" - - # Docker prüfen - if ! command -v docker &> /dev/null; then - log_error "Docker ist nicht installiert!" - exit 1 - fi - - if ! command -v docker-compose &> /dev/null; then - log_error "Docker Compose ist nicht installiert!" - exit 1 - fi - - # Zertifikate kopieren - log_info "Kopiere TLS-Zertifikate..." - mkdir -p certs - cp "$PROJECT_ROOT/frontend/certs/frontend.crt" certs/ - cp "$PROJECT_ROOT/frontend/certs/frontend.key" certs/ - chmod 600 certs/frontend.key - chmod 644 certs/frontend.crt - - # Caddyfile Symlink erstellen - log_info "Erstelle Caddyfile Symlink..." - mkdir -p docker/caddy - if [[ ! -L docker/caddy/Caddyfile ]]; then - ln -sf "$PROJECT_ROOT/frontend/docker/caddy/Caddyfile" docker/caddy/Caddyfile - fi - - # Docker Images bauen - log_info "Baue Docker Images..." - docker-compose build - - # Services starten - log_info "Starte Frontend Services..." - docker-compose up -d - - log_success "Frontend Installation abgeschlossen!" - log_info "Frontend verfügbar unter: https://m040tbaraspi001.de040.corpintra.net" -} - -health_check_backend() { - log_info "=== Backend Health Check ===" - - local max_attempts=30 - local attempt=1 - - while [[ $attempt -le $max_attempts ]]; do - 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 - log_success "Backend ist erreichbar!" - return 0 - fi - - sleep 2 - ((attempt++)) - done - - log_error "Backend Health Check fehlgeschlagen!" - return 1 -} - -health_check_frontend() { - log_info "=== Frontend Health Check ===" - - local max_attempts=30 - local attempt=1 - - while [[ $attempt -le $max_attempts ]]; do - 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 - log_success "Frontend ist erreichbar!" - return 0 - fi - - sleep 2 - ((attempt++)) - done - - log_error "Frontend Health Check fehlgeschlagen!" - return 1 -} - -show_usage() { - echo "Usage: $0 [backend|frontend]" - echo "" - echo "Optionen:" - echo " backend - Installiert das Backend (Python/Flask)" - echo " frontend - Installiert das Frontend (Docker/Next.js)" - echo "" - echo "Beispiele:" - echo " $0 backend # Backend installieren" - echo " $0 frontend # Frontend installieren" -} - -# Main -main() { - log_info "MYP Reservation Platform - Installer v3.2" - log_info "Projektpfad: $PROJECT_ROOT" - - check_root - check_dependencies - - case "${1:-}" in - "backend") - install_backend - health_check_backend - ;; - "frontend") - install_frontend - health_check_frontend - ;; - *) - show_usage - exit 1 - ;; - esac - - log_success "Installation erfolgreich abgeschlossen!" -} - -# Skript ausführen -main "$@" \ No newline at end of file diff --git a/myp_installer.sh b/myp_installer.sh index 7ab0d78c..421b4271 100644 --- a/myp_installer.sh +++ b/myp_installer.sh @@ -81,6 +81,260 @@ get_local_ip() { 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 + + # Systemd Service installieren + if [ $is_root -eq 1 ]; then + prod_log_info "Installiere systemd Service..." + cp myp.service /etc/systemd/system/ + systemctl daemon-reload + systemctl enable myp.service + else + prod_log_warning "systemd Service-Installation übersprungen (keine Root-Rechte)" + prod_log_info "Manuell ausführen: sudo cp backend/myp.service /etc/systemd/system/ && sudo systemctl daemon-reload && sudo systemctl enable myp.service" + fi + + # Datenbank initialisieren + prod_log_info "Initialisiere Datenbank..." + cd app + python3.11 init_db.py + + prod_log_success "Produktions-Backend Installation abgeschlossen!" + if [ $is_root -eq 1 ]; then + prod_log_info "Service starten mit: sudo systemctl start myp.service" + 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" @@ -1069,7 +1323,7 @@ setup_backend_url() { # Backend API Konfiguration NEXT_PUBLIC_API_URL=$backend_url -# Frontend-URL für OAuth Callback +# Frontend-URL NEXT_PUBLIC_FRONTEND_URL=http://localhost:3000 # OAuth Konfiguration @@ -1178,7 +1432,7 @@ start_application() { start_debug_server ;; 7) - return + show_main_menu ;; *) echo -e "${RED}Ungültige Option.${NC}" @@ -1699,18 +1953,21 @@ show_main_menu() { echo -e "${WHITE}2. Backend-Only Installation (Kiosk-ready)${NC}" echo -e "${WHITE}3. Entwicklungs-Setup (Backend + Frontend)${NC}" echo "" + echo -e "${WHITE}🎯 PRODUKTIONS-INSTALLER (v3.2):${NC}" + echo -e "${WHITE}4. Produktions-Installer (install.sh Integration)${NC}" + echo "" echo -e "${WHITE}⚙️ GRANULARE INSTALLATION:${NC}" - echo -e "${WHITE}4. Granulare Installation & Konfiguration${NC}" + echo -e "${WHITE}5. Granulare Installation & Konfiguration${NC}" echo "" echo -e "${WHITE}🔧 SYSTEM & WARTUNG:${NC}" - echo -e "${WHITE}5. Systemvoraussetzungen prüfen${NC}" - echo -e "${WHITE}6. Anwendung starten${NC}" - echo -e "${WHITE}7. Projekt-Informationen${NC}" + echo -e "${WHITE}6. Systemvoraussetzungen prüfen${NC}" + echo -e "${WHITE}7. Anwendung starten${NC}" + echo -e "${WHITE}8. Projekt-Informationen${NC}" echo "" echo -e "${WHITE}0. Beenden${NC}" echo "" - read -p "Wählen Sie eine Option (0-7): " choice + read -p "Wählen Sie eine Option (0-8): " choice case $choice in 1) @@ -1726,17 +1983,20 @@ show_main_menu() { show_main_menu ;; 4) - show_installation_menu + show_production_installer_menu ;; 5) + show_installation_menu + ;; + 6) test_dependencies show_main_menu ;; - 6) + 7) start_application show_main_menu ;; - 7) + 8) show_project_info show_main_menu ;; diff --git a/scripts/generate_certs.sh b/scripts/legacy_generate_certs.sh similarity index 100% rename from scripts/generate_certs.sh rename to scripts/legacy_generate_certs.sh