2014-08-29 20:21:02 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-07-07 20:30:16 -04:00
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# blackbox_register_new_file.sh -- Enroll a new file in the blackbox system.
|
|
|
|
|
#
|
2014-08-28 20:47:32 +00:00
|
|
|
# Takes a previously unencrypted file and enrolls it into the blackbox
|
|
|
|
|
# system. It 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-10-13 21:31:58 +02:00
|
|
|
# TODO(tlim): Add the unencrypted file to .hgignore
|
2014-08-29 20:21:02 +00:00
|
|
|
|
2014-09-08 20:25:38 +00:00
|
|
|
set -e
|
2014-08-28 20:47:32 +00:00
|
|
|
. _blackbox_common.sh
|
2014-10-13 21:31:58 +02:00
|
|
|
_determine_vcs_base_and_type
|
2014-07-07 20:30:16 -04:00
|
|
|
|
|
|
|
|
unencrypted_file=$(get_unencrypted_filename "$1")
|
|
|
|
|
encrypted_file=$(get_encrypted_filename "$1")
|
|
|
|
|
|
|
|
|
|
if [[ $1 == $encrypted_file ]]; then
|
|
|
|
|
echo ERROR: Please only register unencrypted files.
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo ========== PLAINFILE "$unencrypted_file"
|
|
|
|
|
echo ========== ENCRYPTED "$encrypted_file"
|
|
|
|
|
|
|
|
|
|
fail_if_not_exists "$unencrypted_file" "Please specify an existing file."
|
|
|
|
|
fail_if_exists "$encrypted_file" "Will not overwrite."
|
|
|
|
|
|
|
|
|
|
prepare_keychain
|
|
|
|
|
encrypt_file "$unencrypted_file" "$encrypted_file"
|
|
|
|
|
add_filename_to_cryptlist "$unencrypted_file"
|
|
|
|
|
|
|
|
|
|
# Is the unencrypted file already in HG? (ie. are we correcting a bad situation)
|
2014-08-13 15:16:35 -04:00
|
|
|
SECRETSEXPOSED=$(is_in_vcs ${unencrypted_file})
|
2014-07-07 20:30:16 -04:00
|
|
|
echo "========== CREATED: ${encrypted_file}"
|
2014-08-13 15:16:35 -04:00
|
|
|
echo "========== UPDATING REPO:"
|
2014-07-07 20:30:16 -04:00
|
|
|
shred_file "$unencrypted_file"
|
2014-08-13 15:16:35 -04:00
|
|
|
|
|
|
|
|
VCSCMD=$(which_vcs)
|
2014-07-07 20:30:16 -04:00
|
|
|
if $SECRETSEXPOSED ; then
|
2014-08-29 20:21:02 +00:00
|
|
|
vcs_remove "$unencrypted_file"
|
|
|
|
|
vcs_add "$encrypted_file"
|
2014-07-07 20:30:16 -04:00
|
|
|
COMMIT_FILES="$BB_FILES $encrypted_file $unencrypted_file"
|
|
|
|
|
else
|
|
|
|
|
COMMIT_FILES="$BB_FILES $encrypted_file"
|
|
|
|
|
fi
|
2014-10-13 21:31:58 +02:00
|
|
|
|
2014-10-14 14:26:24 +00:00
|
|
|
# TODO(tlim): This should be moved to _blackbox_common.sh in a
|
|
|
|
|
# VCS-independent way.
|
2014-10-13 21:31:58 +02:00
|
|
|
IGNOREFILE=".${VCS_TYPE}ignore"
|
|
|
|
|
if [[ $VCS_TYPE = 'git' ]]; then
|
2014-10-14 14:23:34 +00:00
|
|
|
ignored_file="$(echo "$unencrypted_file" | sed 's/^\([!#]\)/\\\1/')"
|
|
|
|
|
if ! grep -Fsx >/dev/null "$ignored_file" "$IGNOREFILE"; then
|
|
|
|
|
echo "$ignored_file" >>"$IGNOREFILE"
|
|
|
|
|
COMMIT_FILES="$COMMIT_FILES $IGNOREFILE"
|
|
|
|
|
fi
|
|
|
|
|
vcs_add "$IGNOREFILE"
|
2014-10-13 21:31:58 +02:00
|
|
|
fi
|
|
|
|
|
|
2014-07-07 20:30:16 -04:00
|
|
|
echo 'NOTE: "already tracked!" messages are safe to ignore.'
|
2014-08-29 20:21:02 +00:00
|
|
|
vcs_add $BB_FILES $encrypted_file
|
|
|
|
|
vcs_commit "registered in blackbox: ${unencrypted_file}" $COMMIT_FILES
|
2014-08-28 20:47:32 +00:00
|
|
|
echo "========== UPDATING VCS: DONE"
|
2014-07-07 20:30:16 -04:00
|
|
|
echo "Local repo updated. Please push when ready."
|
2014-08-13 15:16:35 -04:00
|
|
|
echo " $VCSCMD push"
|