manage-your-printer/scripts/update_fehlerresilienz.sh
2025-06-04 10:03:22 +02:00

1030 lines
30 KiB
Bash
Raw Permalink 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 Fehlerresilienz und Wartungsfreier Betrieb - Update Script
# =============================================================================
# Installiert und konfiguriert alle Komponenten für absolute Fehlerresilienz
# und wartungsfreien Produktionsbetrieb mit Kiosk-Modus.
# BEREINIGT ALLE DESKTOP-ENVIRONMENTS für maximale Stabilität!
#
# Autor: MYP System
# Version: 2.1.0
# Datum: $(date '+%Y-%m-%d')
# =============================================================================
set -euo pipefail
# Farben für Output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
WHITE='\033[1;37m'
NC='\033[0m' # No Color
# Logging-Funktionen
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
log_debug() {
echo -e "${BLUE}[DEBUG]${NC} $1"
}
log_header() {
echo -e "\n${PURPLE}=== $1 ===${NC}"
}
log_step() {
echo -e "${CYAN}${NC} $1"
}
# Fehlerbehandlung
error_exit() {
log_error "$1"
exit 1
}
# Prüfe Root-Rechte
check_root() {
if [[ $EUID -ne 0 ]]; then
error_exit "Dieses Script muss als root ausgeführt werden!"
fi
}
# Prüfe Betriebssystem
check_os() {
if [[ ! -f /etc/os-release ]]; then
error_exit "Kann Betriebssystem nicht identifizieren!"
fi
. /etc/os-release
case "$ID" in
ubuntu|debian)
PACKAGE_MANAGER="apt"
;;
centos|rhel|fedora)
PACKAGE_MANAGER="yum"
;;
arch)
PACKAGE_MANAGER="pacman"
;;
*)
error_exit "Nicht unterstütztes Betriebssystem: $ID"
;;
esac
log_info "Erkanntes OS: $PRETTY_NAME ($ID)"
log_info "Package Manager: $PACKAGE_MANAGER"
}
# =============================================================================
# DESKTOP-ENVIRONMENT BEREINIGUNG
# =============================================================================
cleanup_desktop_environments() {
log_header "Desktop-Environment Bereinigung"
log_step "Stoppe alle laufenden Desktop-Services..."
# Stoppe Display-Manager und Desktop-Services
systemctl stop gdm3 2>/dev/null || true
systemctl stop gdm 2>/dev/null || true
systemctl stop lightdm 2>/dev/null || true
systemctl stop sddm 2>/dev/null || true
systemctl stop xdm 2>/dev/null || true
systemctl stop kdm 2>/dev/null || true
systemctl stop lxdm 2>/dev/null || true
# Deaktiviere Display-Manager
systemctl disable gdm3 2>/dev/null || true
systemctl disable gdm 2>/dev/null || true
systemctl disable lightdm 2>/dev/null || true
systemctl disable sddm 2>/dev/null || true
systemctl disable xdm 2>/dev/null || true
systemctl disable kdm 2>/dev/null || true
systemctl disable lxdm 2>/dev/null || true
log_step "Entferne Desktop-Environments und unnötige Pakete..."
if [[ "$PACKAGE_MANAGER" == "apt" ]]; then
# GNOME entfernen
apt-get remove --purge -y \
ubuntu-desktop \
gnome-desktop* \
gnome-shell \
gnome-session \
gnome-control-center \
gnome-settings-daemon \
nautilus \
gdm3 \
gdm \
2>/dev/null || true
# KDE entfernen
apt-get remove --purge -y \
kubuntu-desktop \
kde-plasma-desktop \
plasma-desktop \
kdebase-workspace \
kde-window-manager \
kwin \
dolphin \
sddm \
kdm \
2>/dev/null || true
# XFCE entfernen
apt-get remove --purge -y \
xubuntu-desktop \
xfce4 \
xfce4-session \
xfce4-panel \
xfwm4 \
thunar \
lightdm \
2>/dev/null || true
# LXDE/LXQt entfernen
apt-get remove --purge -y \
lubuntu-desktop \
lxde \
lxde-core \
lxqt \
lxsession \
pcmanfm \
lxdm \
2>/dev/null || true
# MATE entfernen
apt-get remove --purge -y \
ubuntu-mate-desktop \
mate-desktop-environment \
mate-session-manager \
mate-panel \
caja \
2>/dev/null || true
# Cinnamon entfernen
apt-get remove --purge -y \
cinnamon \
cinnamon-desktop-environment \
cinnamon-session \
nemo \
2>/dev/null || true
# Budgie entfernen
apt-get remove --purge -y \
ubuntu-budgie-desktop \
budgie-desktop \
budgie-desktop-environment \
2>/dev/null || true
# Unity entfernen (falls noch vorhanden)
apt-get remove --purge -y \
ubuntu-unity-desktop \
unity \
unity-control-center \
unity-settings-daemon \
2>/dev/null || true
# Weitere Desktop-Programme entfernen
apt-get remove --purge -y \
firefox \
libreoffice* \
thunderbird \
evolution \
rhythmbox \
totem \
cheese \
shotwell \
simple-scan \
remmina \
transmission-gtk \
brasero \
deja-dup \
usb-creator-gtk \
software-center \
ubuntu-software \
gnome-software \
snap-store \
update-manager \
2>/dev/null || true
# Autoremove ausführen
apt-get autoremove --purge -y
apt-get autoclean
elif [[ "$PACKAGE_MANAGER" == "yum" ]]; then
# GNOME entfernen
yum groupremove -y "GNOME Desktop" 2>/dev/null || true
yum remove -y gnome-shell gdm 2>/dev/null || true
# KDE entfernen
yum groupremove -y "KDE Plasma Workspaces" 2>/dev/null || true
yum remove -y plasma-desktop sddm 2>/dev/null || true
# XFCE entfernen
yum groupremove -y "Xfce Desktop" 2>/dev/null || true
yum remove -y xfce4-session lightdm 2>/dev/null || true
# LXDE entfernen
yum groupremove -y "LXDE Desktop" 2>/dev/null || true
yum remove -y lxde-common lxdm 2>/dev/null || true
# MATE entfernen
yum groupremove -y "MATE Desktop" 2>/dev/null || true
# Cinnamon entfernen
yum remove -y cinnamon 2>/dev/null || true
elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
# GNOME entfernen
pacman -Rns --noconfirm gnome gnome-extra gdm 2>/dev/null || true
# KDE entfernen
pacman -Rns --noconfirm plasma kde-applications sddm 2>/dev/null || true
# XFCE entfernen
pacman -Rns --noconfirm xfce4 xfce4-goodies lightdm 2>/dev/null || true
# LXDE entfernen
pacman -Rns --noconfirm lxde lxdm 2>/dev/null || true
# MATE entfernen
pacman -Rns --noconfirm mate mate-extra 2>/dev/null || true
# Cinnamon entfernen
pacman -Rns --noconfirm cinnamon 2>/dev/null || true
fi
log_step "Bereinige Autostart-Verzeichnisse..."
# Bereinige System-Autostart
rm -rf /etc/xdg/autostart/* 2>/dev/null || true
rm -rf /usr/share/autostart/* 2>/dev/null || true
# Bereinige Benutzer-Autostart (falls vorhanden)
for user_home in /home/*; do
if [[ -d "$user_home" ]]; then
rm -rf "$user_home/.config/autostart"/* 2>/dev/null || true
rm -rf "$user_home/.kde/Autostart"/* 2>/dev/null || true
rm -rf "$user_home/.kde4/Autostart"/* 2>/dev/null || true
fi
done
log_step "Setze Text-Boot als Standard..."
# Setze Standard-Target auf Multi-User (Text-Modus)
systemctl set-default multi-user.target
log_step "Bereinige Desktop-Konfigurationsdateien..."
# Entferne Desktop-Konfigurationen
rm -rf /etc/gdm3 2>/dev/null || true
rm -rf /etc/gdm 2>/dev/null || true
rm -rf /etc/lightdm 2>/dev/null || true
rm -rf /etc/sddm.conf 2>/dev/null || true
rm -rf /etc/kde 2>/dev/null || true
rm -rf /etc/xdg/plasma* 2>/dev/null || true
rm -rf /etc/xdg/kde* 2>/dev/null || true
# Bereinige X11-Sessions (außer dem was wir für Kiosk brauchen)
find /usr/share/xsessions/ -name "*.desktop" -not -name "kiosk*" -delete 2>/dev/null || true
find /usr/share/wayland-sessions/ -name "*.desktop" -delete 2>/dev/null || true
log_info "✅ Desktop-Environment Bereinigung abgeschlossen"
}
# =============================================================================
# MINIMALE X11-INSTALLATION FÜR KIOSK
# =============================================================================
install_minimal_x11() {
log_header "Minimale X11-Installation für Kiosk"
log_step "Installiere minimale X11-Komponenten..."
if [[ "$PACKAGE_MANAGER" == "apt" ]]; then
apt-get update
apt-get install -y \
xorg \
xserver-xorg-core \
xserver-xorg-input-all \
xserver-xorg-video-all \
xinit \
xauth \
xterm \
openbox \
unclutter \
2>/dev/null || true
elif [[ "$PACKAGE_MANAGER" == "yum" ]]; then
yum install -y \
xorg-x11-server-Xorg \
xorg-x11-drv-* \
xinit \
xauth \
xterm \
openbox \
unclutter \
2>/dev/null || true
elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
pacman -S --noconfirm \
xorg-server \
xorg-xinit \
xorg-xauth \
xterm \
openbox \
unclutter \
2>/dev/null || true
fi
log_info "✅ Minimale X11-Installation abgeschlossen"
}
# =============================================================================
# KIOSK-BENUTZER KONFIGURATION
# =============================================================================
configure_kiosk_user() {
log_header "Kiosk-Benutzer Konfiguration"
# Erstelle kiosk-Benutzer falls nicht vorhanden
if ! id "kiosk" &>/dev/null; then
log_step "Erstelle kiosk-Benutzer..."
useradd -m -s /bin/bash -G audio,video,input kiosk
# Setze einfaches Passwort (wird für Autologin nicht benötigt)
echo "kiosk:kiosk123" | chpasswd
log_info "✅ Kiosk-Benutzer erstellt"
else
log_info " Kiosk-Benutzer bereits vorhanden"
fi
# Konfiguriere Kiosk-Benutzer-Umgebung
log_step "Konfiguriere Kiosk-Benutzer-Umgebung..."
# Erstelle .xinitrc für Kiosk-Session
cat > /home/kiosk/.xinitrc << 'EOF'
#!/bin/bash
# Deaktiviere Bildschirmschoner und Energiesparfunktionen
xset s off
xset s noblank
xset -dpms
# Verstecke Mauszeiger bei Inaktivität
unclutter -idle 1 &
# Starte Openbox Window Manager (minimal)
openbox &
# Warte bis Backend verfügbar ist (mit Timeout)
BACKEND_URL="https://localhost"
TIMEOUT=300
ELAPSED=0
while ! curl -k -s "$BACKEND_URL" >/dev/null 2>&1; do
if [ $ELAPSED -ge $TIMEOUT ]; then
echo "❌ Backend nach ${TIMEOUT}s nicht erreichbar - starte trotzdem Browser"
break
fi
echo "⏳ Warte auf Backend... (${ELAPSED}s/${TIMEOUT}s)"
sleep 5
ELAPSED=$((ELAPSED + 5))
done
# Browser-Präferenzen für Stabilität
export MOZ_DISABLE_RDD_SANDBOX=1
export MOZ_DISABLE_CONTENT_SANDBOX=1
# Starte Browser im Kiosk-Modus (Failover: Chromium -> Firefox -> Chrome)
if command -v chromium-browser >/dev/null; then
BROWSER="chromium-browser"
BROWSER_ARGS="--kiosk --no-sandbox --disable-dev-shm-usage --disable-gpu --disable-software-rasterizer --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-renderer-backgrounding --disable-features=TranslateUI --disable-ipc-flooding-protection --noerrdialogs --disable-infobars --disable-session-crashed-bubble --disable-component-update --check-for-update-interval=31536000"
elif command -v firefox >/dev/null; then
BROWSER="firefox"
BROWSER_ARGS="--kiosk"
elif command -v google-chrome >/dev/null; then
BROWSER="google-chrome"
BROWSER_ARGS="--kiosk --no-sandbox --disable-dev-shm-usage --disable-gpu"
else
echo "❌ Kein unterstützter Browser gefunden!"
exit 1
fi
echo "🚀 Starte $BROWSER im Kiosk-Modus..."
exec $BROWSER $BROWSER_ARGS "$BACKEND_URL"
EOF
chmod +x /home/kiosk/.xinitrc
chown kiosk:kiosk /home/kiosk/.xinitrc
# Konfiguriere Bash-Profile für automatisches X-Start
cat > /home/kiosk/.bash_profile << 'EOF'
# Automatisches X-Start für Kiosk-Modus
if [[ -z $DISPLAY && $(tty) == /dev/tty1 ]]; then
exec startx
fi
EOF
chown kiosk:kiosk /home/kiosk/.bash_profile
log_info "✅ Kiosk-Benutzer konfiguriert"
}
# =============================================================================
# AUTOLOGIN KONFIGURATION
# =============================================================================
configure_autologin() {
log_header "Autologin Konfiguration"
log_step "Konfiguriere Getty für Autologin..."
# Erstelle Getty Override für tty1
mkdir -p /etc/systemd/system/getty@tty1.service.d/
cat > /etc/systemd/system/getty@tty1.service.d/override.conf << 'EOF'
[Service]
ExecStart=
ExecStart=-/sbin/agetty --autologin kiosk --noclear %I $TERM
Type=idle
EOF
# Stelle sicher, dass getty@tty1 aktiviert ist
systemctl enable getty@tty1.service
log_info "✅ Autologin konfiguriert"
}
# =============================================================================
# SYSTEM-ABHÄNGIGKEITEN
# =============================================================================
install_system_dependencies() {
log_header "System-Abhängigkeiten Installation"
log_step "Aktualisiere Paket-Listen..."
if [[ "$PACKAGE_MANAGER" == "apt" ]]; then
apt-get update
log_step "Installiere System-Abhängigkeiten..."
apt-get install -y \
python3 \
python3-pip \
python3-venv \
curl \
wget \
sudo \
systemd \
rsyslog \
cron \
logrotate \
unzip \
git \
psutil \
htop \
netcat \
jq
log_step "Installiere Browser..."
# Installiere bevorzugten Browser (Chromium)
apt-get install -y chromium-browser 2>/dev/null || {
log_warn "Chromium nicht verfügbar, versuche Firefox..."
apt-get install -y firefox 2>/dev/null || {
log_warn "Firefox nicht verfügbar, versuche Chrome..."
# Chrome Repository hinzufügen falls verfügbar
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - 2>/dev/null || true
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list 2>/dev/null || true
apt-get update 2>/dev/null || true
apt-get install -y google-chrome-stable 2>/dev/null || log_error "Kein Browser installiert!"
}
}
elif [[ "$PACKAGE_MANAGER" == "yum" ]]; then
yum update -y
yum install -y \
python3 \
python3-pip \
curl \
wget \
sudo \
systemd \
rsyslog \
cronie \
logrotate \
unzip \
git \
python3-psutil \
htop \
nc \
jq \
chromium \
firefox
elif [[ "$PACKAGE_MANAGER" == "pacman" ]]; then
pacman -Sy
pacman -S --noconfirm \
python \
python-pip \
curl \
wget \
sudo \
systemd \
rsyslog \
cronie \
logrotate \
unzip \
git \
python-psutil \
htop \
netcat \
jq \
chromium \
firefox
fi
log_info "✅ System-Abhängigkeiten installiert"
}
install_python_dependencies() {
log_header "Python-Abhängigkeiten Installation"
log_step "Installiere Python-Pakete für Error-Recovery..."
# Upgrade pip
python3 -m pip install --upgrade pip
# Installiere erforderliche Python-Pakete
python3 -m pip install \
psutil \
watchdog \
requests \
flask \
sqlalchemy \
APScheduler
log_info "✅ Python-Abhängigkeiten installiert"
}
configure_logging() {
log_header "Logging-Konfiguration"
log_step "Erstelle Log-Verzeichnisse..."
# Erstelle Log-Verzeichnisse mit korrekten Berechtigungen
mkdir -p /var/log/myp/{system_control,error_recovery,kiosk}
chmod 755 /var/log/myp
chmod 755 /var/log/myp/*
log_step "Konfiguriere Logrotate..."
# Konfiguriere Log-Rotation
cat > /etc/logrotate.d/myp << 'EOF'
/var/log/myp/*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 644 root root
postrotate
systemctl reload rsyslog 2>/dev/null || true
endscript
}
/var/log/myp/*/*.log {
daily
rotate 30
compress
delaycompress
missingok
notifempty
create 644 root root
postrotate
systemctl reload rsyslog 2>/dev/null || true
endscript
}
EOF
log_step "Konfiguriere Rsyslog für MYP..."
# Konfiguriere Rsyslog für MYP-spezifische Logs
cat > /etc/rsyslog.d/50-myp.conf << 'EOF'
# MYP System Logging
# System Control Logs
:programname,isequal,"myp-system" /var/log/myp/system_control/system.log
:programname,isequal,"myp-kiosk" /var/log/myp/kiosk/kiosk.log
# Error Recovery Logs
if $programname contains "error-recovery" then /var/log/myp/error_recovery/recovery.log
# Stop weitere Verarbeitung für MYP-Messages
if $programname contains "myp-" then stop
EOF
# Rsyslog neu starten
systemctl restart rsyslog
log_info "✅ Logging konfiguriert"
}
configure_sudo_permissions() {
log_header "Sudo-Berechtigungen Konfiguration"
log_step "Konfiguriere Sudo-Rechte für System-Operationen..."
# Erstelle sudoers-Datei für MYP-System-Operationen
cat > /etc/sudoers.d/myp-system << 'EOF'
# MYP System Control Permissions
# Erlaubt webapp-Benutzer System-Operationen für wartungsfreien Betrieb
# System-Neustart und Shutdown
%sudo ALL=(ALL) NOPASSWD: /sbin/reboot, /sbin/shutdown, /bin/systemctl reboot, /bin/systemctl poweroff
# Service-Management
%sudo ALL=(ALL) NOPASSWD: /bin/systemctl start myp-*, /bin/systemctl stop myp-*, /bin/systemctl restart myp-*, /bin/systemctl reload myp-*
%sudo ALL=(ALL) NOPASSWD: /bin/systemctl enable myp-*, /bin/systemctl disable myp-*
%sudo ALL=(ALL) NOPASSWD: /bin/systemctl status myp-*, /bin/systemctl is-active myp-*
# Kiosk-spezifische Services
%sudo ALL=(ALL) NOPASSWD: /bin/systemctl restart getty@tty1.service
%sudo ALL=(ALL) NOPASSWD: /bin/systemctl set-default multi-user.target, /bin/systemctl set-default graphical.target
# Log-Management
%sudo ALL=(ALL) NOPASSWD: /bin/journalctl *
# Netzwerk-Services (für Recovery)
%sudo ALL=(ALL) NOPASSWD: /bin/systemctl restart NetworkManager, /bin/systemctl restart networking
# Cache und Temp-Bereinigung
%sudo ALL=(ALL) NOPASSWD: /bin/sync, /usr/bin/echo * > /proc/sys/vm/drop_caches
# Kiosk-Benutzer Management
%sudo ALL=(ALL) NOPASSWD: /bin/su - kiosk, /bin/loginctl kill-user kiosk
EOF
# Validiere sudoers-Datei
if ! visudo -c -f /etc/sudoers.d/myp-system; then
log_error "Sudoers-Konfiguration ungültig!"
rm -f /etc/sudoers.d/myp-system
return 1
fi
log_info "✅ Sudo-Berechtigungen konfiguriert"
}
install_error_recovery_files() {
log_header "Error-Recovery-Dateien Installation"
log_step "Kopiere Error-Recovery-Module..."
# Prüfe ob Backend-Verzeichnis existiert
if [[ ! -d "/opt/myp-backend" ]] && [[ ! -d "/var/www/myp" ]] && [[ ! -d "$(pwd)" ]]; then
error_exit "MYP-Backend-Verzeichnis nicht gefunden!"
fi
# Bestimme Backend-Pfad
BACKEND_PATH=""
if [[ -d "/opt/myp-backend" ]]; then
BACKEND_PATH="/opt/myp-backend"
elif [[ -d "/var/www/myp" ]]; then
BACKEND_PATH="/var/www/myp"
else
BACKEND_PATH="$(pwd)"
fi
log_info "Backend-Pfad: $BACKEND_PATH"
# Prüfe ob Error-Recovery-Dateien existieren
if [[ ! -f "$BACKEND_PATH/utils/error_recovery.py" ]]; then
log_warn "Error-Recovery-Module nicht gefunden in $BACKEND_PATH"
log_warn "Bitte stellen Sie sicher, dass das Update korrekt angewendet wurde"
return 1
fi
# Prüfe ob System-Control-Module existiert
if [[ ! -f "$BACKEND_PATH/utils/system_control.py" ]]; then
log_warn "System-Control-Module nicht gefunden in $BACKEND_PATH"
log_warn "Bitte stellen Sie sicher, dass das Update korrekt angewendet wurde"
return 1
fi
log_info "✅ Error-Recovery-Module gefunden und validiert"
}
install_kiosk_service() {
log_header "Kiosk-Service Installation"
log_step "Installiere optimierten Kiosk-Service..."
# Der Kiosk-Service wurde bereits durch das Update installiert
# Wir müssen nur sicherstellen, dass er korrekt konfiguriert ist
if [[ ! -f "/etc/systemd/system/myp-kiosk.service" ]]; then
log_warn "Kiosk-Service-Datei nicht gefunden!"
log_warn "Bitte führen Sie zuerst das Backend-Update durch"
return 1
fi
# Service aktivieren aber noch nicht starten
systemctl daemon-reload
systemctl enable myp-kiosk.service
log_info "✅ Kiosk-Service installiert und aktiviert"
}
configure_system_optimizations() {
log_header "System-Optimierungen"
log_step "Konfiguriere Kernel-Parameter für Stabilität..."
# Kernel-Parameter für bessere Stabilität
cat > /etc/sysctl.d/99-myp-stability.conf << 'EOF'
# MYP System Stability Configuration
# Speicher-Management
vm.swappiness = 10
vm.dirty_ratio = 15
vm.dirty_background_ratio = 5
# Netzwerk-Stabilität
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
# File-System-Stabilität
fs.file-max = 65536
fs.inotify.max_user_watches = 524288
EOF
# Lade neue sysctl-Einstellungen
sysctl -p /etc/sysctl.d/99-myp-stability.conf
log_step "Konfiguriere System-Limits..."
# System-Limits für bessere Performance
cat > /etc/security/limits.d/99-myp.conf << 'EOF'
# MYP System Limits
* soft nofile 65536
* hard nofile 65536
* soft nproc 32768
* hard nproc 32768
kiosk soft nofile 8192
kiosk hard nofile 8192
kiosk soft nproc 4096
kiosk hard nproc 4096
EOF
log_step "Deaktiviere unnötige Services..."
# Deaktiviere Services die für Kiosk-Betrieb nicht benötigt werden
SERVICES_TO_DISABLE=(
"cups"
"cups-browsed"
"bluetooth"
"ModemManager"
"avahi-daemon"
"whoopsie"
"apport"
"speech-dispatcher"
"brltty"
"snapd"
"ubuntu-advantage"
)
for service in "${SERVICES_TO_DISABLE[@]}"; do
if systemctl is-enabled "$service" &>/dev/null; then
log_debug "Deaktiviere Service: $service"
systemctl disable "$service" 2>/dev/null || true
systemctl stop "$service" 2>/dev/null || true
fi
done
log_step "Konfiguriere automatische Updates-Deaktivierung..."
# Deaktiviere automatische Updates für Stabilität
if [[ -f "/etc/apt/apt.conf.d/20auto-upgrades" ]]; then
cat > /etc/apt/apt.conf.d/20auto-upgrades << 'EOF'
APT::Periodic::Update-Package-Lists "0";
APT::Periodic::Unattended-Upgrade "0";
APT::Periodic::Download-Upgradeable-Packages "0";
APT::Periodic::AutocleanInterval "0";
EOF
fi
# Deaktiviere unattended-upgrades
systemctl disable unattended-upgrades 2>/dev/null || true
systemctl stop unattended-upgrades 2>/dev/null || true
log_info "✅ System-Optimierungen angewendet"
}
validate_installation() {
log_header "Installation validieren"
local errors=0
log_step "Prüfe Kiosk-Benutzer..."
if ! id "kiosk" &>/dev/null; then
log_error "❌ Kiosk-Benutzer nicht gefunden"
((errors++))
else
log_info "✅ Kiosk-Benutzer OK"
fi
log_step "Prüfe Kiosk-Service..."
if ! systemctl is-enabled myp-kiosk.service &>/dev/null; then
log_error "❌ Kiosk-Service nicht aktiviert"
((errors++))
else
log_info "✅ Kiosk-Service OK"
fi
log_step "Prüfe Browser-Installation..."
if ! command -v chromium-browser &>/dev/null && ! command -v firefox &>/dev/null && ! command -v google-chrome &>/dev/null; then
log_error "❌ Kein unterstützter Browser gefunden"
((errors++))
else
log_info "✅ Browser verfügbar"
fi
log_step "Prüfe X11-Installation..."
if ! command -v X &>/dev/null && ! command -v Xorg &>/dev/null; then
log_error "❌ X11-Server nicht gefunden"
((errors++))
else
log_info "✅ X11-Server verfügbar"
fi
log_step "Prüfe Autologin-Konfiguration..."
if [[ ! -f "/etc/systemd/system/getty@tty1.service.d/override.conf" ]]; then
log_error "❌ Autologin nicht konfiguriert"
((errors++))
else
log_info "✅ Autologin konfiguriert"
fi
log_step "Prüfe Python-Module..."
if ! python3 -c "import psutil" &>/dev/null; then
log_error "❌ Python psutil-Modul fehlt"
((errors++))
else
log_info "✅ Python-Module verfügbar"
fi
if [[ $errors -eq 0 ]]; then
log_info "✅ Alle Validierungen erfolgreich"
return 0
else
log_error "$errors Validierungsfehler gefunden"
return 1
fi
}
show_completion_summary() {
log_header "Installation Abgeschlossen"
echo -e "${GREEN}"
echo "=================================================="
echo " 🎉 MYP FEHLERRESILIENZ INSTALLATION ERFOLG "
echo "=================================================="
echo -e "${NC}"
echo "✅ Desktop-Environments bereinigt"
echo "✅ Minimale X11-Umgebung installiert"
echo "✅ Kiosk-Benutzer konfiguriert"
echo "✅ Autologin aktiviert"
echo "✅ Error-Recovery-System installiert"
echo "✅ System-Control-Manager konfiguriert"
echo "✅ Robuster Kiosk-Service installiert"
echo "✅ System-Optimierungen angewendet"
echo
echo -e "${YELLOW}📋 NÄCHSTE SCHRITTE:${NC}"
echo "1. System neu starten für vollständige Aktivierung:"
echo " ${CYAN}sudo reboot${NC}"
echo
echo "2. Nach dem Neustart startet automatisch der Kiosk-Modus"
echo
echo "3. Überwachen Sie das System über die Admin-Oberfläche:"
echo " ${CYAN}https://<ihr-system>/admin${NC}"
echo
echo -e "${YELLOW}🔧 WARTUNG:${NC}"
echo "• Error-Recovery läuft automatisch im Hintergrund"
echo "• System-Control über Admin-Panel verfügbar"
echo "• Logs werden automatisch rotiert"
echo "• Kein manueller Wartungsaufwand erforderlich"
echo
echo -e "${YELLOW}🆘 NOTFALL-ZUGRIFF:${NC}"
echo "• SSH-Zugriff bleibt für Wartung verfügbar"
echo "• Kiosk-Deaktivierung über Admin-Panel"
echo "• System-Recovery über Tastatur: Strg+Alt+F2"
echo
echo -e "${RED}⚠️ WICHTIG:${NC}"
echo "Das System läuft jetzt im wartungsfreien Produktionsmodus!"
echo "Alle Änderungen sollten über die Admin-Oberfläche erfolgen."
echo
}
# =============================================================================
# MAIN EXECUTION
# =============================================================================
main() {
clear
echo -e "${PURPLE}"
echo "=============================================================="
echo " MYP FEHLERRESILIENZ & WARTUNGSFREIER BETRIEB - UPDATE "
echo "=============================================================="
echo -e "${NC}"
echo
echo "Dieses Script installiert:"
echo "• Absolute Fehlerresilienz mit automatischer Wiederherstellung"
echo "• Wartungsfreien Produktionsbetrieb"
echo "• Optimierten Kiosk-Modus mit robuster Browser-Steuerung"
echo "• Vollautomatische System-Überwachung und -Reparatur"
echo "• Desktop-Environment-Bereinigung für maximale Stabilität"
echo
echo -e "${RED}⚠️ WARNUNG: Alle Desktop-Environments werden entfernt!${NC}"
echo -e "${RED} Das System wird zu einem reinen Kiosk-System!${NC}"
echo
read -p "Möchten Sie fortfahren? [y/N]: " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Installation abgebrochen."
exit 0
fi
log_info "Starte MYP Fehlerresilienz-Installation..."
# Grundlegende Systemprüfungen
check_root
check_os
# Desktop-Environment vollständig bereinigen
cleanup_desktop_environments
# Minimale X11-Umgebung für Kiosk installieren
install_minimal_x11
# System-Abhängigkeiten installieren
install_system_dependencies
install_python_dependencies
# Kiosk-Benutzer und Autologin konfigurieren
configure_kiosk_user
configure_autologin
# Logging und Berechtigungen konfigurieren
configure_logging
configure_sudo_permissions
# Error-Recovery und Kiosk-Service installieren
install_error_recovery_files
install_kiosk_service
# System-Optimierungen anwenden
configure_system_optimizations
# Installation validieren
if validate_installation; then
show_completion_summary
echo
read -p "System jetzt neu starten? [y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
log_info "🔄 System wird neu gestartet..."
sleep 3
reboot
else
log_info "🔄 Bitte starten Sie das System manuell neu: sudo reboot"
fi
else
log_error "❌ Installation nicht erfolgreich - bitte Fehler beheben"
exit 1
fi
}
# Script ausführen
main "$@"