4 # This script does a decrypt-edit-encrypt cycle with gpg and OpenOffice.
5 # The concrete editing program (ooffice) can be set by the variable
6 # $CMD. The detection if the file has been altered is done by a hash sum
7 # algorithm which can be set by $SUMCMD.
10 # * 2008-10-18 Initial version
11 # * 2008-10-19 Introducing a CRYPTID variable
12 # Checking if crypted file has same checksum
13 # * 2010-10-23 ooffice only spawns OpenOffice and gives control back
14 # to shell. Hence, we have to wait for pid now.
19 CRYPTID
="user@example.org"
25 echo "Usage: $CMD-gpg <gpg-file>"
30 #The corresponding gpg-file
33 if [ ! -f "$gpgfile" ]
35 echo "\`$gpgfile\` does not exist..."
37 echo "Opening \`$gpgfile\`..."
42 #Search for filename to to encrypt file to...
43 uncryptfilePost
=${gpgfile%%.gpg}
45 uncryptfile
="$i.$uncryptfilePost"
47 while [ -f "$uncryptfile" ]
50 uncryptfile
="$i.$uncryptfilePost"
54 echo "Uncrypt \`$gpgfile\` to \`$uncryptfile\`..."
58 #Decrypt file and get checksum...
59 gpg
--output "$uncryptfile" --decrypt "$gpgfile"
60 hsumpre
=`$SUMCMD "$uncryptfile" | awk '{ print $1 }'`
61 echo "Checksum is '$hsumpre'."
64 #Edit file and get checksum of altered file
66 #pid=`lsof | grep "$uncryptfile" | cut -d ' ' -f 2`
67 #echo "wait for pid: $pid"
68 #while [ -n "`ps | grep "$pid"`" ] ; do
73 hsumpost
=`$SUMCMD "$uncryptfile" | awk '{ print $1 }'`
74 echo "Checksum is '$hsumpost'."
77 #Check if file has been altered
78 if [ "$hsumpost" != "$hsumpre" ]
80 gpg
--output "$gpgfile" -r "$CRYPTID" --encrypt "$uncryptfile"
82 #Get checksum of crypted version
83 hsumcrypt
=`gpg --decrypt $gpgfile | $SUMCMD | awk '{ print $1 }'`
84 echo "Checksum of crypted file is '$hsumcrypt'"
86 if [ "$hsumpost" != "$hsumcrypt" ]
89 echo "*** WARNING ***"
90 echo "*** WARNING *** Encrypted file \`$gpgfile\` leads to different checksum."
91 echo "*** WARNING *** Not removing unencrypted file \`$uncryptfile\`."
92 echo "*** WARNING ***"
99 echo "No changes. Skip re-encrypting"
110 if [ -f "$uncryptfile" ]
113 echo "*** WARNING ***"
114 echo "*** WARNING *** Unencrypted file \`$uncryptfile\` not removed!"
115 echo "*** WARNING ***"