diff --git a/myp_installer.sh b/myp_installer.sh index 421b4271..b6e71208 100644 --- a/myp_installer.sh +++ b/myp_installer.sh @@ -155,9 +155,131 @@ install_production_backend() { 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 + if [ $is_root -eq 1 ]; then + prod_log_info "Erstelle Kiosk-Browser-Service für Produktion..." + + cat > "/etc/systemd/system/myp-kiosk-browser.service" << EOF +[Unit] +Description=MYP Production Kiosk Browser +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 + prod_log_success "Kiosk-Browser-Service erstellt" + + # Optional: Service automatisch aktivieren + 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 } @@ -514,7 +636,7 @@ setup_python_node_environment() { install_backend() { show_header "Backend Installation" - echo -e "${BLUE}MYP Backend (Flask API) installieren${NC}" + echo -e "${BLUE}MYP Backend (Flask API + Web Interface) installieren${NC}" echo "" # Python prüfen @@ -597,6 +719,13 @@ install_backend() { create_ssl_certificates fi + # Kiosk-Konfiguration fragen + echo -e "${BLUE}8. 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 "" @@ -604,8 +733,17 @@ install_backend() { 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}" + 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" @@ -614,6 +752,230 @@ install_backend() { 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) + 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 +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 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}" + 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 (verbesserte Version) +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 vollständiges Kiosk-System für Touchscreen-Bedienung.${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 + + # Prüfen ob Backend läuft + if ! curl -k -s --max-time 5 https://localhost:443/ > /dev/null 2>&1; then + echo -e "${YELLOW}⚠ Backend scheint nicht zu laufen. Stellen Sie sicher, dass das Backend gestartet ist.${NC}" + echo -e "${BLUE}Backend starten mit: cd $APP_DIR && python app.py${NC}" + else + echo -e "${GREEN}✓ Backend ist verfügbar${NC}" + fi + + # Virtual Environment aktivieren + source "$VENV_DIR/bin/activate" + cd "$APP_DIR" + + # Kiosk-Konfiguration sicherstellen + echo -e "${BLUE}1. Kiosk-Konfiguration sicherstellen...${NC}" + configure_backend_for_kiosk + + # Systemd Service für automatischen Browser-Start + if [ $is_root -eq 1 ]; then + echo -e "${BLUE}2. Automatischen Kiosk-Start aktivieren...${NC}" + + read -p "Soll der Kiosk-Browser automatisch beim System-Start gestartet werden? (j/n, Standard: n): " auto_start + if [ "$auto_start" = "j" ]; then + systemctl enable myp-kiosk-browser.service + echo -e "${GREEN}✓ Automatischer Kiosk-Start aktiviert${NC}" + echo -e "${BLUE}Der Browser startet automatisch nach dem nächsten Neustart${NC}" + else + echo -e "${YELLOW}⚠ Automatischer Start nicht aktiviert${NC}" + echo -e "${BLUE}Manuell aktivieren mit: sudo systemctl enable myp-kiosk-browser${NC}" + fi + else + echo -e "${YELLOW}⚠ Systemd-Service-Installation übersprungen (keine Root-Rechte)${NC}" + fi + + # Kiosk jetzt starten (optional) + echo -e "${BLUE}3. Kiosk-Test...${NC}" + read -p "Möchten Sie den Kiosk-Modus jetzt testen? (j/n, Standard: n): " test_kiosk + if [ "$test_kiosk" = "j" ]; then + echo -e "${BLUE}Starte Kiosk-Test (Browser öffnet sich)...${NC}" + echo -e "${YELLOW}Drücken Sie F11 oder Alt+F4 um den Kiosk zu beenden${NC}" + sleep 3 + "$APP_DIR/start_kiosk.sh" & + echo -e "${GREEN}✓ Kiosk-Browser gestartet${NC}" + fi + + deactivate + cd "$PROJECT_DIR" + + echo "" + echo -e "${GREEN}✓ Kiosk-Modus Installation abgeschlossen!${NC}" + echo "" + echo -e "${BLUE}🖥️ Kiosk-Modus verwenden:${NC}" + echo -e "${WHITE} - Backend starten: cd $APP_DIR && python app.py${NC}" + echo -e "${WHITE} - Kiosk manuell starten: $APP_DIR/start_kiosk.sh${NC}" + echo -e "${WHITE} - Systemd-Service: sudo systemctl start myp-kiosk-browser${NC}" + echo "" + echo -e "${BLUE}🌐 Kiosk-URLs:${NC}" + echo -e "${WHITE} - Hauptinterface: https://localhost:443/${NC}" + echo -e "${WHITE} - Dashboard: https://localhost:443/dashboard${NC}" + echo -e "${WHITE} - Drucker: https://localhost:443/printers${NC}" + echo -e "${WHITE} - Jobs: https://localhost:443/jobs${NC}" + echo "" + echo -e "${BLUE}🔧 Kiosk-Features:${NC}" + echo -e "${WHITE} - Vollbild-Web-Interface${NC}" + echo -e "${WHITE} - Touch-optimierte Bedienung${NC}" + echo -e "${WHITE} - Automatisches Login${NC}" + echo -e "${WHITE} - Deaktivierung mit Passwort: 744563017196A${NC}" + + echo "" + read -p "Drücken Sie ENTER, um fortzufahren..." +} + # Frontend installieren install_frontend() { show_header "Frontend Installation" @@ -826,121 +1188,6 @@ deploy_frontend_production() { 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}" @@ -1825,14 +2072,14 @@ show_installation_menu() { 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}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)${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)${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}" @@ -1950,7 +2197,7 @@ show_main_menu() { 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}2. Backend-Only Installation (mit Kiosk Web Interface)${NC}" echo -e "${WHITE}3. Entwicklungs-Setup (Backend + Frontend)${NC}" echo "" echo -e "${WHITE}🎯 PRODUKTIONS-INSTALLER (v3.2):${NC}"