Debian Codegraph @

bin/build/download

raw
1 #!/usr/bin/env bash
2 # -xe
3
4 ############################################################################
5 # This file is part of FreeFEM. #
6 # #
7 # FreeFEM is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU Lesser General Public License as #
9 # published by the Free Software Foundation, either version 3 of #
10 # the License, or (at your option) any later version. #
11 # #
12 # FreeFEM is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU Lesser General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU Lesser General Public License #
18 # along with FreeFEM. If not, see <http://www.gnu.org/licenses/>. #
19 ############################################################################
20 # SUMMARY : Download a file by whatever means available
21 # LICENSE : LGPLv3
22 # ORG : LJLL Universite Pierre et Marie Curie, Paris, FRANCE
23 # AUTHORS : Antoine Le Hyaric
24 # E-MAIL : ...
25
26 # $1=url
27 # $2=local name
28 # $3=BAD_CERT if the SSL certificate of the web server is wrong
29
30 if test -x /usr/bin/wget || test -x /usr/bin/wget.exe || test -x /opt/local/bin/wget
31 then
32
33 opts=
34 if test "$3" = BAD_CERT
35 then
36 opts=--no-check-certificate
37 fi
38
39 # [[man:wget]] we could use no-verbose to avoid mixing several wget outputs together when called concurrently in
40 # [[file:../3rdparty/getall]], but then nothing moves while the download goes on, and the user may think that it's
41 # stuck.
42
43 wget "$1" --timeout=30 --tries=2 --output-document="$2" $opts
44 ret=$?
45 elif test -x /usr/bin/curl
46 then
47 curl -L "$1" --output "$2" --connect-timeout 30
48 ret=$?
49
50 elif test -x /usr/bin/GET
51 then
52 GET "$1" > "$2"
53 ret=$?
54 else
55 echo FF download: No way to download files from the web
56 echo FF download: Please install wget or curl or GET
57 exit 1
58 fi
59 if test "$ret" -eq 0
60 then
61 case `file $2` in
62 *zip*) exit 0 ;;
63 *) echo " incorrect file type => removing " $2;
64 rm $2;
65 exit 1 ;;
66 esac
67 fi
68 echo "Error download $2"
69 exit $ret
70
71 # Local Variables:
72 # mode:shell-script
73 # ispell-local-dictionary:"british"
74 # coding:utf-8
75 # eval:(flyspell-prog-mode)
76 # eval:(outline-minor-mode)
77 # End:
78 # LocalWords: emacs