Files
blackbox/bin/blackbox_edit_start
Ben Watson 818db98506 Requiring a file to be entered to finish editing (#175)
* Requiring a file to be entered to finish editing

Running blackbox_edit_end without an argument doesn't currently print out a warning that no files are being changed. A developer in my team who was new to Blackbox committed a decrypted file (and made no changes to the GPG file) as they didn't realise the command hadn't worked.

The check I've added should help to avoid these errors.

* Adding argument check to start editing
2016-12-12 14:07:33 +00:00

37 lines
883 B
Bash
Executable File

#!/usr/bin/env bash
#
# blackbox_edit_start -- Decrypt a file for editing.
#
set -e
source "${0%/*}/_blackbox_common.sh"
if [ $# -eq 0 ]; then
echo >&2 "Please provide at least one file to start editing"
exit 1
fi
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"
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 >&2 SKIPPING: "$1" "Will not overwrite non-empty files."
continue
fi
prepare_keychain
# FIXME(tlim): prepare_keychain only needs to run once, outside of the loop.
decrypt_file "$encrypted_file" "$unencrypted_file"
done