diff --git a/bin/blackbox_edit b/bin/blackbox_edit new file mode 100755 index 0000000..9258e41 --- /dev/null +++ b/bin/blackbox_edit @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +# +# blackbox_edit.sh -- Decrypt a file temporarily for edition, then re-encrypts it again +# + +. _blackbox_common.sh + +for param in """$@""" ; do + unencrypted_file=$(mktemp) + encrypted_file=$(get_encrypted_filename "$param") + echo ========== PLAINFILE "$unencrypted_file" + + fail_if_not_on_cryptlist "$unencrypted_file" + fail_if_not_exists "$encrypted_file" "This should not happen." + if [[ ! -s "$unencrypted_file" ]]; then + rm -f "$unencrypted_file" + fi + if [[ -f "$unencrypted_file" ]]; then + echo SKIPPING: "$1" "Will not overwrite non-empty files." + continue + fi + + prepare_keychain + decrypt_file "$encrypted_file" "$unencrypted_file" + $EDITOR $unencrypted_file + + encrypt_file "$unencrypted_file" "$encrypted_file" + shred_file "$unencrypted_file" + + echo "========== UPDATED ${encrypted_file}" + echo "Likely next step:" + echo " git commit -m\"${encrypted_file} updated\" $encrypted_file" +done