From 7b6255b4e6604b687da33407a691b1e08b569056 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Thu, 5 Mar 2015 12:08:50 -0400 Subject: experimental ipfs special remote, with addurl support --- doc/special_remotes.mdwn | 1 + doc/special_remotes/external/git-annex-remote-ipfs | 125 +++++++++++++++++++++ doc/special_remotes/ipfs.mdwn | 86 ++++++++++++++ 3 files changed, 212 insertions(+) create mode 100755 doc/special_remotes/external/git-annex-remote-ipfs create mode 100644 doc/special_remotes/ipfs.mdwn (limited to 'doc') diff --git a/doc/special_remotes.mdwn b/doc/special_remotes.mdwn index e6c1e6da5..079e9d576 100644 --- a/doc/special_remotes.mdwn +++ b/doc/special_remotes.mdwn @@ -42,6 +42,7 @@ for using git-annex with various services: * [chef-vault](https://github.com/3ofcoins/knife-annex/) * [hubiC](https://github.com/Schnouki/git-annex-remote-hubic) * [pCloud](https://github.com/tochev/git-annex-remote-pcloud) +* [[ipfs]] Want to add support for something else? [[Write your own!|external]] diff --git a/doc/special_remotes/external/git-annex-remote-ipfs b/doc/special_remotes/external/git-annex-remote-ipfs new file mode 100755 index 000000000..fc91aefc8 --- /dev/null +++ b/doc/special_remotes/external/git-annex-remote-ipfs @@ -0,0 +1,125 @@ +#!/bin/sh +# This is a git-annex external special remote program, +# which adds experimental ipfs support to git-annex. +# +# Install in PATH as git-annex-remote-ipfs +# +# Copyright 2015 Joey Hess; licenced under the GNU GPL version 3 or higher. + +set -e + +# use ipfs: as a prefix to indicate when an "url" is really stored in ipfs +isipfsurl () { + echo "$1" | egrep -q "^ipfs:" +} + +# convert an ipfs: url to an address that the ipfs client understands +urltoaddress () { + echo "$1" | sed -e 's/^ipfs://' +} + +addresstourl () { + echo "ipfs:$1" +} + +# Gets a VALUE response and stores it in $RET +getvalue () { + read resp + # Tricky POSIX shell code to split first word of the resp, + # preserving all other whitespace + case "${resp%% *}" in + VALUE) + RET="$(echo "$resp" | sed 's/^VALUE \?//')" + ;; + *) + RET="" + ;; + esac +} + +# Get a list of all known ipfs addresses for a key, +# storing it in a temp file. +getaddrs () { + key="$1" + tmp="$2" + + echo GETURLS "$key" + getvalue + while [ -n "$RET" ]; do + if isipfsurl "$RET"; then + echo "$RET" >> "$tmp" + fi + getvalue + done +} + +# This has to come first, to get the protocol started. +echo VERSION 1 + +while read line; do + set -- $line + case "$1" in + INITREMOTE) + echo INITREMOTE-SUCCESS + ;; + PREPARE) + echo PREPARE-SUCCESS + ;; + CLAIMURL) + url="$2" + if isipfsurl "$url"; then + echo CLAIMURL-SUCCESS + else + echo CLAIMURL-FAILURE + fi + ;; + CHECKURL) + url="$2" + # TODO if size of file can be quickly determined + # (without downloading it) return the size + # instead of UNKNOWN + echo CHECKURL-CONTENTS UNKNOWN "$(urltoaddress "$url")" + ;; + TRANSFER) + key="$3" + file="$4" + case "$2" in + STORE) + addr=$(ipfs add -q "$file" &2