-
Notifications
You must be signed in to change notification settings - Fork 6
/
batch-download.sh
executable file
·74 lines (67 loc) · 1.99 KB
/
batch-download.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#! /bin/bash
set -euo pipefail
# Issues a batch download request; downloads to a file in the current
# directory.
url="https://ezid.cdlib.org/download_request"
if [ $# -lt 3 ]; then
echo "Usage: batch-download.sh username password parameters..."
echo
echo " format={anvl|csv|xml} required"
echo " compression={gzip|zip} defaults to gzip"
echo " column=c repeatable"
echo " _id"
echo " _mappedCreator"
echo " _mappedTitle"
echo " _mappedPublisher"
echo " _mappedDate"
echo " _mappedType"
echo " _target"
echo " notify=address repeatable"
echo " convertTimestamps={yes|no}"
echo " createdAfter={t|YYYY-MM-DDTHH:MM:SSZ} inclusive"
echo " createdBefore={t|YYYY-MM-DDTHH:MM:SSZ} exclusive"
echo " crossref={yes|no}"
echo " datacite={yes|no}"
echo " exported={yes|no}"
echo " owner=u repeatable"
echo " ownergroup=g repeatable"
echo " permanence={test|real}"
echo " profile=p repeatable"
echo " status={reserved|public|unavailable} repeatable"
echo " type={ark|doi|uuid} repeatable"
echo " updatedAfter={t|YYYY-MM-DDTHH:MM:SSZ} inclusive"
echo " updatedBefore={t|YYYY-MM-DDTHH:MM:SSZ} exclusive"
exit
fi
echo "submitting download request..."
username="$1"; shift
password="$1"; shift
args=()
for a in "$@"; do
args+=("-d")
args+=("$a")
done
s="$(curl -sS -u "$username:$password" "${args[@]}" $url)"
if [ $? -ne 0 -o "${s:0:9}" != "success: " ]; then
echo "$s"
echo "request failed"
exit 1
fi
echo -n "waiting.."
url=${s:9:${#s}}
file=${url##*/}
status=22
while [ $status -eq 22 ]; do
echo -n "."
sleep 5
curl -L -f -O -s $url
status=$?
done
echo
if [ $status -eq 0 ]; then
echo "downloaded file: $file"
else
echo "download failed"
echo "url: $url"
exit 1
fi