📚 Improved IHK Projektdokumentation and logs for better clarity & error handling in backend installation process. 🖥️🔍
This commit is contained in:
117
backend/setup.sh
117
backend/setup.sh
@@ -11,6 +11,42 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# =========================== KOMMANDOZEILEN-PARAMETER =======================
|
||||
# Erkenne Skip-Parameter
|
||||
SKIP_BASH_PROFILE=false
|
||||
SKIP_SYSTEMD=false
|
||||
SKIP_KIOSK=false
|
||||
|
||||
for arg in "$@"; do
|
||||
case $arg in
|
||||
--skip-bash-profile)
|
||||
SKIP_BASH_PROFILE=true
|
||||
;;
|
||||
--skip-systemd)
|
||||
SKIP_SYSTEMD=true
|
||||
;;
|
||||
--skip-kiosk)
|
||||
SKIP_KIOSK=true
|
||||
;;
|
||||
--wsl|--dev)
|
||||
# WSL/Development-Modus: Überspringe systemspezifische Schritte
|
||||
SKIP_BASH_PROFILE=true
|
||||
SKIP_SYSTEMD=true
|
||||
SKIP_KIOSK=true
|
||||
echo "WSL/Development-Modus aktiviert - systemspezifische Schritte werden übersprungen"
|
||||
;;
|
||||
--help|-h)
|
||||
echo "MYP Setup-Skript - Optionen:"
|
||||
echo " --skip-bash-profile Überspringe Bash-Profile Updates"
|
||||
echo " --skip-systemd Überspringe Systemd-Service Installation"
|
||||
echo " --skip-kiosk Überspringe Kiosk-Modus Konfiguration"
|
||||
echo " --wsl, --dev WSL/Development-Modus (überspringt alle systemspezifischen Schritte)"
|
||||
echo " --help, -h Zeige diese Hilfe"
|
||||
exit 0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# =========================== GLOBALE KONFIGURATION ===========================
|
||||
readonly APP_NAME="MYP Druckerverwaltung"
|
||||
readonly APP_VERSION="4.1.0"
|
||||
@@ -1839,32 +1875,85 @@ FLASK_ENV=production
|
||||
EOF
|
||||
|
||||
# Bash-Profile für alle User aktualisieren (robust)
|
||||
if [ "$SKIP_BASH_PROFILE" = true ]; then
|
||||
log "⏭️ Bash-Profile Update übersprungen (--skip-bash-profile oder --wsl/--dev)"
|
||||
return
|
||||
fi
|
||||
|
||||
progress "Aktualisiere Bash-Profile..."
|
||||
local profile_updated=0
|
||||
|
||||
for user_home in "/root" "/home/"*; do
|
||||
if [ -d "$user_home" ] && [ "$user_home" != "/home/lost+found" ] && [ -w "$user_home" ]; then
|
||||
if ! grep -q "MYP Application Environment" "$user_home/.bashrc" 2>/dev/null; then
|
||||
cat >> "$user_home/.bashrc" << 'EOF'
|
||||
# WSL-Erkennung
|
||||
local is_wsl=false
|
||||
if grep -qEi "(Microsoft|WSL)" /proc/version 2>/dev/null || [ -n "${WSL_DISTRO_NAME:-}" ]; then
|
||||
is_wsl=true
|
||||
debug "WSL-Umgebung erkannt - verwende angepasste Bash-Profile-Logik"
|
||||
fi
|
||||
|
||||
# Definiere die zu prüfenden Verzeichnisse basierend auf der Umgebung
|
||||
local home_dirs=()
|
||||
if [ "$is_wsl" = true ]; then
|
||||
# In WSL nur das aktuelle Benutzerverzeichnis verwenden
|
||||
if [ -n "${HOME:-}" ] && [ -d "$HOME" ]; then
|
||||
home_dirs=("$HOME")
|
||||
fi
|
||||
# Füge /root nur hinzu wenn wir als root laufen
|
||||
if [ "$(id -u)" = "0" ] && [ -d "/root" ] && [ -w "/root" ]; then
|
||||
home_dirs+=("/root")
|
||||
fi
|
||||
else
|
||||
# Standard-Verhalten für echtes Linux
|
||||
home_dirs=("/root")
|
||||
# Füge alle Home-Verzeichnisse hinzu, aber mit Timeout
|
||||
while IFS= read -r -d '' user_home; do
|
||||
if [ "$user_home" != "/home/lost+found" ]; then
|
||||
home_dirs+=("$user_home")
|
||||
fi
|
||||
done < <(find /home -maxdepth 1 -type d -print0 2>/dev/null | head -20)
|
||||
fi
|
||||
|
||||
# Aktualisiere Bash-Profile mit Timeout
|
||||
for user_home in "${home_dirs[@]}"; do
|
||||
if [ -d "$user_home" ] && [ -w "$user_home" ]; then
|
||||
# Prüfe ob .bashrc existiert und lesbar ist
|
||||
if [ -f "$user_home/.bashrc" ] && [ -r "$user_home/.bashrc" ]; then
|
||||
# Verwende timeout um hängende Operationen zu vermeiden
|
||||
if timeout 5s grep -q "MYP Application Environment" "$user_home/.bashrc" 2>/dev/null; then
|
||||
debug "Bash-Profile bereits konfiguriert: $user_home/.bashrc"
|
||||
else
|
||||
# Schreibe mit timeout und prüfe Erfolg
|
||||
if timeout 5s bash -c "cat >> '$user_home/.bashrc' << 'EOF'
|
||||
|
||||
# MYP Application Environment
|
||||
if [ -d "/opt/myp" ]; then
|
||||
export MYP_APP_DIR="/opt/myp"
|
||||
export FLASK_APP="/opt/myp/app.py"
|
||||
export FLASK_ENV="production"
|
||||
if [ -z "${PYTHONPATH:-}" ]; then
|
||||
export PYTHONPATH="/opt/myp"
|
||||
if [ -d \"/opt/myp\" ]; then
|
||||
export MYP_APP_DIR=\"/opt/myp\"
|
||||
export FLASK_APP=\"/opt/myp/app.py\"
|
||||
export FLASK_ENV=\"production\"
|
||||
if [ -z \"\${PYTHONPATH:-}\" ]; then
|
||||
export PYTHONPATH=\"/opt/myp\"
|
||||
else
|
||||
export PYTHONPATH="/opt/myp:$PYTHONPATH"
|
||||
export PYTHONPATH=\"/opt/myp:\$PYTHONPATH\"
|
||||
fi
|
||||
fi
|
||||
EOF
|
||||
((profile_updated++))
|
||||
log "✅ Bash-Profile aktualisiert: $user_home/.bashrc"
|
||||
EOF" 2>/dev/null; then
|
||||
((profile_updated++))
|
||||
log "✅ Bash-Profile aktualisiert: $user_home/.bashrc"
|
||||
else
|
||||
warning "⚠️ Konnte Bash-Profile nicht aktualisieren: $user_home/.bashrc"
|
||||
fi
|
||||
fi
|
||||
else
|
||||
debug "Überspringe nicht-existierendes/unlesbares .bashrc: $user_home/.bashrc"
|
||||
fi
|
||||
else
|
||||
debug "Überspringe nicht-schreibbares Verzeichnis: $user_home"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $profile_updated -eq 0 ] && [ "$is_wsl" = false ]; then
|
||||
warning "⚠️ Keine Bash-Profile wurden aktualisiert"
|
||||
fi
|
||||
|
||||
# Validiere Deployment
|
||||
progress "Validiere Application Deployment..."
|
||||
local validation_errors=0
|
||||
|
Reference in New Issue
Block a user