Files
blackbox/bin/blackbox_register_new_file

57 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2014-07-07 20:30:16 -04:00
#
# blackbox_register_new_file -- Enroll new file(s) in the blackbox system.
2014-07-07 20:30:16 -04:00
#
# Takes previously unencrypted file(s) and enrolls them into the blackbox
# system. Each file will be kept in the repo as an encrypted file. On deployment
# to systems that need the plaintext (unencrypted) versions, run
# blackbox_postdeploy.sh to decrypt all the files.
2014-07-07 20:30:16 -04:00
2014-09-08 20:25:38 +00:00
set -e
source "${0%/*}/_blackbox_common.sh"
2014-07-07 20:30:16 -04:00
function register_new_file() {
unencrypted_file=$(get_unencrypted_filename "$1")
encrypted_file=$(get_encrypted_filename "$1")
2014-07-07 20:30:16 -04:00
if [[ "$1" == "$encrypted_file" ]]; then
echo ERROR: Please only register unencrypted files.
exit 1
fi
2014-07-07 20:30:16 -04:00
echo ========== PLAINFILE "$unencrypted_file"
echo ========== ENCRYPTED "$encrypted_file"
2014-07-07 20:30:16 -04:00
fail_if_not_exists "$unencrypted_file" "Please specify an existing file."
fail_if_exists "$encrypted_file" "Will not overwrite."
2014-07-07 20:30:16 -04:00
prepare_keychain
encrypt_file "$unencrypted_file" "$encrypted_file"
add_filename_to_cryptlist "$unencrypted_file"
2014-07-07 20:30:16 -04:00
# Is the unencrypted file already in HG? (ie. are we correcting a bad situation)
SECRETSEXPOSED=$(is_in_vcs "${unencrypted_file}")
echo "========== CREATED: ${encrypted_file}"
echo "========== UPDATING REPO:"
shred_file "$unencrypted_file"
if "$SECRETSEXPOSED" ; then
vcs_remove "$unencrypted_file"
vcs_add "$encrypted_file"
fi
vcs_ignore "$unencrypted_file"
echo 'NOTE: "already tracked!" messages are safe to ignore.'
vcs_add "$BB_FILES" "$encrypted_file"
vcs_commit "registered in blackbox: ${unencrypted_file}" "$BB_FILES" "$encrypted_file"
}
for target in "$@"; do
register_new_file "$target"
done
echo "========== UPDATING VCS: DONE"
2014-07-07 20:30:16 -04:00
echo "Local repo updated. Please push when ready."
echo " $(which_vcs) push"