From 1f2d99436d92511204e4ab68adc527377d437619 Mon Sep 17 00:00:00 2001 From: "tlimoncelli@stackexchange.com" Date: Fri, 24 Jul 2015 09:57:34 -0400 Subject: [PATCH] Fixed #83 blackbox_edit* scripts should accept multiple filenames --- bin/blackbox_edit | 19 +++++++++++++------ bin/blackbox_edit_end | 35 +++++++++++++++++++++++------------ bin/blackbox_edit_start | 4 ++++ 3 files changed, 40 insertions(+), 18 deletions(-) diff --git a/bin/blackbox_edit b/bin/blackbox_edit index 0861d73..ff67ce9 100755 --- a/bin/blackbox_edit +++ b/bin/blackbox_edit @@ -7,20 +7,27 @@ set -e source "${0%/*}/_blackbox_common.sh" for param in "$@" ; do + unencrypted_file=$(get_unencrypted_filename "$param") - if ! is_on_cryptlist "$param" && ! is_on_cryptlist "$unencrypted_file" ; then + encrypted_file=$(get_encrypted_filename "$param") + + echo >&2 ========== PLAINFILE '"'$unencrypted_file'"' + echo >&2 ========== ENCRYPTED '"'$encrypted_file'"' + + if ! is_on_cryptlist "$encrypted_file" && ! is_on_cryptlist "$unencrypted_file" ; then read -r -p "Encrypt file $param? (y/n) " ans case "$ans" in y* | Y*) - "${BLACKBOX_HOME}/blackbox_register_new_file" "$param" + "${BLACKBOX_HOME}/blackbox_register_new_file" "$unencrypted_file" ;; *) - echo 'Skipping...' + echo >&2 'Skipping...' continue ;; esac fi - "${BLACKBOX_HOME}/blackbox_edit_start" "$param" - "$EDITOR" "$(get_unencrypted_filename "$param")" - "${BLACKBOX_HOME}/blackbox_edit_end" "$param" + "${BLACKBOX_HOME}/blackbox_edit_start" "$unencrypted_file" + "$EDITOR" "$(get_unencrypted_filename "$unencrypted_file")" + "${BLACKBOX_HOME}/blackbox_edit_end" "$unencrypted_file" + done diff --git a/bin/blackbox_edit_end b/bin/blackbox_edit_end index 80c1891..618d13a 100755 --- a/bin/blackbox_edit_end +++ b/bin/blackbox_edit_end @@ -7,18 +7,29 @@ set -e source "${0%/*}/_blackbox_common.sh" -unencrypted_file=$(get_unencrypted_filename "$1") -encrypted_file=$(get_encrypted_filename "$1") -echo ========== PLAINFILE '"'$unencrypted_file'"' -echo ========== ENCRYPTED '"'$encrypted_file'"' +next_steps=() -fail_if_not_on_cryptlist "$unencrypted_file" -fail_if_not_exists "$unencrypted_file" "No unencrypted version to encrypt!" -fail_if_keychain_has_secrets +for param in "$@" ; do -encrypt_file "$unencrypted_file" "$encrypted_file" -shred_file "$unencrypted_file" + unencrypted_file=$(get_unencrypted_filename "$param") + encrypted_file=$(get_encrypted_filename "$param") -echo ========== UPDATED '"'$encrypted_file'"' -echo "Likely next step:" -echo " $VCS_TYPE commit -m\"${encrypted_file} updated\" \"$encrypted_file\"" + echo >&2 ========== PLAINFILE '"'$unencrypted_file'"' + echo >&2 ========== ENCRYPTED '"'$encrypted_file'"' + + fail_if_not_on_cryptlist "$unencrypted_file" + fail_if_not_exists "$unencrypted_file" "No unencrypted version to encrypt!" + fail_if_keychain_has_secrets + + encrypt_file "$unencrypted_file" "$encrypted_file" + shred_file "$unencrypted_file" + echo >&2 ========== UPDATED '"'$encrypted_file'"' + next_steps+=( " $VCS_TYPE commit -m\"${encrypted_file} updated\" \"$encrypted_file\"" ) + +done + +echo >&2 "Likely next step:" +for x in "${next_steps[@]}" +do + echo >&2 "$x" +done diff --git a/bin/blackbox_edit_start b/bin/blackbox_edit_start index 7122c77..79df67f 100755 --- a/bin/blackbox_edit_start +++ b/bin/blackbox_edit_start @@ -8,8 +8,10 @@ set -e source "${0%/*}/_blackbox_common.sh" for param in "$@" ; do + unencrypted_file=$(get_unencrypted_filename "$param") encrypted_file=$(get_encrypted_filename "$param") + echo >&2 ========== PLAINFILE '"'$unencrypted_file'"' fail_if_not_on_cryptlist "$unencrypted_file" @@ -23,5 +25,7 @@ for param in "$@" ; do fi prepare_keychain + # FIXME(tlim): prepare_keychain only needs to run once, outside of the loop. decrypt_file "$encrypted_file" "$unencrypted_file" + done