Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 90 lines (83 sloc) 2.12 KB
#!/bin/bash
SERVER=http://www.cross-copy.net
QUIET=false
FETCH_RECENT_DATA=false
PARAMETERS="?"
VERBOSE=false
JSON=''
function usage(){
echo "usage: cross-copy [options...] <secred-code> [ 'message' | <filename> ]"
echo "To transfer data from one device to the other"
echo " 1. choose a shared secred"
echo " 2. listen for data on receiving device with cross-copy <secred-code>"
echo " 3. share text with cross-copy <secred-code> \"your message\""
echo " or a file with cross-copy <secred-code> <filename>"
}
while getopts ":lhqrvjs:d:k:" opt; do
case $opt in
h) usage
exit 0
;;
q)
QUIET=true
;;
k)
PARAMETERS="${PARAMETERS}keep_for=${OPTARG}&"
;;
r)
FETCH_RECENT_DATA=true
;;
s)
PARAMETERS="${PARAMETERS}since=${OPTARG}&"
;;
j)
JSON=".json"
;;
v)
VERBOSE=true
;;
d)
PARAMETERS="${PARAMETERS}device_id=${OPTARG}&"
;;
l)
SERVER=http://localhost:8080
$QUIET || echo "using localhost instead of cross-copy.net"
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
shift $((OPTIND-1)); OPTIND=1
done
if [ $# == 1 ]; then
if [ $FETCH_RECENT_DATA == true ]; then
CMD="curl -s $SERVER/api/$1/recent-data.json"
$VERBOSE && echo $CMD
RECENT=`$CMD`
echo $RECENT
exit 0
fi
$QUIET || echo "waiting for pastes with secret '$1' on $SERVER"
CMD="curl -s $SERVER/api/$1$JSON$PARAMETERS"
$VERBOSE && echo $CMD
PASTE=`$CMD`
# download file if it's an internal uri
if [[ $PASTE == /api/${1}* ]]; then
PASTE=${SERVER}$PASTE
wget $PASTE
else
echo $PASTE
fi
elif [ $# == 2 ]; then
PASTE=$2
FILE=$(basename "$2")
[ -f "$2" ] && curl -q -F "file=@$2" "$SERVER/api/$1/$FILE" --limit-rate 10k > /dev/null &
[ -f "$2" ] && PASTE="/api/$1/$FILE"
DELIVERIES=`curl -X PUT -s -d "$PASTE" "$SERVER/api/$1$JSON$PARAMETERS"`
echo "$DELIVERIES direct deliveries"
[[ $DELIVERIES == 0 ]] && echo "(you should wait for data on the other device while sending somthing)"
else
echo "wrong number of arguments."
usage
fi