WebservicePutExamples: uploadFileToProSE.sh

File uploadFileToProSE.sh, 1.5 KB (added by Gregory Vincic, 13 years ago)

Example shell script for uploading files to ProSE

Line 
1#!/bin/sh
2# written by Gregory Vincic
3host=$1
4username=$2
5password=$3
6project=$4
7projectENC=${project//\*/%25}
8path=$5
9url="$host/proteios/resource"
10auth="?username=$username&password=$password"
11tmp="/tmp/ul2p.tmp"
12filename=${path##*/}
13if [ "$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
22fi
23
24if [ "$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"
32else
33 filesUri="$url/files"
34fi
35
36
37if [ -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
50fi
51exit 1;
52