336 lines
9.5 KiB
Bash
336 lines
9.5 KiB
Bash
#!/bin/bash
|
|
# MYP Kiosk Helper - Mercedes-Benz TBA Marienfelde
|
|
# Zusätzliche Hilfsfunktionen für Kiosk-Modus
|
|
|
|
set -e
|
|
|
|
# Farben
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
RED='\033[0;31m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
show_help() {
|
|
echo -e "${BLUE}MYP Kiosk Helper - Mercedes-Benz TBA Marienfelde${NC}"
|
|
echo ""
|
|
echo "Verfügbare Befehle:"
|
|
echo " start - Startet Kiosk-Modus"
|
|
echo " stop - Stoppt Kiosk-Modus"
|
|
echo " restart - Neustart des Kiosk-Modus"
|
|
echo " status - Zeigt aktuellen Status"
|
|
echo " autostart - Aktiviert/Deaktiviert Autostart"
|
|
echo " install - Installiert/Repariert Desktop-Icons"
|
|
echo " uninstall - Entfernt Kiosk-Komponenten"
|
|
echo " logs - Zeigt Docker-Container-Logs"
|
|
echo " update - Aktualisiert Container"
|
|
echo ""
|
|
echo "Beispiele:"
|
|
echo " $0 start # Startet Kiosk-Modus"
|
|
echo " $0 autostart enable # Aktiviert Autostart"
|
|
echo " $0 autostart disable # Deaktiviert Autostart"
|
|
}
|
|
|
|
check_requirements() {
|
|
local missing=0
|
|
|
|
if ! command -v docker &> /dev/null; then
|
|
echo -e "${RED}❌ Docker nicht installiert${NC}"
|
|
missing=1
|
|
fi
|
|
|
|
if ! command -v docker-compose &> /dev/null; then
|
|
echo -e "${RED}❌ Docker Compose nicht installiert${NC}"
|
|
missing=1
|
|
fi
|
|
|
|
if ! command -v chromium-browser &> /dev/null; then
|
|
echo -e "${RED}❌ Chromium Browser nicht installiert${NC}"
|
|
missing=1
|
|
fi
|
|
|
|
if [ $missing -eq 1 ]; then
|
|
echo -e "${YELLOW}Bitte führe zuerst das Setup-Skript aus: sudo ./setup-docker.sh${NC}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
start_kiosk() {
|
|
echo -e "${BLUE}🚀 Starte MYP Kiosk-Modus...${NC}"
|
|
|
|
# Prüfe ob bereits läuft
|
|
if pgrep -f "chromium.*kiosk.*localhost" > /dev/null; then
|
|
echo -e "${YELLOW}⚠️ Kiosk-Modus läuft bereits${NC}"
|
|
exit 1
|
|
fi
|
|
|
|
# Prüfe Docker-Container
|
|
if ! docker ps --format "table {{.Names}}" | grep -q myp-system; then
|
|
echo -e "${YELLOW}⚠️ Starte Docker-Container...${NC}"
|
|
if [ -f docker-compose.yml ]; then
|
|
docker-compose up -d
|
|
else
|
|
echo -e "${RED}❌ docker-compose.yml nicht gefunden${NC}"
|
|
exit 1
|
|
fi
|
|
sleep 10
|
|
fi
|
|
|
|
# Starte Kiosk-Skript
|
|
if [ -f "$HOME/start-myp-kiosk.sh" ]; then
|
|
"$HOME/start-myp-kiosk.sh" &
|
|
echo -e "${GREEN}✅ Kiosk-Modus gestartet${NC}"
|
|
else
|
|
echo -e "${RED}❌ Kiosk-Skript nicht gefunden: $HOME/start-myp-kiosk.sh${NC}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
stop_kiosk() {
|
|
echo -e "${BLUE}🛑 Stoppe MYP Kiosk-Modus...${NC}"
|
|
|
|
if [ -f "$HOME/stop-myp-kiosk.sh" ]; then
|
|
"$HOME/stop-myp-kiosk.sh"
|
|
echo -e "${GREEN}✅ Kiosk-Modus gestoppt${NC}"
|
|
else
|
|
# Manuell stoppen
|
|
pkill -f "chromium.*kiosk.*localhost" 2>/dev/null || true
|
|
pkill unclutter 2>/dev/null || true
|
|
echo -e "${GREEN}✅ Kiosk-Modus gestoppt (manuell)${NC}"
|
|
fi
|
|
}
|
|
|
|
restart_kiosk() {
|
|
echo -e "${BLUE}🔄 Starte Kiosk-Modus neu...${NC}"
|
|
stop_kiosk
|
|
sleep 3
|
|
start_kiosk
|
|
}
|
|
|
|
show_status() {
|
|
echo -e "${BLUE}📊 MYP System Status${NC}"
|
|
echo ""
|
|
|
|
# Docker-Container Status
|
|
echo -e "${BLUE}🐳 Docker Container:${NC}"
|
|
if docker ps --format "table {{.Names}}\t{{.Status}}" | grep myp-system; then
|
|
echo -e "${GREEN}✅ Container laufen${NC}"
|
|
else
|
|
echo -e "${RED}❌ Keine Container aktiv${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Kiosk-Status
|
|
echo -e "${BLUE}🖥️ Kiosk-Modus:${NC}"
|
|
if pgrep -f "chromium.*kiosk.*localhost" > /dev/null; then
|
|
local pid=$(pgrep -f "chromium.*kiosk.*localhost")
|
|
echo -e "${GREEN}✅ Aktiv (PID: $pid)${NC}"
|
|
else
|
|
echo -e "${RED}❌ Nicht aktiv${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Service-Erreichbarkeit
|
|
echo -e "${BLUE}🌐 Service-Erreichbarkeit:${NC}"
|
|
if curl -f http://localhost:80/ >/dev/null 2>&1; then
|
|
echo -e "${GREEN}✅ HTTP (Port 80)${NC}"
|
|
else
|
|
echo -e "${RED}❌ HTTP (Port 80)${NC}"
|
|
fi
|
|
|
|
if curl -k -f https://localhost:443/ >/dev/null 2>&1; then
|
|
echo -e "${GREEN}✅ HTTPS (Port 443)${NC}"
|
|
else
|
|
echo -e "${RED}❌ HTTPS (Port 443)${NC}"
|
|
fi
|
|
|
|
if curl -f http://localhost:5000/ >/dev/null 2>&1; then
|
|
echo -e "${GREEN}✅ Development (Port 5000)${NC}"
|
|
else
|
|
echo -e "${RED}❌ Development (Port 5000)${NC}"
|
|
fi
|
|
echo ""
|
|
|
|
# Autostart-Status
|
|
echo -e "${BLUE}🎯 Autostart:${NC}"
|
|
if [ -f "$HOME/.config/autostart/myp-kiosk.desktop" ]; then
|
|
echo -e "${GREEN}✅ Aktiviert${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ Deaktiviert${NC}"
|
|
fi
|
|
}
|
|
|
|
manage_autostart() {
|
|
local action=${1:-status}
|
|
local autostart_file="$HOME/.config/autostart/myp-kiosk.desktop"
|
|
local disabled_file="$HOME/.config/autostart/myp-kiosk.desktop.disabled"
|
|
|
|
case $action in
|
|
enable)
|
|
if [ -f "$disabled_file" ]; then
|
|
mv "$disabled_file" "$autostart_file"
|
|
echo -e "${GREEN}✅ Autostart aktiviert${NC}"
|
|
else
|
|
echo -e "${RED}❌ Autostart-Datei nicht gefunden${NC}"
|
|
fi
|
|
;;
|
|
disable)
|
|
if [ -f "$autostart_file" ]; then
|
|
mv "$autostart_file" "$disabled_file"
|
|
echo -e "${GREEN}✅ Autostart deaktiviert${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ Autostart bereits deaktiviert${NC}"
|
|
fi
|
|
;;
|
|
status)
|
|
if [ -f "$autostart_file" ]; then
|
|
echo -e "${GREEN}✅ Autostart ist aktiviert${NC}"
|
|
else
|
|
echo -e "${YELLOW}⚠️ Autostart ist deaktiviert${NC}"
|
|
fi
|
|
;;
|
|
*)
|
|
echo -e "${RED}❌ Unbekannte Autostart-Aktion: $action${NC}"
|
|
echo "Verfügbare Aktionen: enable, disable, status"
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
install_desktop_icons() {
|
|
echo -e "${BLUE}📍 Installiere Desktop-Icons...${NC}"
|
|
|
|
local desktop_path="$HOME/Desktop"
|
|
mkdir -p "$desktop_path"
|
|
|
|
# MYP Kiosk Icon
|
|
cat > "$desktop_path/MYP-Kiosk.desktop" << EOF
|
|
[Desktop Entry]
|
|
Version=1.0
|
|
Type=Application
|
|
Name=MYP Kiosk
|
|
Comment=Mercedes-Benz 3D-Drucker Management (Kiosk-Modus)
|
|
Icon=applications-internet
|
|
Exec=$HOME/start-myp-kiosk.sh
|
|
Terminal=false
|
|
StartupNotify=true
|
|
Categories=Application;Network;
|
|
Keywords=MYP;Mercedes;Drucker;3D;Kiosk;
|
|
EOF
|
|
|
|
chmod +x "$desktop_path/MYP-Kiosk.desktop"
|
|
|
|
# MYP Container Management Icon
|
|
cat > "$desktop_path/MYP-Container.desktop" << EOF
|
|
[Desktop Entry]
|
|
Version=1.0
|
|
Type=Application
|
|
Name=MYP Container
|
|
Comment=Mercedes-Benz MYP Docker Container Management
|
|
Icon=applications-system
|
|
Exec=x-terminal-emulator -e 'cd \$(find /home /opt -name "docker-compose.yml" -path "*/myp*" -exec dirname {} \\; 2>/dev/null | head -1) && echo "🐳 MYP Container Management" && echo "Verfügbare Befehle:" && echo " docker-compose ps - Status anzeigen" && echo " docker-compose logs -f - Logs verfolgen" && echo " docker-compose restart - Neustart" && echo " docker-compose down - Stoppen" && echo " docker-compose up -d - Starten" && echo "" && bash'
|
|
Terminal=false
|
|
StartupNotify=true
|
|
Categories=Application;System;
|
|
Keywords=MYP;Docker;Container;Management;
|
|
EOF
|
|
|
|
chmod +x "$desktop_path/MYP-Container.desktop"
|
|
|
|
echo -e "${GREEN}✅ Desktop-Icons installiert${NC}"
|
|
}
|
|
|
|
uninstall_kiosk() {
|
|
echo -e "${BLUE}🗑️ Entferne Kiosk-Komponenten...${NC}"
|
|
|
|
# Stoppe Kiosk-Modus
|
|
stop_kiosk
|
|
|
|
# Entferne Desktop-Icons
|
|
rm -f "$HOME/Desktop/MYP-Kiosk.desktop"
|
|
rm -f "$HOME/Desktop/MYP-Container.desktop"
|
|
|
|
# Entferne Autostart
|
|
rm -f "$HOME/.config/autostart/myp-kiosk.desktop"
|
|
rm -f "$HOME/.config/autostart/myp-kiosk.desktop.disabled"
|
|
|
|
# Entferne Skripte
|
|
rm -f "$HOME/start-myp-kiosk.sh"
|
|
rm -f "$HOME/stop-myp-kiosk.sh"
|
|
rm -f "$HOME/restart-myp-kiosk.sh"
|
|
|
|
echo -e "${GREEN}✅ Kiosk-Komponenten entfernt${NC}"
|
|
}
|
|
|
|
show_logs() {
|
|
echo -e "${BLUE}📋 Docker Container Logs${NC}"
|
|
|
|
if docker ps --format "table {{.Names}}" | grep -q myp-system; then
|
|
docker-compose logs --tail=50 -f
|
|
else
|
|
echo -e "${RED}❌ Keine aktiven Container gefunden${NC}"
|
|
fi
|
|
}
|
|
|
|
update_containers() {
|
|
echo -e "${BLUE}🔄 Aktualisiere Container...${NC}"
|
|
|
|
if [ -f docker-compose.yml ]; then
|
|
docker-compose pull
|
|
docker-compose up -d --force-recreate
|
|
echo -e "${GREEN}✅ Container aktualisiert${NC}"
|
|
else
|
|
echo -e "${RED}❌ docker-compose.yml nicht gefunden${NC}"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Hauptfunktion
|
|
main() {
|
|
local command=${1:-help}
|
|
|
|
case $command in
|
|
start)
|
|
check_requirements
|
|
start_kiosk
|
|
;;
|
|
stop)
|
|
stop_kiosk
|
|
;;
|
|
restart)
|
|
check_requirements
|
|
restart_kiosk
|
|
;;
|
|
status)
|
|
show_status
|
|
;;
|
|
autostart)
|
|
manage_autostart ${2:-status}
|
|
;;
|
|
install)
|
|
install_desktop_icons
|
|
;;
|
|
uninstall)
|
|
uninstall_kiosk
|
|
;;
|
|
logs)
|
|
show_logs
|
|
;;
|
|
update)
|
|
check_requirements
|
|
update_containers
|
|
;;
|
|
help|--help|-h)
|
|
show_help
|
|
;;
|
|
*)
|
|
echo -e "${RED}❌ Unbekannter Befehl: $command${NC}"
|
|
echo ""
|
|
show_help
|
|
exit 1
|
|
;;
|
|
esac
|
|
}
|
|
|
|
# Skript ausführen
|
|
main "$@" |