Files
blackbox/bin/blackbox_update_all_files

59 lines
1.6 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2014-07-07 20:30:16 -04:00
#
# blackbox_update_all_files -- Decrypt then re-encrypt all files. Useful after keys are changed.
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
gpg_agent_notice
2014-07-07 20:30:16 -04:00
disclose_admins
prepare_keychain
2014-07-07 20:30:16 -04:00
echo '========== ENCRYPTED FILES TO BE RE-ENCRYPTED:'
while IFS= read <&99 -r unencrypted_file; do
echo " $unencrypted_file.gpg"
done 99<"$BB_FILES"
2014-07-07 20:30:16 -04:00
echo '========== FILES IN THE WAY:'
need_warning=false
while IFS= read <&99 -r unencrypted_file; do
unencrypted_file=$(get_unencrypted_filename "$unencrypted_file")
encrypted_file=$(get_encrypted_filename "$unencrypted_file")
2014-07-07 20:30:16 -04:00
if [[ -f "$unencrypted_file" ]]; then
need_warning=true
echo " $unencrypted_file"
fi
done 99<"$BB_FILES"
2015-02-27 01:01:48 +07:00
if "$need_warning" ; then
2014-07-07 20:30:16 -04:00
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:'
while IFS= read <&99 -r unencrypted_file; do
unencrypted_file=$(get_unencrypted_filename "$unencrypted_file")
encrypted_file=$(get_encrypted_filename "$unencrypted_file")
echo ========== PROCESSING '"'$unencrypted_file'"'
2014-07-07 20:30:16 -04:00
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 99<"$BB_FILES"
2014-07-07 20:30:16 -04:00
fail_if_keychain_has_secrets
2014-08-29 20:28:08 +00:00
echo '========== COMMITING TO VCS:'
while IFS= read <&99 -r unencrypted_file; do
vcs_add "$unencrypted_file.gpg"
done 99<"$BB_FILES"
vcs_commit 'Re-encrypted keys'
2014-07-07 20:30:16 -04:00
echo '========== DONE.'
echo 'Likely next step:'
echo " $VCS_TYPE push"