Last active
December 2, 2022 04:06
-
-
Save RichardBronosky/4ab330edc33879046cb9b984f66a8676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
declare -t _lastcmd; trap '_lastcmd="$BASH_COMMAND"' DEBUG; trap 'echo "LINE $LINENO: $_lastcmd"' EXIT; | |
# export CA PEM from Apple "Keychain Access" app and pass as ARG1 | |
new_ca_cert="$1" | |
get_python_cert_chain(){ | |
python -m certifi | |
} | |
backup_file(){ | |
original_file="$1" | |
cp -v "$original_file" "$original_file.$(date +%s)" | |
} | |
prepend_metadata_comments(){ | |
cert_file="$1" | |
( | |
openssl x509 -subject -noout -in "$cert_file" | |
) | sed $'1i\\\n\n;s/^/# /;' | |
cat "$cert_file" | |
} | |
main(){ | |
original_cert_chain="$(get_python_cert_chain)" | |
backup_file "$original_cert_chain" | |
prepend_metadata_comments "$new_ca_cert" \ | |
| tee -a "$original_cert_chain" | |
} | |
trap - EXIT | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice! :)