Photolog

Through the Looking-Glass
2010-10-12: Through the Looking-Glass
My radio speaks is binary!
2010-10-10: My radio speaks is binary!
Gigaminx: (present for my birthday)
2010-09-16: Gigaminx: (present for my birthday)
Trini on bike
2010-09-05: Trini on bike
Valporquero
2010-08-28: Valporquero
My new bike!
2010-08-22: My new bike!
Mario and Ana's wedding
2010-08-13: Mario and Ana's wedding
Canyoning in Guara
2010-08-07: Canyoning in Guara
Trini and Mari in Marbella
2010-08-05: Trini and Mari in Marbella
Trini and Chelo in Tabarca
2010-08-03: Trini and Chelo in Tabarca
Valid XHTML 1.1
Log in
Back
#!/bin/bash
#
# Copyright (C) 2010, 2011 Juan Cespedes <cespedes@thehackers.org>

FILE="$1"

if [ ! "$FILE" ]
then
  echo "Usage: $0 <file>" 1>&2
  exit 1
fi

TEMPFILE=$( tempfile 2>/dev/null || mktemp /tmp/file.XXXXXX )

sleep .2
echo -n "Please enter passphrase: " 1>&2
stty -echo
read pass </dev/tty
stty echo
echo 1>&2

if [ -f "$FILE" ]
then
  gpg --passphrase-fd 0 --output - $FILE > $TEMPFILE << EOF
$pass
EOF
  if [ "$?" != "0" ]
  then
    rm -f $TEMPFILE
    exit 1
  fi
  MD5=$( md5sum $TEMPFILE 2>/dev/null || md5 $TEMPFILE )
else
  MD5=foo
fi

${VISUAL:-${EDITOR:-vi}} $TEMPFILE

MD5NEW=$( md5sum $TEMPFILE 2>/dev/null || md5 $TEMPFILE )

if [ "$?" = "0" -a "$MD5" != "$MD5NEW" ]
then
  gpg --passphrase-fd 0 --symmetric --output - $TEMPFILE > $FILE <<EOF
$pass
EOF
fi

rm -f $TEMPFILE