1 | #!/bin/sh |
---|
2 | # written by Gregory Vincic |
---|
3 | host=$1 |
---|
4 | username=$2 |
---|
5 | password=$3 |
---|
6 | project=$4 |
---|
7 | projectENC=${project//\*/%25} |
---|
8 | path=$5 |
---|
9 | url="$host/proteios/resource" |
---|
10 | auth="?username=$username&password=$password" |
---|
11 | tmp="/tmp/ul2p.tmp" |
---|
12 | filename=${path##*/} |
---|
13 | if [ "$path" == "" ] || [ ! -f $path ]; then |
---|
14 | echo "Usage: $0 http://host[:port] username password \"projectName\" file" |
---|
15 | echo |
---|
16 | echo " projectName e.g. *test would match any project that ends with test" |
---|
17 | echo |
---|
18 | echo "For multiple file upload use" |
---|
19 | echo " find path -type f -exec $0 http://host[:port] username password \"projectName\" '{}' \;" |
---|
20 | echo |
---|
21 | exit |
---|
22 | fi |
---|
23 | |
---|
24 | if [ "$project" != "" ]; then |
---|
25 | # Find project id here |
---|
26 | projectsQuery="$url/projects$auth&select=Id,Name&whereName==$projectENC" |
---|
27 | projectid=`curl -s "$projectsQuery"| grep -v 'Id' | awk '{print $1}'` |
---|
28 | pcount=${#projectid} |
---|
29 | if [ "$pcount" == "0" ]; then echo "No project name matching [$project]"; exit; fi |
---|
30 | if [ "$pcount" != "1" ]; then echo "[$project] matches $pcount projects"; exit; fi |
---|
31 | filesUri="$url/projects/$projectid/files" |
---|
32 | else |
---|
33 | filesUri="$url/files" |
---|
34 | fi |
---|
35 | |
---|
36 | |
---|
37 | if [ -f $path ]; then |
---|
38 | echo -e "Name\n$filename" > $tmp |
---|
39 | curl -f -s -T $tmp "$filesUri$auth" |
---|
40 | if [ $? == 22 ]; then echo "Failed to upload $path"; exit; fi |
---|
41 | rm $tmp |
---|
42 | listQuery="$filesUri$auth&select=Id,Name&whereName==$filename" |
---|
43 | id=`curl -s "$listQuery"| grep -v 'Id' | awk '{print $1}'` |
---|
44 | if [ "$id" != "" ]; then |
---|
45 | filePutQuery="$filesUri/$id$auth" |
---|
46 | curl -s -T $path $filePutQuery |
---|
47 | else |
---|
48 | echo "Error" |
---|
49 | fi |
---|
50 | fi |
---|
51 | exit 1; |
---|
52 | |
---|