2014-08-29 20:21:02 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-07-07 20:30:16 -04:00
|
|
|
|
|
|
|
|
#
|
2015-06-02 15:37:06 +00:00
|
|
|
# blackbox_edit_start -- Decrypt a file for editing.
|
2014-07-07 20:30:16 -04:00
|
|
|
#
|
|
|
|
|
|
2014-09-08 20:25:38 +00:00
|
|
|
set -e
|
2015-06-16 13:21:51 -05:00
|
|
|
source "${0%/*}/_blackbox_common.sh"
|
2014-07-07 20:30:16 -04:00
|
|
|
|
2016-12-12 14:07:33 +00:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
|
echo >&2 "Please provide at least one file to start editing"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2015-06-12 13:27:42 -05:00
|
|
|
for param in "$@" ; do
|
2015-07-24 09:57:34 -04:00
|
|
|
|
2014-07-07 20:30:16 -04:00
|
|
|
unencrypted_file=$(get_unencrypted_filename "$param")
|
|
|
|
|
encrypted_file=$(get_encrypted_filename "$param")
|
2015-07-24 09:57:34 -04:00
|
|
|
|
2015-05-14 09:36:13 -07:00
|
|
|
echo >&2 ========== PLAINFILE '"'$unencrypted_file'"'
|
2014-07-07 20:30:16 -04:00
|
|
|
|
|
|
|
|
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
|
2015-05-14 09:36:13 -07:00
|
|
|
echo >&2 SKIPPING: "$1" "Will not overwrite non-empty files."
|
2014-07-07 20:30:16 -04:00
|
|
|
continue
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
prepare_keychain
|
2015-07-24 09:57:34 -04:00
|
|
|
# FIXME(tlim): prepare_keychain only needs to run once, outside of the loop.
|
2014-07-07 20:30:16 -04:00
|
|
|
decrypt_file "$encrypted_file" "$unencrypted_file"
|
2015-07-24 09:57:34 -04:00
|
|
|
|
2014-07-07 20:30:16 -04:00
|
|
|
done
|