Skip to content

Commit

Permalink
Bugfix w/xclip, added support for transferring directories with tar
Browse files Browse the repository at this point in the history
  • Loading branch information
Zi1mo5zo committed Nov 22, 2018
1 parent 36e8f2e commit 4db68ac
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions ipfs-wormhole.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ IFS=$'\n\t'

set +e
PWGENCMD="$(command -v pwgen)"
TARCMD="$(command -v tar)"
GPGCMD="$(command -v gpg)"
IPFSCMD="$(command -v ipfs)"
set +e
Expand All @@ -26,6 +27,10 @@ if [ -z "$PWGENCMD" ]; then
echo pwgen not found
ERROR=1
fi
if [ -z "$TARCMD" ]; then
echo tar not found
ERROR=1
fi
if [ -z "$GPGCMD" ]; then
echo gpg not found
ERROR=1
Expand All @@ -39,16 +44,28 @@ fi

case "${1:-}" in
send)
echo "Send..."
PASSWORD=$($PWGENCMD -1 20)
FILE=${2:-}
TAG=$($GPGCMD --batch --passphrase="$PASSWORD" -c -o - "$FILE" |
$IPFSCMD add -Q)
if [ -d "$FILE" ]; then
TAG=$(
$TARCMD -Jc "$FILE" | $GPGCMD --batch --passphrase="$PASSWORD" \
-c -o - | $IPFSCMD add -Q
)
FILE="$FILE".tar.xz
echo "Directory compressed and sent as $FILE."
elif [ -f "$FILE" ]; then
TAG=$($GPGCMD --batch --passphrase="$PASSWORD" -c -o - "$FILE" |
$IPFSCMD add -Q)
echo "File $FILE sent."
else
echo "error: $FILE is neither a file, nor a directory"
exit 1
fi
FILENAME="$(echo "$FILE" | base64)"
RECEIVECMD="$0 receive $TAG$PASSWORD$FILENAME"
echo "Retrieve with $RECEIVECMD"
echo "Retrieve it with $RECEIVECMD"
set +e
XCLIPCMD="$(command -v xclipe)"
XCLIPCMD="$(command -v xclip)"
set -e
if [ -n "$XCLIPCMD" ]; then
echo "$RECEIVECMD" | $XCLIPCMD
Expand All @@ -58,6 +75,10 @@ send)
;;
receive)
DSTFILENAME="$(echo "${2:66}" | base64 -d)"
if [ -f "$DSTFILENAME" ]; then
echo "File $DSTFILENAME already exists, aborting..."
exit 1
fi
echo "Receiving $DSTFILENAME..."
$IPFSCMD cat "${2:0:46}" |
$GPGCMD --batch --passphrase="${2:46:20}" -d \
Expand Down

0 comments on commit 4db68ac

Please sign in to comment.