diff --git a/ipfs-wormhole.sh b/ipfs-wormhole.sh index 6ccef48..1d0c16f 100755 --- a/ipfs-wormhole.sh +++ b/ipfs-wormhole.sh @@ -13,27 +13,82 @@ IFS=$'\n\t' # - gpg # - ipfs +# Check deps + +set +e +PWGENCMD="$(command -v pwgen)" +GPGCMD="$(command -v gpg)" +IPFSCMD="$(command -v ipfs)" +set +e + +ERROR=0 +if [ -z "$PWGENCMD" ]; then + echo pwgen not found + ERROR=1 +fi +if [ -z "$GPGCMD" ]; then + echo gpg not found + ERROR=1 +fi +if [ -z "$IPFSCMD" ]; then + echo ipfs not found + ERROR=1 +fi + +[ "$ERROR" -eq 1 ] && exit 1 + case "${1:-}" in send) echo "Send..." - PASSWORD=$(pwgen -1 20) + PASSWORD=$($PWGENCMD -1 20) FILE=${2:-} - TAG=$(gpg --batch --passphrase="$PASSWORD" -c -o - "$FILE" | - ipfs add -Q) + TAG=$($GPGCMD --batch --passphrase="$PASSWORD" -c -o - "$FILE" | + $IPFSCMD add -Q) FILENAME="$(echo "$FILE" | base64)" - echo "Retrieve with $0 receive $TAG$PASSWORD$FILENAME" + RECEIVECMD="$0 receive $TAG$PASSWORD$FILENAME" + echo "Retrieve with $RECEIVECMD" + set +e + XCLIPCMD="$(command -v xclipe)" + set -e + if [ -n "$XCLIPCMD" ]; then + echo "$RECEIVECMD" | $XCLIPCMD + echo "Copied to clipboard" + fi exit 0 ;; receive) DSTFILENAME="$(echo "${2:66}" | base64 -d)" echo "Receiving $DSTFILENAME..." - ipfs cat "${2:0:46}" | - gpg --batch --passphrase="${2:46:20}" -d \ + $IPFSCMD cat "${2:0:46}" | + $GPGCMD --batch --passphrase="${2:46:20}" -d \ >"$DSTFILENAME" \ 2>/dev/null exit 0 ;; -esac +update) + echo Update... + wget -O "${0:-}" \ + https://raw.githubusercontent.com/aurelg/ipfs-wormhole/master/ipfs-wormhole.sh + exit 0 + ;; +*) + cat <" -echo "${0:-} receive " +On machine A: +------------- + +${0:-} send + +# Will encrypt and add the file to IPFS, and output a tag (and copy it to the +# clipboard if xclip is installed) + +On machine B: +------------- + +${0:-} receive + +# Will retrieve the file over IPFS, decrypt it and save it locally. +EOM + ;; +esac