-
Notifications
You must be signed in to change notification settings - Fork 1
/
fetch.sh
executable file
·73 lines (60 loc) · 1.5 KB
/
fetch.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
#!/bin/bash
readonly DATA_URL='https://linqs-data.soe.ucsc.edu/public/pujara-emnlp17/data-full.tar.gz'
readonly DATA_FILE='data-full.tar.gz'
readonly DATA_DIR='data'
FETCH_COMMAND=''
function err() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2
}
# Check for:
# - wget or curl (final choice to be set in FETCH_COMMAND)
# - tar
function check_requirements() {
local hasWget
type wget > /dev/null 2> /dev/null
hasWget=$?
type curl > /dev/null 2> /dev/null
if [[ "$?" -eq 0 ]]; then
FETCH_COMMAND="curl -o"
elif [[ "${hasWget}" -eq 0 ]]; then
FETCH_COMMAND="wget -O"
else
err 'wget or curl required to download dataset'
exit 10
fi
type tar > /dev/null 2> /dev/null
if [[ "$?" -ne 0 ]]; then
err 'tar required to extract dataset'
exit 11
fi
}
function fetch_data() {
if [[ -e "${DATA_FILE}" ]]; then
echo "Data file found cached, skipping download."
return
fi
echo "Downloading the dataset with command: $FETCH_COMMAND"
$FETCH_COMMAND "${DATA_FILE}" "${DATA_URL}"
if [[ "$?" -ne 0 ]]; then
err 'Failed to download dataset'
exit 20
fi
}
function extract_data() {
if [[ -e "${DATA_DIR}" ]]; then
echo "Extracted data found cached, skipping extract."
return
fi
echo 'Extracting the dataset'
tar -xvzf "${DATA_FILE}"
if [[ "$?" -ne 0 ]]; then
err 'Failed to extract dataset'
exit 30
fi
}
function main() {
check_requirements
fetch_data
extract_data
}
main "$@"