2013-03-20 15:19:31 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# This script demonstrates basic interaction with tusd form BASH/curl.
|
|
|
|
# Can also be used as a simple way to test, or extend to see how it
|
|
|
|
# responds to edge cases or learn the basic tech.
|
|
|
|
#
|
|
|
|
|
|
|
|
# Constants
|
|
|
|
SERVICE="localhost:1080"
|
|
|
|
|
|
|
|
# Environment
|
2013-03-20 15:51:06 +00:00
|
|
|
set -e
|
2013-03-20 15:19:31 +00:00
|
|
|
__FILE__="$(test -L "${0}" && readlink "${0}" || echo "${0}")"
|
|
|
|
__DIR__="$(cd "$(dirname "${__FILE__}")"; echo $(pwd);)"
|
|
|
|
|
|
|
|
# POST requests the upload location
|
2013-03-20 15:51:06 +00:00
|
|
|
echo -ne "POST '${SERVICE}' \t\t\t\t\t\t\t"
|
2013-03-20 15:19:31 +00:00
|
|
|
location=$(curl -s \
|
|
|
|
--include \
|
|
|
|
--request POST \
|
|
|
|
--header 'Content-Range: bytes */26' \
|
2013-03-20 15:51:06 +00:00
|
|
|
${SERVICE}/files |awk -F': ' '/^Location/ {print $2}' |tr -d '\r')
|
|
|
|
# `tr -d '\r'` is required or location will have one in it ---^
|
|
|
|
echo "<-- Location: ${location}"
|
2013-03-20 15:19:31 +00:00
|
|
|
|
|
|
|
# PUT some data
|
2013-03-20 15:51:06 +00:00
|
|
|
echo -ne "PUT '${SERVICE}${location}' \t\t"
|
|
|
|
status=$(curl -s \
|
2013-03-20 15:19:31 +00:00
|
|
|
--include \
|
|
|
|
--request PUT \
|
|
|
|
--header 'Content-Length: 3' \
|
|
|
|
--header 'Content-Range: bytes 0-2/26' \
|
|
|
|
--data 'abc' \
|
2013-03-20 16:53:09 +00:00
|
|
|
${SERVICE}${location} |head -1 |tr -d '\r')
|
2013-03-20 15:51:06 +00:00
|
|
|
echo "<-- ${status}"
|
2013-03-20 15:19:31 +00:00
|
|
|
|
|
|
|
# check that data with HEAD
|
2013-03-20 15:51:06 +00:00
|
|
|
echo -ne "HEAD '${SERVICE}${location}' \t\t"
|
|
|
|
has_range=$(curl -s -I -X HEAD ${SERVICE}${location} |awk -F': ' '/^Range/ {print $2}' |tr -d '\r')
|
|
|
|
echo "<-- Range: ${has_range}"
|
|
|
|
|
|
|
|
# get that data with GET
|
|
|
|
echo -ne "GET '${SERVICE}${location}' \t\t"
|
|
|
|
has_content=$(curl -s ${SERVICE}${location})
|
|
|
|
echo "<-- ${has_content}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# PUT some data
|
|
|
|
echo -ne "PUT '${SERVICE}${location}' \t\t"
|
|
|
|
status=$(curl -s \
|
2013-03-20 15:19:31 +00:00
|
|
|
--include \
|
2013-03-20 15:51:06 +00:00
|
|
|
--request PUT \
|
|
|
|
--header 'Content-Length: 3' \
|
|
|
|
--header 'Content-Range: bytes 22-25/26' \
|
|
|
|
--data 'xyz' \
|
2013-03-20 16:53:09 +00:00
|
|
|
${SERVICE}${location} |head -1 |tr -d '\r')
|
2013-03-20 15:51:06 +00:00
|
|
|
echo "<-- ${status}"
|
|
|
|
|
|
|
|
# check that data with HEAD
|
|
|
|
echo -ne "HEAD '${SERVICE}${location}' \t\t"
|
|
|
|
has_range=$(curl -s -I -X HEAD ${SERVICE}${location} |awk -F': ' '/^Range/ {print $2}' |tr -d '\r')
|
|
|
|
echo "<-- Range: ${has_range}"
|
2013-03-20 15:19:31 +00:00
|
|
|
|
2013-03-20 15:51:06 +00:00
|
|
|
# get that data with GET
|
|
|
|
echo -ne "GET '${SERVICE}${location}' \t\t"
|
|
|
|
has_content=$(curl -s ${SERVICE}${location})
|
2013-03-20 16:53:09 +00:00
|
|
|
echo "<-- ${has_content}"
|
|
|
|
|