Created
April 29, 2013 14:24
-
-
Save dankerrigan/5481889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
randomString32() { | |
index=0 | |
str="" | |
for i in {a..z}; do arr[index]=$i; index=`expr ${index} + 1`; done | |
for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done | |
for i in {1..63}; do str="$str${arr[$RANDOM%$index]}"; done | |
echo $str | |
} | |
sectionHeader() { | |
echo $'\n\n##############################' | |
echo $1 | |
echo $'##############################\n' | |
} | |
function jsonval { | |
temp=`echo $json | sed 's/\\\\\//\//g' | sed 's/[{}]//g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}' | sed 's/\"\:\"/\|/g' | sed 's/[\,]/ /g' | sed 's/\"//g' | grep -w $prop` | |
echo ${temp##*|} | |
} | |
REPO=`randomString32` | |
FILENAME=`randomString32` | |
cp test.pdf $FILENAME.pdf | |
echo "Random REPO string: $REPO" | |
sectionHeader "1) Create a new repository, $REPO" | |
curl -i -XPUT http://127.0.0.1:60001/repos/$REPO?oauth_token=damp-r0-read-write -H "Content-Type: application/json" -d '{"description": "test repo called '"$REPO"'", "model_uri": "/models/stub"}' | |
sectionHeader "2) Get the master workspace for $REPO in order to determine the ID of the head revision" | |
json=$(curl -i "http://127.0.0.1:60001/repos/$REPO/workspaces/master?oauth_token=damp-r0-read-write") | |
echo "$json" | |
prop='head_revision_uri' | |
head_revision_uri=`jsonval` | |
parent_revision_id=$(basename $head_revision_uri) | |
echo $'\nparent_revision_id: '"$parent_revision_id" | |
sectionHeader "3) Using the value of the head attribute from step 2 for the parent_revision_id, add $FILENAME.pdf (or any other filename you like):" | |
json=$(curl -i -XPOST http://127.0.0.1:60001/repos/$REPO/workspaces/master/revisions?oauth_token=damp-r0-read-write -H "Content-Type: application/json" -d '{ "description": "test change to repo '"$REPO"'", "parent_revision_id" : "'"$parent_revision_id"'", "commands": [ { "action": "store", "path": "/'"$FILENAME"'.pdf", "classifier_uri": "/models/stub/classifiers/contract", "blob_hash": "123412341234", "meta_data": {} } ] }') | |
echo "$json" | |
prop='modified_blobs' | |
blob_uri=`jsonval` | |
blob_uri="${blob_uri%?}" | |
echo $'\nblob_uri: '"$blob_uri" | |
IFS="=" | |
set -- $blob_uri | |
revision_id="$2" | |
echo $'\nrevision_id: '"$revision_id" | |
sectionHeader "4) Upload the blob using the URIs returned in the response to step 3:" | |
curl -i -XPUT -H "Content-Type: application/octet-stream" --data-binary @$FILENAME.pdf "http://127.0.0.1:60001$blob_uri&oauth_token=damp-r0-read-write" | |
rm $FILENAME.pdf | |
sectionHeader "5) Apply the revision" | |
curl -i -XPATCH "http://127.0.0.1:60001/repos/$REPO/workspaces/master?revision_id=$revision_id&oauth_token=damp-r0-read-write" | |
sectionHeader "6) Get the HEAD asset information for $FILENAME.pdf" | |
curl -i -XGET "http://127.0.0.1:60001/repos/$REPO/workspaces/master/assets/$FILENAME.pdf?oauth_token=damp-r0-read-write" | |
sectionHeader "7) Download the HEAD asset blob" | |
curl -v -XGET -o $FILENAME.pdf -H "Content-Type: application/octet-stream" -H "Accept: application/octet-stream" "http://127.0.0.1:60001/repos/$REPO/workspaces/master/assets/$FILENAME.pdf/blob?oauth_token=damp-r0-read-write" | |
sectionHeader "8) Verify file is here" | |
ls -al | grep pdf | |
echo "shasum test.pdf" | |
echo `shasum test.pdf` | |
echo "shasum $FILENAME.pdf" | |
echo `shasum $FILENAME.pdf` | |
rm $FILENAME.pdf | |
sectionHeader "9) Search for the File" | |
curl -v "http://127.0.0.1:60001/repos/$REPO/workspaces/master/search/?oauth_token=damp-r0-read-write&query=name:$FILENAME.pdf" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment