2020-07-20 18:05:49 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# Demo git-annex external backend program.
|
|
|
|
#
|
|
|
|
# Install in PATH as git-annex-backend-XFOO
|
|
|
|
#
|
|
|
|
# Copyright 2020 Joey Hess; licenced under the GNU GPL version 3 or higher.
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2020-07-29 19:23:18 +00:00
|
|
|
hashfile () {
|
2020-07-20 18:05:49 +00:00
|
|
|
local contentfile="$1"
|
|
|
|
# could send PROGRESS while doing this, but it's
|
|
|
|
# hard to implement that in shell
|
2020-07-29 20:35:14 +00:00
|
|
|
md5sum "$contentfile" | cut -d ' ' -f 1 || echo ''
|
2020-07-20 18:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while read line; do
|
|
|
|
set -- $line
|
|
|
|
case "$1" in
|
|
|
|
GETVERSION)
|
|
|
|
echo VERSION 1
|
|
|
|
;;
|
|
|
|
CANVERIFY)
|
|
|
|
echo CANVERIFY-YES
|
|
|
|
;;
|
|
|
|
ISSTABLE)
|
|
|
|
echo ISSTABLE-YES
|
|
|
|
;;
|
|
|
|
ISCRYPTOGRAPHICALLYSECURE)
|
|
|
|
# md5 is not cryptographically secure
|
|
|
|
echo ISCRYPTOGRAPHICALLYSECURE-NO
|
|
|
|
;;
|
|
|
|
GENKEY)
|
|
|
|
contentfile="$2"
|
|
|
|
hash=$(hashfile "$contentfile")
|
2020-07-20 23:56:47 +00:00
|
|
|
sz=$(wc -c "$contentfile" | cut -d ' ' -f 1)
|
2020-07-20 18:05:49 +00:00
|
|
|
if [ -n "$hash" ]; then
|
2020-07-20 23:56:47 +00:00
|
|
|
echo "GENKEY-SUCCESS" "XFOO-s$sz--$hash"
|
2020-07-20 18:05:49 +00:00
|
|
|
else
|
|
|
|
echo "GENKEY-FAILURE" "md5sum failed"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
VERIFYKEYCONTENT)
|
|
|
|
key="$2"
|
|
|
|
contentfile="$3"
|
|
|
|
hash=$(hashfile "$contentfile")
|
|
|
|
khash=$(echo "$key" | sed 's/.*--//')
|
2020-07-29 20:35:14 +00:00
|
|
|
if [ "$hash" = "$khash" ]; then
|
2020-07-20 18:05:49 +00:00
|
|
|
echo "VERIFYKEYCONTENT-SUCCESS"
|
|
|
|
else
|
|
|
|
echo "VERIFYKEYCONTENT-FAILURE"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo ERROR protocol error
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|