forked from NrgXnat/oasis-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.sh
executable file
·48 lines (42 loc) · 1.67 KB
/
functions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
# Authenticates credentials against Central and returns the cookie jar file name. USERNAME and
# PASSWORD must be set before calling this function.
# USERNAME="foo"
# PASSWORD="bar"
# COOKIE_JAR=$(startSession)
startSession() {
# Authentication to XNAT and store cookies in cookie jar file
local COOKIE_JAR=.cookies-$(date +%Y%M%d%s).txt
curl -k -s -u ${USERNAME}:${PASSWORD} --cookie-jar ${COOKIE_JAR} "https://central.xnat.org/data/JSESSION" > /dev/null
echo ${COOKIE_JAR}
}
# Downloads a resource from a URL and stores the results to the specified path. The first parameter
# should be the destination path and the second parameter should be the URL.
download() {
local OUTPUT=${1}
local URL=${2}
curl -H 'Expect:' --keepalive-time 2 -k --cookie ${COOKIE_JAR} -o ${OUTPUT} ${URL}
}
# Downloads a resource from a URL and stores the results to the specified path. The first parameter
# should be the destination path and the second parameter should be the URL. This function tries to
# resume a previously started but interrupted download.
continueDownload() {
local OUTPUT=${1}
local URL=${2}
curl -H 'Expect:' --keepalive-time 2 -k --continue - --cookie ${COOKIE_JAR} -o ${OUTPUT} ${URL}
}
# Gets a resource from a URL.
get() {
local URL=${1}
curl -H 'Expect:' --keepalive-time 2 -k --cookie ${COOKIE_JAR} ${URL}
}
# Ends the user session.
endSession() {
# Delete the JSESSION token - "log out"
curl -i -k --cookie ${COOKIE_JAR} -X DELETE "https://central.xnat.org/data/JSESSION"
rm -f ${COOKIE_JAR}
}
bailOnWget() {
echo "There are session management issues using wget. It's probably best not to do this."
exit -1
}