Skip to content

Commit

Permalink
Runtime check of dependencies, added selfupdate from github repo, and…
Browse files Browse the repository at this point in the history
… help.
  • Loading branch information
Zi1mo5zo committed Nov 22, 2018
1 parent bbafac5 commit b45efe7
Showing 1 changed file with 64 additions and 9 deletions.
73 changes: 64 additions & 9 deletions ipfs-wormhole.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOM
Get things from one computer to another, safely. Over IPFS.
echo "${0:-} send <filename>"
echo "${0:-} receive <tag>"
On machine A:
-------------
${0:-} send <filename>
# 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 <tag>
# Will retrieve the file over IPFS, decrypt it and save it locally.
EOM
;;
esac

0 comments on commit b45efe7

Please sign in to comment.