Last active
September 26, 2018 05:39
-
-
Save kvhnuke/ea19033062f485f7ec5253ab2268af63 to your computer and use it in GitHub Desktop.
publish ipfs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GNU nano 2.5.3 File: ipfs-publish.sh | |
#!/bin/bash | |
source ~/.profile | |
if [ "$#" -ne 1 ]; then | |
echo "usage:" | |
echo " ipfs-publish.sh <dir>" | |
echo " ipfs-publish.sh -- (read .tar.bzip2 archive from stdin)" | |
echo " example: tar -cjvf - dist | ./ipfs-publish.sh --" | |
exit 1 | |
fi | |
DIR=$1 | |
echo "ipfs-publish.sh $DIR" | |
if [ "$DIR" = "--" ]; then | |
echo "archive from stdin" | |
TMPDIR=$(mktemp -d) | |
cd "$TMPDIR" | |
if ! tar -xjf /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" | |
CMD="ipfs pin add -r /ipfs/$HASH" | |
if ! $CMD ; then | |
echo "error executing $CMD." | |
exit 4 | |
fi | |
else | |
echo "$DIR is not a directory" | |
exit 2 | |
fi | |
echo "<hash>$HASH</hash>" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment