kind of more secureish vimcrypted
This commit is contained in:
@@ -7,12 +7,20 @@
|
|||||||
|
|
||||||
function helpexit() {
|
function helpexit() {
|
||||||
echo "Edit a GPG encrypted file with vim.
|
echo "Edit a GPG encrypted file with vim.
|
||||||
Unsecure implementation, since the file is saved
|
####################################################
|
||||||
IN PLAIN TEXT when editing,
|
# UNSECURE IMPLEMENTATION, since the file is saved #
|
||||||
this script only takes care of storing the file
|
# IN PLAIN TEXT when editing, #
|
||||||
encrypted
|
# this script only takes care of storing the file #
|
||||||
|
# encrypted. #
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
Modified file is always backed up as .old
|
||||||
|
|
||||||
|
Usage: $( basename $0 ) textfile.gpg
|
||||||
|
|
||||||
|
Vim additions: H to unhide all lines
|
||||||
|
h to hide lines except cursor
|
||||||
|
|
||||||
Changed file is always backed up as .old
|
|
||||||
"
|
"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
@@ -20,39 +28,38 @@ Changed file is always backed up as .old
|
|||||||
[[ "$1" = "-h" ]] && helpexit
|
[[ "$1" = "-h" ]] && helpexit
|
||||||
RM=rm
|
RM=rm
|
||||||
which shred &> /dev/null && RM="shred -u"
|
which shred &> /dev/null && RM="shred -u"
|
||||||
set -x
|
|
||||||
if [[ ! "$1" == *\.gpg ]]
|
if [[ ! "$1" == *\.gpg ]]; then
|
||||||
then
|
|
||||||
echo "source is not .gpg"
|
echo "source is not .gpg"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
unc="${1%.gpg}"
|
unc="${1%.gpg}"
|
||||||
if [ -e "$unc" ]
|
if [ -e "$unc" ]; then
|
||||||
then echo "$unc already exists. exiting"
|
echo "$unc already exists. exiting"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ ! -e "$1" ]
|
if [ ! -e "$1" ]; then
|
||||||
then echo "File $1 does not exist. Creating empty file"
|
echo "File $1 does not exist. Creating empty file"
|
||||||
echo " " > "$unc"
|
echo " " > "$unc"
|
||||||
else
|
else
|
||||||
gpg --decrypt "$1" > "$unc"
|
gpg --decrypt "$1" > "$unc"
|
||||||
fi
|
fi
|
||||||
LIB=$( dirname $( readlink -f $0 ) )/crypted.vim
|
LIB=$( dirname $( readlink -f $0 ) )/crypted.vim
|
||||||
edit=`date +%s -r $unc`
|
edit=`date +%s -r $unc`
|
||||||
if [ -s "$unc" ]
|
if [ -s "$unc" ]; then
|
||||||
then vim -i NONE -S "$LIB" -n "$unc"
|
vim -i NONE -S "$LIB" -n -c "call Hide()" "$unc"
|
||||||
else echo Error in decrypting
|
else
|
||||||
|
echo Error in decrypting
|
||||||
$RM "$unc"
|
$RM "$unc"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
afteredit=`date +%s -r "$unc"`
|
afteredit=`date +%s -r "$unc"`
|
||||||
|
|
||||||
if (( $edit != $afteredit ))
|
if (( $edit != $afteredit )); then
|
||||||
then
|
|
||||||
cat "$unc" | gpg -ca > "$1".tmp
|
cat "$unc" | gpg -ca > "$1".tmp
|
||||||
if [ -s "$1".tmp ]
|
if [ -s "$1".tmp ]; then
|
||||||
then [[ -e "$1" ]] && mv -f "$1" "$1".old
|
[[ -e "$1" ]] && mv -f "$1" "$1".old
|
||||||
mv -f "$1".tmp "$1"
|
mv -f "$1".tmp "$1"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user