diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2013-10-18 17:03:40 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2013-10-18 17:03:40 -0300 |
commit | 72f6db37961e30117818c1d030a7c69869928028 (patch) | |
tree | 713c32a61aaf3961cf842f113e8ecd711e10f555 /lib/keyringer/actions/recrypt | |
parent | d402c7b9acd03c9bf8cb4ac9fc4581839cc540b0 (diff) | |
download | keyringer-72f6db37961e30117818c1d030a7c69869928028.tar.gz keyringer-72f6db37961e30117818c1d030a7c69869928028.tar.bz2 |
FHS compliance (closes #18)
Diffstat (limited to 'lib/keyringer/actions/recrypt')
-rwxr-xr-x | lib/keyringer/actions/recrypt | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/keyringer/actions/recrypt b/lib/keyringer/actions/recrypt new file mode 100755 index 0000000..014fef7 --- /dev/null +++ b/lib/keyringer/actions/recrypt @@ -0,0 +1,45 @@ +#!/bin/bash +# +# Re-encrypt files to multiple recipients. +# + +# Load functions +LIB="`dirname $0`/../functions" +source "$LIB" || exit 1 + +function keyringer_recrypt { + # Get file + keyringer_get_file "$1" + + # Set recipients file + keyringer_set_recipients "$FILE" + + # Decrypt + decrypted="$($GPG --use-agent -d "$KEYDIR/$FILE" 2> /dev/null)" + + if [ "$?" != "0" ]; then + echo "Decryption error." + exit 1 + fi + + # Recrypt + recrypted="`echo "$decrypted" | $GPG --use-agent --armor -e -s $(keyringer_recipients "$RECIPIENTS_FILE")`" + + if [ "$?" != "0" ]; then + echo "Recryption error." + exit 1 + fi + + unset decrypted + echo "$recrypted" > "$KEYDIR/$FILE" +} + +if [ ! -z "$2" ]; then + keyringer_recrypt $2 +else + cd $KEYDIR && find | while read file; do + if [ ! -d "$KEYDIR/$file" ]; then + keyringer_recrypt "$file" + fi + done +fi |