Skip to content

Instantly share code, notes, and snippets.

@rklaehn
Last active July 23, 2019 19:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rklaehn/306e3ede1a4a7981238c79103a9dbde9 to your computer and use it in GitHub Desktop.
Save rklaehn/306e3ede1a4a7981238c79103a9dbde9 to your computer and use it in GitHub Desktop.
Publishing to ipfs/ipns by key
#!/bin/bash
if [ "$#" -ne 3 ]; then
echo "usage:"
echo " ipfs-publish-remote.sh <keyname> <dir> <host>"
echo " example: ipfs-publish-remote.sh keyname output/rootdir user@ipfs.company.net"
exit 1
fi
KEYNAME=$1
DIR=$2
HOST=$3
if [ ! -d "$DIR" ]; then
echo "$DIR is not a directory"
exit 2
fi
TESTCMD="ssh -q $HOST exit"
if ! $TESTCMD ; then
echo "$HOST is not a valid host or not reachable"
exit 3
fi
tar -cjvf - -C $DIR . | ssh -t $HOST ipfs-publish.sh $KEYNAME --
#!/bin/bash
if [ "$#" -ne 2 ]; then
echo "usage:"
echo " ipfs-publish.sh <keyname> <dir>"
echo " ipfs-publish.sh <keyname> -- (read .tar.bzip2 archive from stdin)"
echo " example: tar -cjvf - dist | ./ipfs-publish.sh key --"
exit 1
fi
KEYNAME=$1
DIR=$2
echo "ipfs-publish.sh $KEYNAME $DIR"
if [ "$DIR" = "--" ]; then
echo "archive from stdin"
TMPDIR=$(mktemp -d)
cd "$TMPDIR"
if ! tar -xjvf /dev/stdin ; then
echo "unable to decompress archive from stdin in gzip format"
exit 5
fi
trap "{ rm -rf $TMPDIR; }" EXIT
DIR="$TMPDIR"
fi
if [ -d "$DIR" ]; then
echo "adding directory to ipfs recursively. please be patient..."
CMD="ipfs add -r -Q $DIR"
if ! HASH=`$CMD`; then
echo "error executing $CMD. Is the daemon running?"
exit 3
fi
echo "completed. Hash is $HASH"
TTL=100000h
CMD="ipfs name publish --lifetime=$TTL --key=$KEYNAME --ttl=$TTL $HASH"
if ! $CMD ; then
echo "error executing $CMD. Does the key exist?"
exit 4
fi
else
echo "$DIR is not a directory"
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment