Skip to content

Instantly share code, notes, and snippets.

@d10r
Created March 30, 2017 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d10r/ee35731b2f2ca43014b464547cc5c100 to your computer and use it in GitHub Desktop.
Save d10r/ee35731b2f2ca43014b464547cc5c100 to your computer and use it in GitHub Desktop.
Local part of a simple ipfs replication solution. To be executed by a cronjob
#!/bin/bash
# Checks the locally pinned files against a previously persisted.
# If something changed, the updated list file is pushed to a given server (needs to be ssh accessible without password).
# Finally, the new list is persisted locally.
# Note that the local ipfs daemon needs to be running in order for the server to be able to fetch.
# The local ipfs config may be restricted to connect only to that server (add as only Bootstrap node and disable discovery).
set -e
set -u
FILE=$HOME/.ipfs/pinned.list
touch $FILE # avoid failure when run first
DEST="youruser@yourhost.yourtld"
# source: https://ipfs.io/ipns/ipfs.git.sexy/sketches/replicate_node.html
LISTCMD="ipfs pin ls -q --type=recursive | sort"
DIFFCMD="diff <(eval $LISTCMD) $FILE > /dev/null"
if ! eval $DIFFCMD; then
echo "something changed, pushing new list to server..."
eval $LISTCMD | ssh $DEST "cat > .ipfs/${HOSTNAME}.pinned.list"
# yeah, here we have a small race condition. The list may have changed in the meantime :-(
echo "updating local list file..."
eval $LISTCMD > $FILE
fi
~
~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment