203 lines
6.5 KiB
Bash
203 lines
6.5 KiB
Bash
#!/bin/bash
|
|
|
|
#######################################################################
|
|
# Mercedes-Benz Corporate Zertifikate - Schnell-Installation
|
|
#
|
|
# Löst sofort Internet-Verbindungsprobleme in Corporate VMs
|
|
#######################################################################
|
|
|
|
set -euo pipefail
|
|
|
|
# Farben für Ausgabe
|
|
readonly RED='\033[0;31m'
|
|
readonly GREEN='\033[0;32m'
|
|
readonly YELLOW='\033[1;33m'
|
|
readonly BLUE='\033[0;34m'
|
|
readonly NC='\033[0m'
|
|
|
|
log() {
|
|
local level="$1"
|
|
shift
|
|
local message="$*"
|
|
|
|
case "$level" in
|
|
"INFO") echo -e "${GREEN}[INFO]${NC} $message" ;;
|
|
"WARN") echo -e "${YELLOW}[WARN]${NC} $message" ;;
|
|
"ERROR") echo -e "${RED}[ERROR]${NC} $message" ;;
|
|
"DEBUG") echo -e "${BLUE}[DEBUG]${NC} $message" ;;
|
|
esac
|
|
}
|
|
|
|
# Root-Check
|
|
if [[ $EUID -ne 0 ]]; then
|
|
log "ERROR" "Script muss als root ausgeführt werden: sudo $0"
|
|
exit 1
|
|
fi
|
|
|
|
echo "🏢 Mercedes-Benz Corporate Zertifikate Installation"
|
|
echo "=================================================="
|
|
echo
|
|
|
|
# Script-Verzeichnis ermitteln
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(dirname "${SCRIPT_DIR}")"
|
|
MERCEDES_CERT_DIR="$PROJECT_ROOT/certs/mercedes"
|
|
|
|
log "INFO" "Suche Mercedes-Zertifikate in: $MERCEDES_CERT_DIR"
|
|
|
|
# Prüfe ob Zertifikate vorhanden sind
|
|
if [[ ! -d "$MERCEDES_CERT_DIR" ]]; then
|
|
log "ERROR" "Mercedes-Zertifikat-Verzeichnis nicht gefunden: $MERCEDES_CERT_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
cert_files_found=0
|
|
if [[ -f "$MERCEDES_CERT_DIR/Corp-Prj-Root-CA.cer" ]]; then
|
|
cert_files_found=$((cert_files_found + 1))
|
|
log "INFO" "✓ Corp-Prj-Root-CA.cer gefunden"
|
|
fi
|
|
|
|
if [[ -f "$MERCEDES_CERT_DIR/Corp-Root-CA-G2.cer" ]]; then
|
|
cert_files_found=$((cert_files_found + 1))
|
|
log "INFO" "✓ Corp-Root-CA-G2.cer gefunden"
|
|
fi
|
|
|
|
if [[ $cert_files_found -eq 0 ]]; then
|
|
log "ERROR" "Keine Mercedes-Zertifikate gefunden!"
|
|
exit 1
|
|
fi
|
|
|
|
log "INFO" "$cert_files_found Mercedes-Zertifikate gefunden"
|
|
echo
|
|
|
|
# System-Zertifikat-Verzeichnis erstellen
|
|
SYSTEM_CERT_DIR="/usr/local/share/ca-certificates/mercedes"
|
|
log "INFO" "Erstelle System-Zertifikat-Verzeichnis: $SYSTEM_CERT_DIR"
|
|
mkdir -p "$SYSTEM_CERT_DIR"
|
|
|
|
# Zertifikate installieren
|
|
log "INFO" "Installiere Mercedes-Zertifikate..."
|
|
|
|
if [[ -f "$MERCEDES_CERT_DIR/Corp-Prj-Root-CA.cer" ]]; then
|
|
log "INFO" "Installiere Corp-Prj-Root-CA..."
|
|
cp "$MERCEDES_CERT_DIR/Corp-Prj-Root-CA.cer" "$SYSTEM_CERT_DIR/Corp-Prj-Root-CA.crt"
|
|
chmod 644 "$SYSTEM_CERT_DIR/Corp-Prj-Root-CA.crt"
|
|
log "INFO" "✓ Corp-Prj-Root-CA installiert"
|
|
fi
|
|
|
|
if [[ -f "$MERCEDES_CERT_DIR/Corp-Root-CA-G2.cer" ]]; then
|
|
log "INFO" "Installiere Corp-Root-CA-G2..."
|
|
cp "$MERCEDES_CERT_DIR/Corp-Root-CA-G2.cer" "$SYSTEM_CERT_DIR/Corp-Root-CA-G2.crt"
|
|
chmod 644 "$SYSTEM_CERT_DIR/Corp-Root-CA-G2.crt"
|
|
log "INFO" "✓ Corp-Root-CA-G2 installiert"
|
|
fi
|
|
|
|
# CA-Zertifikat-Store aktualisieren
|
|
log "INFO" "Aktualisiere System-CA-Store..."
|
|
if update-ca-certificates --verbose; then
|
|
log "INFO" "✅ System-CA-Store erfolgreich aktualisiert"
|
|
else
|
|
log "ERROR" "❌ Fehler beim Aktualisieren des CA-Stores"
|
|
exit 1
|
|
fi
|
|
|
|
# Python-Requests konfigurieren
|
|
log "INFO" "Konfiguriere Python für Mercedes-Zertifikate..."
|
|
mkdir -p "/etc/myp"
|
|
cat > "/etc/myp/python-certs.conf" << 'EOF'
|
|
# Mercedes-Benz Python Certificate Configuration
|
|
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
|
|
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
|
|
export SSL_CERT_DIR=/etc/ssl/certs
|
|
export PYTHONHTTPSVERIFY=1
|
|
export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
|
|
EOF
|
|
|
|
# In /etc/environment einbinden
|
|
if ! grep -q "source /etc/myp/python-certs.conf" /etc/environment 2>/dev/null; then
|
|
echo "source /etc/myp/python-certs.conf" >> /etc/environment
|
|
fi
|
|
|
|
log "INFO" "✓ Python-Zertifikat-Konfiguration abgeschlossen"
|
|
|
|
# Node.js konfigurieren
|
|
log "INFO" "Konfiguriere Node.js für Mercedes-Zertifikate..."
|
|
cat > "/etc/myp/nodejs-certs.conf" << 'EOF'
|
|
# Mercedes-Benz Node.js Certificate Configuration
|
|
export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
|
|
EOF
|
|
|
|
log "INFO" "✓ Node.js-Zertifikat-Konfiguration abgeschlossen"
|
|
|
|
# Sofort in aktuelle Session laden
|
|
export REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
|
|
export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
|
|
export SSL_CERT_DIR=/etc/ssl/certs
|
|
export PYTHONHTTPSVERIFY=1
|
|
export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
|
|
export NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt
|
|
|
|
log "INFO" "✓ Zertifikat-Variablen in aktuelle Session geladen"
|
|
|
|
# Internet-Test nach Zertifikat-Installation
|
|
echo
|
|
log "INFO" "Teste Internet-Verbindung nach Zertifikat-Installation..."
|
|
|
|
test_success=false
|
|
|
|
# curl-Test
|
|
if command -v curl &>/dev/null; then
|
|
if curl -sf --connect-timeout 15 --max-time 20 "https://www.google.com" &>/dev/null; then
|
|
log "INFO" "✅ HTTPS-Verbindung zu Google erfolgreich"
|
|
test_success=true
|
|
else
|
|
log "WARN" "HTTPS-Verbindung zu Google fehlgeschlagen"
|
|
fi
|
|
fi
|
|
|
|
# wget-Test als Fallback
|
|
if [[ "$test_success" == "false" ]] && command -v wget &>/dev/null; then
|
|
if timeout 20 wget -q --spider --timeout=15 "https://www.google.com" 2>/dev/null; then
|
|
log "INFO" "✅ HTTPS-Verbindung (wget) zu Google erfolgreich"
|
|
test_success=true
|
|
fi
|
|
fi
|
|
|
|
# Python-Test
|
|
if command -v python3 &>/dev/null; then
|
|
if python3 -c "import urllib.request; urllib.request.urlopen('https://www.google.com', timeout=15)" &>/dev/null; then
|
|
log "INFO" "✅ Python HTTPS-Verbindung erfolgreich"
|
|
test_success=true
|
|
else
|
|
log "WARN" "Python HTTPS-Verbindung fehlgeschlagen"
|
|
fi
|
|
fi
|
|
|
|
# Fazit
|
|
echo
|
|
echo "🎯 INSTALLATION ABGESCHLOSSEN"
|
|
echo "=============================="
|
|
|
|
log "INFO" "Mercedes-Zertifikate erfolgreich installiert:"
|
|
log "INFO" " - $cert_files_found Zertifikate in System-CA-Store"
|
|
log "INFO" " - Python/requests konfiguriert"
|
|
log "INFO" " - Node.js konfiguriert"
|
|
log "INFO" " - Umgebungsvariablen gesetzt"
|
|
|
|
if [[ "$test_success" == "true" ]]; then
|
|
log "INFO" "✅ Internet-Verbindung funktioniert!"
|
|
echo
|
|
echo "🚀 JETZT MYP-INSTALLATION STARTEN:"
|
|
echo "sudo ./setup/aio_installer.sh --vm-mode --full"
|
|
else
|
|
log "WARN" "Internet-Verbindung noch problematisch"
|
|
echo
|
|
echo "🔄 NÄCHSTE SCHRITTE:"
|
|
echo "1. Terminal neu starten (für Umgebungsvariablen)"
|
|
echo "2. sudo ./setup/aio_installer.sh --vm-mode --full"
|
|
echo "3. oder: sudo ./setup/aio_installer.sh --skip-internet-check --full"
|
|
fi
|
|
|
|
echo
|
|
echo "📋 ZERTIFIKAT-STATUS:"
|
|
ls -la "$SYSTEM_CERT_DIR"/ 2>/dev/null || log "WARN" "Zertifikat-Verzeichnis leer" |