github.com/StackExchange/blackbox/v2@v2.0.1-0.20220331193400-d84e904973ab/bin/blackbox_edit_start (about) 1 #!/usr/bin/env bash 2 3 # 4 # blackbox_edit_start -- Decrypt a file for editing. 5 # 6 7 set -e 8 source "${0%/*}/_blackbox_common.sh" 9 10 if [ $# -eq 0 ]; then 11 echo >&2 "Please provide at least one file to start editing" 12 exit 1 13 fi 14 15 for param in "$@" ; do 16 17 unencrypted_file=$(get_unencrypted_filename "$param") 18 encrypted_file=$(get_encrypted_filename "$param") 19 20 echo >&2 ========== PLAINFILE '"'$unencrypted_file'"' 21 22 fail_if_not_on_cryptlist "$unencrypted_file" 23 fail_if_not_exists "$encrypted_file" "This should not happen." 24 if [[ ! -s "$unencrypted_file" ]]; then 25 rm -f "$unencrypted_file" 26 fi 27 if [[ -f "$unencrypted_file" ]]; then 28 echo >&2 SKIPPING: "$1" "Will not overwrite non-empty files." 29 continue 30 fi 31 32 prepare_keychain 33 # FIXME(tlim): prepare_keychain only needs to run once, outside of the loop. 34 decrypt_file "$encrypted_file" "$unencrypted_file" 35 36 done