forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jldownload
executable file
·52 lines (45 loc) · 1.39 KB
/
jldownload
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
#!/bin/sh
#
# usage: jldownload [<output-filename>] <url>
#
MIRROR_HOST=https://d304tytmzqn1fl.cloudfront.net
WGET=$(which wget 2>/dev/null)
CURL=$(which curl 2>/dev/null)
FETCH=$(which fetch 2>/dev/null)
TIMEOUT=15 # seconds
WGET_OPTS="--no-check-certificate --tries=1 --timeout=$TIMEOUT"
CURL_OPTS="-fkL --connect-timeout $TIMEOUT -y $TIMEOUT"
FETCH_OPTS="-T $TIMEOUT"
if [ $# -eq 1 ]; then
CURL_OPTS="$CURL_OPTS -O"
URL=$1
elif [ $# -eq 2 ]; then
WGET_OPTS="$WGET_OPTS -O $1"
CURL_OPTS="$CURL_OPTS -o $1"
FETCH_OPTS="$FETCH_OPTS -o $1"
URL=$2
else
exit 1
fi
MIRROR_BASENAME=`basename $1`
MIRROR_URL="$MIRROR_HOST/$MIRROR_BASENAME"
if [ -x "$CURL" ] && $CURL -V >/dev/null; then
GETURL="$CURL $CURL_OPTS"
elif [ -x "$WGET" ] && $WGET -V >/dev/null; then
GETURL="$WGET $WGET_OPTS"
elif [ -x "$FETCH" ]; then
GETURL="$FETCH $FETCH_OPTS"
else
echo "Could not find working curl, wget, or fetch."
echo "You need to install one of these to download dependencies."
exit 1
fi
if [ -z "$JLDOWNLOAD_PREFER_MIRROR" ]; then
$GETURL $URL || $GETURL $MIRROR_URL
else
# Still try downloading from the original URL if the mirror fails.
# User may want to get around a single failure, only to run into a dep
# that we haven't mirrored yet, so better to be safe than sorry and try
# the original URL in that case
$GETURL $MIRROR_URL || $GETURL $URL
fi