2014-08-13 15:16:35 -04:00
|
|
|
#!/usr/bin/env bash
|
2014-07-07 20:30:16 -04:00
|
|
|
|
|
|
|
|
#
|
2014-10-02 17:03:49 -07:00
|
|
|
# blackbox_update_all_files -- Re-encrypt file after edits.
|
2014-07-07 20:30:16 -04:00
|
|
|
#
|
|
|
|
|
|
2014-09-08 20:25:38 +00:00
|
|
|
set -e
|
2015-01-13 14:42:58 -05:00
|
|
|
blackbox_home=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
|
|
|
|
|
source ${blackbox_home}/_blackbox_common.sh
|
2014-07-07 20:30:16 -04:00
|
|
|
|
|
|
|
|
if [[ -z $GPG_AGENT_INFO ]]; then
|
|
|
|
|
echo 'WARNING: You probably want to run gpg-agent as'
|
|
|
|
|
echo 'you will be asked for your passphrase many times.'
|
|
|
|
|
echo 'Example: $ eval $(gpg-agent --daemon)'
|
2014-11-05 16:48:10 +00:00
|
|
|
read -r -p 'Press CTRL-C now to stop. ENTER to continue: '
|
2014-07-07 20:30:16 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
disclose_admins
|
2014-09-25 15:35:45 -05:00
|
|
|
prepare_keychain
|
2014-07-07 20:30:16 -04:00
|
|
|
|
|
|
|
|
echo '========== ENCRYPTED FILES TO BE RE-ENCRYPTED:'
|
|
|
|
|
awk <"$BB_FILES" '{ print " " $1 ".gpg" }'
|
|
|
|
|
|
|
|
|
|
echo '========== FILES IN THE WAY:'
|
|
|
|
|
need_warning=false
|
2015-02-10 18:54:47 -05:00
|
|
|
for i in $(<"$BB_FILES") ; do
|
2014-07-07 20:30:16 -04:00
|
|
|
unencrypted_file=$(get_unencrypted_filename "$i")
|
|
|
|
|
encrypted_file=$(get_encrypted_filename "$i")
|
|
|
|
|
if [[ -f "$unencrypted_file" ]]; then
|
|
|
|
|
need_warning=true
|
|
|
|
|
echo " $unencrypted_file"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
if $need_warning ; then
|
|
|
|
|
echo
|
|
|
|
|
echo 'WARNING: This will overwrite any unencrypted files laying about.'
|
2014-11-05 16:48:10 +00:00
|
|
|
read -r -p 'Press CTRL-C now to stop. ENTER to continue: '
|
2014-07-07 20:30:16 -04:00
|
|
|
else
|
|
|
|
|
echo 'All OK.'
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo '========== RE-ENCRYPTING FILES:'
|
2015-02-10 18:54:47 -05:00
|
|
|
for i in $(<"$BB_FILES") ; do
|
2014-07-07 20:30:16 -04:00
|
|
|
unencrypted_file=$(get_unencrypted_filename "$i")
|
|
|
|
|
encrypted_file=$(get_encrypted_filename "$i")
|
|
|
|
|
echo ========== PROCESSING "$unencrypted_file"
|
|
|
|
|
fail_if_not_on_cryptlist "$unencrypted_file"
|
|
|
|
|
decrypt_file_overwrite "$encrypted_file" "$unencrypted_file"
|
|
|
|
|
encrypt_file "$unencrypted_file" "$encrypted_file"
|
|
|
|
|
shred_file "$unencrypted_file"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
fail_if_keychain_has_secrets
|
|
|
|
|
|
2014-08-29 20:28:08 +00:00
|
|
|
echo '========== COMMITING TO VCS:'
|
2015-02-10 18:54:47 -05:00
|
|
|
vcs_commit 'Re-encrypted keys' $(awk <"$BB_FILES" '{ print $1 ".gpg" }' )
|
2014-07-07 20:30:16 -04:00
|
|
|
|
2014-08-29 20:21:02 +00:00
|
|
|
VCSCMD=$(which_vcs)
|
2014-07-07 20:30:16 -04:00
|
|
|
echo '========== DONE.'
|
|
|
|
|
echo 'Likely next step:'
|
2014-08-28 20:47:32 +00:00
|
|
|
echo " ${VCSCMD} push"
|