]>
git.sthu.org Git - shutils.git/blob - office-gpg
2 # Copyright (c) 2013 Stefan Huber
4 # Permission is hereby granted, free of charge, to any person
5 # obtaining a copy of this software and associated documentation
6 # files (the "Software"), to deal in the Software without
7 # restriction, including without limitation the rights to use,
8 # copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 # OTHER DEALINGS IN THE SOFTWARE.
25 # Author: Stefan Huber <shuber@sthu.org>
28 # This script does a decrypt-edit-encrypt cycle with gpg and OpenOffice resp.
35 CMD
="/usr/bin/libreoffice"
36 [ -x ${CMD} ] || CMD
="/usr/bin/ooffice"
38 [ -f "$HOME/.office-gpg.cfg" ] && source "$HOME/.office-gpg.cfg"
40 if [ -z "$CRYPTID" ]; then
41 echo "No CRYPTID set in $HOME/.office-gpg.cfg"
48 echo "Usage: $CMD-gpg <gpg-file>"
53 #The corresponding gpg-file
56 if [ ! -f "$gpgfile" ]
58 echo "\`$gpgfile\` does not exist..."
60 echo "Opening \`$gpgfile\`..."
65 #Search for filename to to encrypt file to...
66 uncryptfilePost
=${gpgfile%%.gpg}
68 uncryptfile
="$i.$uncryptfilePost"
70 while [ -f "$uncryptfile" ]
73 uncryptfile
="$i.$uncryptfilePost"
77 echo "Uncrypt \`$gpgfile\` to \`$uncryptfile\`..."
81 #Decrypt file and get checksum...
82 gpg
--output "$uncryptfile" --decrypt "$gpgfile"
83 hsumpre
=`$SUMCMD "$uncryptfile" | awk '{ print $1 }'`
84 echo "Checksum is '$hsumpre'."
87 #Edit file and get checksum of altered file
89 #pid=`lsof | grep "$uncryptfile" | cut -d ' ' -f 2`
90 #echo "wait for pid: $pid"
91 #while [ -n "`ps | grep "$pid"`" ] ; do
96 hsumpost
=`$SUMCMD "$uncryptfile" | awk '{ print $1 }'`
97 echo "Checksum is '$hsumpost'."
100 #Check if file has been altered
101 if [ "$hsumpost" != "$hsumpre" ]
103 gpg
--output "$gpgfile" -r "$CRYPTID" --encrypt "$uncryptfile"
105 #Get checksum of crypted version
106 hsumcrypt
=`gpg --decrypt $gpgfile | $SUMCMD | awk '{ print $1 }'`
107 echo "Checksum of crypted file is '$hsumcrypt'"
109 if [ "$hsumpost" != "$hsumcrypt" ]
112 echo "*** WARNING ***"
113 echo "*** WARNING *** Encrypted file \`$gpgfile\` leads to different checksum."
114 echo "*** WARNING *** Not removing unencrypted file \`$uncryptfile\`."
115 echo "*** WARNING ***"
122 echo "No changes. Skip re-encrypting"
133 if [ -f "$uncryptfile" ]
136 echo "*** WARNING ***"
137 echo "*** WARNING *** Unencrypted file \`$uncryptfile\` not removed!"
138 echo "*** WARNING ***"