├── LICENSE ├── README.md ├── install.sh ├── ipfs-paste └── test └── sharness ├── .gitignore ├── Makefile ├── lib └── install-sharness.sh └── t0000-sharness.sh /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Juan Batiz-Benet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ipfs-paste - paste to ipfs 2 | 3 | Paste stuff to [IPFS](http://ipfs.io). 4 | 5 | 1. `ipfs add` stdin (or clipboard with `--paste`) 6 | 2. print + copy url to the HTTP gateway 7 | 3. prefetch on the gateway 8 | 9 | (note: Today, clipboard only on {OSX, Linux}. Tomorrow, cross platform). 10 | 11 | ## Install 12 | 13 | ```sh 14 | # install from ipfs 15 | ipfs cat QmSKVENxxkS3QGkFJDofWgcPySdCHZ3sbrU5onXAzhWZdz >/usr/local/bin/ipfs-paste 16 | chmod +x /usr/local/bin/ipfs-paste 17 | 18 | # install from http 19 | curl -s https://github.com/jbenet/ipfs-paste/blob/master/ipfs-paste >/usr/local/bin/ipfs-paste 20 | chmod +x /usr/local/bin/ipfs-paste 21 | ``` 22 | 23 | Note: requires running IPFS daemon. 24 | 25 | ## Usage 26 | 27 | ```sh 28 | > ipfs-paste -h 29 | ipfs-paste [-v] [--paste] [] 30 | publish stdin (or pasteboard) to ipfs 31 | ``` 32 | 33 | ## Examples 34 | 35 | ```sh 36 | # stdin to ipfs 37 | > echo hello mars | ipfs-paste 38 | http://gateway.ipfs.io/ipfs/QmZd56pN6zKvFrqp3ojRHHJQ2x2NWKTLmsEQbni37cDgvx/paste 39 | 40 | # clipboard to ipfs 41 | > echo hello mars | pbcopy 42 | > pbpaste 43 | hello mars 44 | > ipfs-paste --paste 45 | http://gateway.ipfs.io/ipfs/QmV3pQbmx9ziGt4r7i6wyJuSg7hovT6Znxo9PAEoo6M8qB/paste 46 | 47 | # set a name to file 48 | > head -c 1024 /dev/random | ipfs-paste rand-kb 49 | http://gateway.ipfs.io/ipfs/QmctPRXHkmoQfZSKExNvcpPS7g1BQciarzWVM7QYdzS6eJ/rand-kb 50 | 51 | # verbose 52 | > cat ipfs-paste | ipfs-paste -v 53 | stdin to ipfs... QmbSV3f1T5qbdfxfhSgrudRSv3YiJBxKFGthPAEDZVEhpj 54 | constructing dir... QmYXNKmW7vyvpcTEtAUXGjJ8X9wmh1BgqmZLutFQYLhUev 55 | copying url to clipboard... copied 56 | http://gateway.ipfs.io/ipfs/QmYXNKmW7vyvpcTEtAUXGjJ8X9wmh1BgqmZLutFQYLhUev/paste 57 | preloading on the gateways... ok 58 | ``` 59 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | 6 | src=ipfs-paste 7 | dst=/usr/local/bin/ipfs-paste 8 | 9 | echo cp "$src" "$dst" 10 | cp "$src" "$dst" 11 | -------------------------------------------------------------------------------- /ipfs-paste: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | USAGE="$0 [-v] [--paste] []" 4 | 5 | usage() { 6 | echo "$USAGE" 7 | echo "publish stdin (or pasteboard) to ipfs" 8 | exit 0 9 | } 10 | 11 | die() { 12 | echo >&2 "error: $@" 13 | exit 1 14 | } 15 | 16 | log() { 17 | if [ $verbose ]; then 18 | printf >&2 "$@" 19 | fi 20 | } 21 | 22 | # todo: make this cross-platform 23 | case $(uname) in 24 | Darwin) 25 | clicopy="pbcopy" 26 | clipaste="pbpaste" 27 | ;; 28 | Linux) 29 | if type xsel >/dev/null; 30 | then 31 | clicopy="xsel -i" 32 | clipaste="xsel -o" 33 | else 34 | if type xclip >/dev/null; 35 | then 36 | clicopy="xclip -i" 37 | clipaste="xclip -o" 38 | else 39 | die "xsel or xclip is needed on Linux" 40 | fi 41 | fi 42 | ;; 43 | *) ;; 44 | esac 45 | 46 | # get user options 47 | while [ $# -gt 0 ]; do 48 | # get options 49 | arg="$1" 50 | shift 51 | 52 | case "$arg" in 53 | -h|--help) usage ;; 54 | -v|--verbose) verbose=1 ;; 55 | --paste) paste=1 ;; 56 | --*) 57 | die "unrecognised option: '$arg'\n$USAGE" ;; 58 | *) 59 | if [ "$name" = "" ]; then 60 | name="$arg" 61 | else 62 | die "too many arguments\n$USAGE" 63 | fi 64 | ;; 65 | esac 66 | done 67 | 68 | 69 | if [ "$name" = "" ]; then 70 | name=paste 71 | fi 72 | 73 | if [ $paste ]; then 74 | test -n "$clipaste" || die "clipboard paste unkown for $(uname)" 75 | log "paste to ipfs..." 76 | 77 | date=$(date +"%Y-%m-%dT%H:%M:%SZ") 78 | fpath=$(mktemp "/tmp/paste.$date.XXXXXX.txt") || 79 | die "could not 'mktemp /tmp/paste.$date.XXXXXX.txt'" 80 | 81 | $clipaste >"$fpath" || 82 | die "could not paste using '$clipaste'" 83 | fhash=$(ipfs add -q <"$fpath") || 84 | die "could not 'ipfs add -q' content from '$fpath'" 85 | else 86 | log "stdin to ipfs..." 87 | fhash=$(cat | ipfs add -q) || 88 | die "could not 'ipfs add -q'" 89 | fi 90 | log " $fhash\n" 91 | 92 | 93 | log "constructing dir..." 94 | dir=$(ipfs object new unixfs-dir) || 95 | die "could not 'ipfs object new unixfs-dir'" 96 | dir=$(ipfs object patch "$dir" add-link "$name" "$fhash") || 97 | die "could not 'ipfs object patch $dir add-link $name $fhash'" 98 | pin=$(ipfs pin add -r "$dir") || 99 | die "could not 'ipfs pin add -r $dir'" 100 | log " $dir\n" 101 | 102 | log "copying url to clipboard..." 103 | out="https://ipfs.io/ipfs/$dir/$name" 104 | echo "$out" | $clicopy || 105 | die "could not copy using '$clicopy'" 106 | log " copied\n" 107 | echo "$out" 108 | 109 | log "preloading on the gateways..." 110 | (curl "$out" >/dev/null 2>&1 && log " ok\n") || log " n/a\n" 111 | -------------------------------------------------------------------------------- /test/sharness/.gitignore: -------------------------------------------------------------------------------- 1 | lib/sharness/ 2 | test-results/ 3 | trash directory.*.sh/ 4 | -------------------------------------------------------------------------------- /test/sharness/Makefile: -------------------------------------------------------------------------------- 1 | # Run sharness tests 2 | # 3 | # Copyright (c) 2014 Christian Couder 4 | # MIT Licensed; see the LICENSE file in this repository. 5 | # 6 | # NOTE: run with TEST_VERBOSE=1 for verbose sharness tests. 7 | 8 | T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) 9 | LIBDIR = lib 10 | SHARNESSDIR = sharness 11 | AGGREGATE = $(LIBDIR)/$(SHARNESSDIR)/aggregate-results.sh 12 | 13 | 14 | # Add below the binaries that this project generates or needs. 15 | # For example: 16 | # BINS = bin/ipfs 17 | BINS = 18 | 19 | all: aggregate 20 | 21 | clean: clean-test-results 22 | @echo "*** $@ ***" 23 | # Clean binaries below. 24 | # For example: 25 | # -rm -rf bin/ipfs 26 | 27 | clean-test-results: 28 | @echo "*** $@ ***" 29 | -rm -rf test-results 30 | 31 | $(T): clean-test-results deps 32 | @echo "*** $@ ***" 33 | ./$@ 34 | 35 | aggregate: clean-test-results $(T) 36 | @echo "*** $@ ***" 37 | ls test-results/t*-*.sh.*.counts | $(AGGREGATE) 38 | 39 | # Add below some needed dependencies. 40 | # For example: 41 | # deps: sharness $(BINS) curl 42 | deps: sharness $(BINS) 43 | 44 | sharness: 45 | @echo "*** checking $@ ***" 46 | lib/install-sharness.sh 47 | 48 | # Add below other targets like: 49 | # - the targets needed to build binaries, 50 | # - targets using special compile flags, 51 | # - targets to check or install dependencies. 52 | # 53 | # For example: 54 | # 55 | # GOFLAGS = 56 | # 57 | # bin/%: FORCE 58 | # cd .. && make GOFLAGS=$(GOFLAGS) $@ 59 | # 60 | # race: 61 | # make GOFLAGS=-race all 62 | # 63 | # curl: 64 | # @which curl >/dev/null || (echo "Please install curl!" && false) 65 | 66 | .PHONY: all clean clean-test-results $(T) aggregate deps sharness FORCE 67 | 68 | -------------------------------------------------------------------------------- /test/sharness/lib/install-sharness.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # install-sharness.sh 3 | # 4 | # Copyright (c) 2014 Juan Batiz-Benet 5 | # Copyright (c) 2015 Christian Couder 6 | # MIT Licensed; see the LICENSE file in this repository. 7 | # 8 | # This script checks that Sharness is installed in: 9 | # 10 | # $(pwd)/$clonedir/$sharnessdir/ 11 | # 12 | # where $clonedir and $sharnessdir are configured below. 13 | # 14 | # If Sharness is not installed, this script will clone it 15 | # from $urlprefix (defined below). 16 | # 17 | # If Sharness is not uptodate with $version (defined below), 18 | # this script will fetch and will update the installed 19 | # version to $version. 20 | # 21 | 22 | # settings 23 | version=1487d96e7ea61c23e856348ec439e2415761aab2 24 | urlprefix=/home/christian/git/sharness 25 | clonedir=lib 26 | sharnessdir=sharness 27 | 28 | if test -f "$clonedir/$sharnessdir/SHARNESS_VERSION_$version" 29 | then 30 | # There is the right version file. Great, we are done! 31 | exit 0 32 | fi 33 | 34 | die() { 35 | echo >&2 "$@" 36 | exit 1 37 | } 38 | 39 | checkout_version() { 40 | git checkout "$version" || die "Could not checkout '$version'" 41 | rm -f SHARNESS_VERSION_* || die "Could not remove 'SHARNESS_VERSION_*'" 42 | touch "SHARNESS_VERSION_$version" || die "Could not create 'SHARNESS_VERSION_$version'" 43 | echo "Sharness version $version is checked out!" 44 | } 45 | 46 | if test -d "$clonedir/$sharnessdir/.git" 47 | then 48 | # We need to update sharness! 49 | cd "$clonedir/$sharnessdir" || die "Could not cd into '$clonedir/$sharnessdir' directory" 50 | git fetch || die "Could not fetch to update sharness" 51 | else 52 | # We need to clone sharness! 53 | mkdir -p "$clonedir" || die "Could not create '$clonedir' directory" 54 | cd "$clonedir" || die "Could not cd into '$clonedir' directory" 55 | 56 | git clone "$urlprefix" || die "Could not clone '$urlprefix'" 57 | cd "$sharnessdir" || die "Could not cd into '$sharnessdir' directory" 58 | fi 59 | 60 | checkout_version 61 | -------------------------------------------------------------------------------- /test/sharness/t0000-sharness.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | test_description="Show basic features of Sharness" 4 | 5 | . ./lib/sharness/sharness.sh 6 | 7 | test_expect_success "Success is reported like this" " 8 | echo hello world | grep hello 9 | " 10 | 11 | test_expect_success "Commands are chained this way" " 12 | test x = 'x' && 13 | test 2 -gt 1 && 14 | echo success 15 | " 16 | 17 | return_42() { 18 | echo "Will return soon" 19 | return 42 20 | } 21 | 22 | test_expect_success "You can test for a specific exit code" " 23 | test_expect_code 42 return_42 24 | " 25 | 26 | test_expect_failure "We expect this to fail" " 27 | test 1 = 2 28 | " 29 | 30 | test_done 31 | 32 | # vi: set ft=sh : 33 | --------------------------------------------------------------------------------