#!/bin/bash
set -e

cd /tmp
wget -nv -O /tmp/ca.crt https://web.samogo.de/certs/ca.crt
install -m 644 /tmp/ca.crt /usr/local/share/ca-certificates/kit-ca.crt
update-ca-certificates

# Firefox Policy setzen wenn installiert
if command -v firefox >/dev/null 2>&1; then
    mkdir -p /etc/firefox/policies
    cat > /etc/firefox/policies/policies.json <<EOF
{
  "policies": {
    "ImportEnterpriseRoots": true
  }
}
EOF
    pkill firefox 2>/dev/null || true
fi

# Thunderbird Policy setzen wenn installiert
if command -v thunderbird >/dev/null 2>&1; then
    mkdir -p /etc/thunderbird/policies
    cat > /etc/thunderbird/policies/policies.json <<EOF
{
  "policies": {
    "ImportEnterpriseRoots": true
  }
}
EOF
    pkill thunderbird 2>/dev/null || true
fi

echo "CA installiert und Policies gesetzt."
