#!/usr/bin/bash

# Supported digest algorithms:
# sha1
# sha256
# sha512
# sha512/256 - how to generate?
# md5

# Create 'a'  
echo -n "create /a (expect 201 or 204) - "
curl -s -i -XPUT localhost:8080/rest/a 

# Create local binary:
echo "Hello World" > binary.txt
sha1sum -z binary.txt | awk '{print $1}' > binary.txt.sha1
sha256sum -z binary.txt | awk '{print $1}' > binary.txt.sha256
sha512sum -z binary.txt | awk '{print $1}' > binary.txt.sha512
md5sum -z binary.txt | awk '{print $1}' > binary.txt.md5

# Add binary to F6
echo -n "create binary /a/b (expect 201 or 204)- "
curl -s -i -XPUT --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/b 

echo -n "create binary /a/b with SHA1 (expect 201 or 204)- "
curl -s -i -XPUT -H"digest: sha=`cat binary.txt.sha1`" --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/b1 

echo -n "create binary /a/b with SHA256 (expect 201 or 204)- "
curl -s -i -XPUT -H"digest: sha-256=`cat binary.txt.sha256`" --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/b256 

echo -n "create binary /a/b with SHA512 (expect 201 or 204)- "
curl -s -i -XPUT -H"digest: sha-512=`cat binary.txt.sha512`" --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/b512 

echo -n "create binary /a/b with MD5 (expect 201 or 204)- "
curl -s -i -XPUT -H"digest: md5=`cat binary.txt.md5`" --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/bmd5md5md5md5md5 

echo -n "create binary /a/b with bad digest (expect 409)- "
curl -s -i -XPUT -H"digest: md5=`cat binary.txt.md5`+123" --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/bmd5md5md5md5md5 

echo -n "create binary /a/b with MD5 & SHA512 (expect 201 or 204)- "
curl -s -i -XPUT -H"digest: sha-512=`cat binary.txt.sha512`, md5=`cat binary.txt.md5`" --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/b512-md5 

echo -n "create binary /a/b with MD5 & bad-SHA512 (expect 409)- "
curl -s -i -XPUT -H"digest: sha-512=`cat binary.txt.sha512`+123, md5=`cat binary.txt.md5`" --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/b-bad512-md5 

echo -n "create binary /a/b with MD5 & bad-SHA1 (expect 409)- "
curl -s -i -XPUT -H"digest: sha=`cat binary.txt.sha1`+123, md5=`cat binary.txt.md5`" --data-binary @binary.txt -H"Link: <http://www.w3.org/ns/ldp#NonRDFSource>; rel='type'" localhost:8080/rest/a/b-bad1-md5 

