From a8e282f91142be3c8d930eba1b1b59e7316e9a14 Mon Sep 17 00:00:00 2001 From: Zi1mo5zo Date: Thu, 22 Nov 2018 08:01:14 +0100 Subject: [PATCH] Runtime check of dependencies, automatically copy tag to clipboard if xclip is installed, added selfupdate from github repo, and help text. --- ipfs-wormhole.sh | 78 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/ipfs-wormhole.sh b/ipfs-wormhole.sh index 6ccef48..0877dca 100755 --- a/ipfs-wormhole.sh +++ b/ipfs-wormhole.sh @@ -13,27 +13,87 @@ 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 " +${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. + +Update from github repo +----------------------- + +${0:-} update +EOM + ;; +esac