2024-08-13 09:20:08 +03:00
|
|
|
#!/bin/sh
|
|
|
|
set -ef
|
|
|
|
|
|
|
|
dst_dir=/usr/local/share/ca-certificates
|
|
|
|
|
|
|
|
w=$(mktemp -d) ; : "${w:?}"
|
|
|
|
w_cleanup() {
|
2024-12-04 21:17:59 +03:00
|
|
|
[ -z "$w" ] || ls -lA "$w/" >&2
|
2024-08-13 09:20:08 +03:00
|
|
|
[ -z "$w" ] || rm -rf "$w"
|
|
|
|
unset w
|
|
|
|
exit "${1:-0}"
|
|
|
|
}
|
|
|
|
|
|
|
|
def_bundle='/etc/ssl/certs/ca-certificates.crt'
|
|
|
|
|
2024-12-04 21:17:59 +03:00
|
|
|
openssl-cert-auto-pem.sh "${def_bundle}" "$w/cacert.pem" "$w/cacert.fp"
|
|
|
|
[ -s "$w/cacert.pem" ] || w_cleanup 1
|
|
|
|
[ -s "$w/cacert.fp" ] || w_cleanup 1
|
2024-08-13 09:20:08 +03:00
|
|
|
|
2024-12-04 21:17:59 +03:00
|
|
|
openssl-cert-auto-pem.sh "$1" "$w/certifi.pem" "$w/certifi.fp" "$w/certifi.off"
|
|
|
|
[ -s "$w/certifi.pem" ] || w_cleanup 1
|
|
|
|
[ -s "$w/certifi.fp" ] || w_cleanup 1
|
2024-08-13 09:20:08 +03:00
|
|
|
[ -s "$w/certifi.off" ] || w_cleanup 1
|
|
|
|
|
|
|
|
set +e
|
2024-12-04 21:17:59 +03:00
|
|
|
grep -Fxnv -f "$w/cacert.fp" "$w/certifi.fp" | cut -d : -f 1 > "$w/diff.ln"
|
2024-08-13 09:20:08 +03:00
|
|
|
set -e
|
|
|
|
|
2024-12-04 21:17:59 +03:00
|
|
|
if [ -s "$w/diff.ln" ] ; then
|
|
|
|
terse_fingerprint() { cut -d = -f 2- | tr -cd '[:alnum:]' ; }
|
2024-08-13 09:20:08 +03:00
|
|
|
|
|
|
|
while read -r n ; do
|
|
|
|
[ -n "$n" ] || continue
|
|
|
|
|
|
|
|
fp=$(sed -ne "${n}p" "$w/certifi.fp" | terse_fingerprint)
|
|
|
|
off=$(sed -ne "${n}p" "$w/certifi.off")
|
2024-12-04 21:17:59 +03:00
|
|
|
sed -ne "${off}p" "$w/certifi.pem" > "${dst_dir}/certifi-${fp}.crt"
|
|
|
|
done < "$w/diff.ln"
|
2024-08-13 09:20:08 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
rm -rf "$w" ; unset w
|
|
|
|
|
|
|
|
exec update-ca-certificates --fresh
|