Projektarbeit-MYP/backend/app/test-kiosk-setup.sh

293 lines
8.8 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# ===================================================================
# MYP Kiosk-Setup Test und Validierung
# Testet alle Komponenten der Kiosk-Installation
# ===================================================================
set -e
# Farben für Ausgabe
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
# Test-Funktionen
test_passed() {
echo -e "${GREEN}$1${NC}"
}
test_failed() {
echo -e "${RED}$1${NC}"
}
test_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
test_info() {
echo -e "${BLUE} $1${NC}"
}
echo "====================================================================="
echo "🧪 MYP Kiosk-Setup Validierung"
echo "====================================================================="
echo
# ========================== SYSTEM-TESTS ==========================
echo "🔍 SYSTEM-TESTS"
echo "---------------------------------------------------------------------"
# Benutzer-Tests
if id "kiosk" &>/dev/null; then
test_passed "Kiosk-Benutzer existiert"
else
test_failed "Kiosk-Benutzer fehlt"
fi
if id "myp" &>/dev/null; then
test_passed "MYP-Benutzer existiert"
else
test_failed "MYP-Benutzer fehlt"
fi
# Verzeichnis-Tests
if [ -d "/opt/myp-druckerverwaltung" ]; then
test_passed "MYP-Anwendungsverzeichnis existiert"
else
test_failed "MYP-Anwendungsverzeichnis fehlt"
fi
if [ -f "/opt/myp-druckerverwaltung/app.py" ]; then
test_passed "Flask-Anwendung gefunden"
else
test_warning "Flask-Anwendung nicht gefunden (wird erstellt)"
fi
# ========================== SERVICE-TESTS ==========================
echo
echo "🔧 SERVICE-TESTS"
echo "---------------------------------------------------------------------"
# Systemd-Services prüfen
services=("myp-druckerverwaltung" "lightdm" "kiosk-chromium")
for service in "${services[@]}"; do
if systemctl is-enabled --quiet "$service" 2>/dev/null; then
test_passed "Service '$service' ist aktiviert"
if systemctl is-active --quiet "$service" 2>/dev/null; then
test_passed "Service '$service' läuft"
else
test_warning "Service '$service' läuft nicht (normal vor Reboot)"
fi
else
test_failed "Service '$service' ist nicht aktiviert"
fi
done
# ========================== KONFIGURATION-TESTS ==========================
echo
echo "⚙️ KONFIGURATION-TESTS"
echo "---------------------------------------------------------------------"
# LightDM-Konfiguration
if [ -f "/etc/lightdm/lightdm.conf" ]; then
if grep -q "autologin-user=kiosk" /etc/lightdm/lightdm.conf; then
test_passed "LightDM Autologin konfiguriert"
else
test_failed "LightDM Autologin nicht konfiguriert"
fi
else
test_failed "LightDM-Konfiguration fehlt"
fi
# Kiosk-Skript
if [ -f "/home/kiosk/start-kiosk.sh" ]; then
if [ -x "/home/kiosk/start-kiosk.sh" ]; then
test_passed "Kiosk-Starter-Skript vorhanden und ausführbar"
else
test_failed "Kiosk-Starter-Skript nicht ausführbar"
fi
else
test_failed "Kiosk-Starter-Skript fehlt"
fi
# Openbox-Konfiguration
if [ -f "/home/kiosk/.config/openbox/rc.xml" ]; then
test_passed "Openbox-Konfiguration vorhanden"
else
test_failed "Openbox-Konfiguration fehlt"
fi
# Desktop-Autostart
if [ -f "/home/kiosk/.config/autostart/myp-kiosk.desktop" ]; then
test_passed "Desktop-Autostart konfiguriert"
else
test_failed "Desktop-Autostart fehlt"
fi
# ========================== PAKET-TESTS ==========================
echo
echo "📦 PAKET-TESTS"
echo "---------------------------------------------------------------------"
# Wichtige Pakete prüfen
packages=("chromium" "openbox" "lightdm" "python3" "unclutter" "xorg")
for package in "${packages[@]}"; do
if dpkg -l | grep -q "^ii.*$package" 2>/dev/null; then
test_passed "Paket '$package' installiert"
elif command -v "$package" &>/dev/null; then
test_passed "Programm '$package' verfügbar"
else
test_failed "Paket/Programm '$package' fehlt"
fi
done
# Chromium-Binary finden
if command -v chromium &>/dev/null; then
test_passed "Chromium-Binary gefunden: $(which chromium)"
elif command -v chromium-browser &>/dev/null; then
test_passed "Chromium-Browser-Binary gefunden: $(which chromium-browser)"
else
test_failed "Kein Chromium-Binary gefunden"
fi
# ========================== NETZWERK-TESTS ==========================
echo
echo "🌐 NETZWERK-TESTS"
echo "---------------------------------------------------------------------"
# Internetverbindung
if ping -c 1 google.com &>/dev/null; then
test_passed "Internetverbindung verfügbar"
else
test_warning "Keine Internetverbindung (optional)"
fi
# Lokale Ports testen (falls Services laufen)
if systemctl is-active --quiet myp-druckerverwaltung 2>/dev/null; then
if curl -s --connect-timeout 5 http://localhost:5000 >/dev/null 2>&1; then
test_passed "Port 5000 erreichbar"
else
test_warning "Port 5000 nicht erreichbar"
fi
if curl -s --connect-timeout 5 http://localhost:8080 >/dev/null 2>&1; then
test_passed "Port 8080 erreichbar"
else
test_info "Port 8080 nicht verfügbar (optional)"
fi
else
test_info "Backend-Service nicht aktiv - Port-Tests übersprungen"
fi
# ========================== RASPBERRY PI TESTS ==========================
echo
echo "🍓 RASPBERRY PI TESTS"
echo "---------------------------------------------------------------------"
if grep -q "Raspberry Pi" /proc/cpuinfo 2>/dev/null; then
test_passed "Raspberry Pi erkannt"
# Boot-Konfiguration prüfen
if [ -f "/boot/config.txt" ]; then
if grep -q "gpu_mem=" /boot/config.txt; then
GPU_MEM=$(grep "gpu_mem=" /boot/config.txt | cut -d= -f2)
test_passed "GPU Memory Split konfiguriert: ${GPU_MEM}MB"
else
test_warning "GPU Memory Split nicht konfiguriert"
fi
if grep -q "disable_splash=1" /boot/config.txt; then
test_passed "Boot-Splash deaktiviert"
else
test_warning "Boot-Splash nicht deaktiviert"
fi
else
test_warning "/boot/config.txt nicht gefunden"
fi
# Temperatur prüfen
if command -v vcgencmd &>/dev/null; then
TEMP=$(vcgencmd measure_temp 2>/dev/null | cut -d= -f2 | cut -d"'" -f1)
if [ -n "$TEMP" ]; then
test_passed "CPU Temperatur: ${TEMP}°C"
if (( $(echo "$TEMP > 70" | bc -l 2>/dev/null || echo 0) )); then
test_warning "Hohe CPU Temperatur: ${TEMP}°C"
fi
fi
fi
else
test_info "Kein Raspberry Pi - Pi-spezifische Tests übersprungen"
fi
# ========================== WARTUNGSTOOLS-TESTS ==========================
echo
echo "🔧 WARTUNGSTOOLS-TESTS"
echo "---------------------------------------------------------------------"
if [ -f "/usr/local/bin/myp-maintenance" ]; then
if [ -x "/usr/local/bin/myp-maintenance" ]; then
test_passed "Wartungstool verfügbar"
else
test_failed "Wartungstool nicht ausführbar"
fi
else
test_failed "Wartungstool fehlt"
fi
# Log-Verzeichnisse
if [ -f "/var/log/kiosk-session.log" ]; then
test_passed "Kiosk-Session-Log verfügbar"
else
test_warning "Kiosk-Session-Log nicht vorhanden"
fi
# ========================== ZUSAMMENFASSUNG ==========================
echo
echo "====================================================================="
echo "📊 TEST-ZUSAMMENFASSUNG"
echo "====================================================================="
# Zähle Tests
TOTAL_TESTS=$(grep -E "(test_passed|test_failed|test_warning)" "$0" | wc -l)
echo "Gesamte Tests durchgeführt: $TOTAL_TESTS"
echo
echo "🎯 NÄCHSTE SCHRITTE:"
echo "---------------------------------------------------------------------"
if systemctl is-active --quiet lightdm 2>/dev/null; then
echo "✅ System ist bereits im Kiosk-Modus"
echo " - Kiosk läuft bereits"
echo " - Verwenden Sie 'sudo myp-maintenance status' für Details"
else
echo "🔄 System-Neustart erforderlich:"
echo " sudo reboot"
echo
echo "📋 Nach dem Neustart:"
echo " - System startet automatisch ohne Login"
echo " - Chromium öffnet im Kiosk-Modus"
echo " - Anwendung ist unter http://localhost:5000 oder :8080 verfügbar"
fi
echo
echo "🔧 WARTUNG:"
echo " sudo myp-maintenance status # System-Status"
echo " sudo myp-maintenance logs # Live-Logs"
echo " sudo myp-maintenance restart # Services neustarten"
echo
echo "📋 LOG-DATEIEN:"
echo " tail -f /var/log/kiosk-session.log"
echo " journalctl -u myp-druckerverwaltung -f"
echo " journalctl -u lightdm -f"
echo
echo "====================================================================="
echo "🏁 Test abgeschlossen"
echo "====================================================================="