Skip to content
Snippets Groups Projects
Commit 7fd55e66 authored by Jonathan Seguin's avatar Jonathan Seguin
Browse files

Remove obsolete shell client

parent a061f1be
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env bash
SCRIPT_PATH=$(pwd)
action=$1
arg2=$2
BASE_URL=https://thepond.bioinfo.iric.ca
COOKIES=$SCRIPT_PATH/.iricdata.cookies.txt
help() {
echo "To download files in a dataset, provide \"get\" as first argument, followed by a dataset ID."
echo "ex. ./iric-data.sh get DSeccbc87e"
echo ""
echo "To upload a file, provide \"put\" as first argument, followed by the path to the file you wish to upload."
echo "Arguments --annotation (json string or path to json file), --dataset (dataset id), --lab (lab id) and --as-user (user id) may also be added."
echo "ex. ./iric-data.sh put a.txt --annotation='{\"a\": \"b\"}' --lab=2 --dataset=11 --as-user=3"
echo ""
echo "To avoid being prompted for your username and password combination. Place your username on the first line "
echo "and password on the 2nd line of a file named .auth alongside this script."
echo ""
echo "The service url defaults to $BASE_URL. This may be overriden with the --url parameter."
echo "ex. ./iric-data.sh get DSeccbc87e --url http://binfo06.iric.ca:8000"
}
login() {
if test -f ".auth"; then
login=$(head -n 1 .auth)
password=$(head -2 .auth | tail -1)
else
read -p "Login: " login
read -p "Password: " -s password
fi
echo -n "$password" > .iricdata.auth.txt
chmod 600 .iricdata.auth.txt
echo ""
echo "Django Auth: get csrftoken ..."
$CURL_BIN $LOGIN_URL > /dev/null
csrftoken="$(grep csrftoken $COOKIES | sed 's/^.*csrftoken\s*//' | tr -d '[[:blank:]]')"
DJANGO_TOKEN="csrfmiddlewaretoken=$csrftoken"
echo " perform login ..."
$CURL_BIN \
-d "$DJANGO_TOKEN&username=$login" --data-urlencode "password@.iricdata.auth.txt" \
-X POST $LOGIN_URL
}
if [ -z "$action" ]; then
help
exit
fi
LONG=annotation:,lab:,dataset:,as-user:,url:,help
OPTS=$(getopt --long $LONG --name "$0" -- "$@")
if [ $? != 0 ] ; then exit 1 ; fi
eval set -- "$OPTS"
LAB=''
while true ; do
case "$1" in
--annotation )
ANNOTATION="$2"
shift 2
;;
--lab )
LAB="$2"
shift 2
;;
--dataset )
DATASET="$2"
shift 2
;;
--as-user )
AS_USER="$2"
shift 2
;;
--url )
BASE_URL="$2"
shift 2
;;
--help )
help
exit
;;
-- )
shift
break
;;
*)
echo "Internal error!"
exit 1
;;
esac
done
LOGIN_URL=${BASE_URL}/login
FILE_UPLOAD_URL=${BASE_URL}/secure/servlet/datafiles/upload
CURL_BIN="curl -c $COOKIES -b $COOKIES -e $LOGIN_URL"
case "$action" in
"get")
dataset_id=$arg2
if [ -z "$dataset_id" ]; then
help
exit
fi
login
echo " fetching files ..."
mkdir -p $dataset_id
for f in `$CURL_BIN -s -L \
-d "$DJANGO_TOKEN&username=$login" --data-urlencode "password@.iricdata.auth.txt" \
-X GET ${BASE_URL}/secure/dataset/${dataset_id}/file-list`
do
echo "Downloading" $f
(cd $dataset_id;
$CURL_BIN -L -C - \
-d "$DJANGO_TOKEN&username=$login" --data-urlencode "password@$SCRIPT_PATH/.iricdata.auth.txt" \
-X GET $f -O -J --user-agent "WebKit")
done
;;
"put")
if [ -z "$arg2" ]; then
help
exit
else
FILE=$arg2
fi
if [[ -f "$ANNOTATION" ]]; then
ANNOTATION="$(cat $ANNOTATION)"
echo $ANNOTATION
fi
login
echo " uploading" $FILE "..."
$CURL_BIN -b "csrftoken=$csrftoken" -F "$DJANGO_TOKEN" \
-F "annotations=$ANNOTATION" \
-F "lab=$LAB" \
-F "dataset=$DATASET" \
-F "as_user=$AS_USER" \
-F "file=@$FILE" ${FILE_UPLOAD_URL}
;;
*)
help
;;
esac
# Cleanup
rm -f .iricdata.auth.txt $COOKIES
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment