1 ################################################################################
3 # src_fetch.cygpart - cygport source downloading functions
5 # Copyright (C) 2006-2020 Cygport authors
6 # Provided by the Cygwin project <https://cygwin.com/>
8 # cygport is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # cygport is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with cygport. If not, see <https://www.gnu.org/licenses/>.
21 ################################################################################
23 #****** Chapter 5/Downloading
26 #****v* Downloading/SRC_URI
28 # Download address(es) for the package source file(s), as a string.
29 # The first file in SRC_URI will be considered the primary source file
30 # and will determine the default SRC_DIR.
32 # Individual source files maintained locally may also be used by adding
33 # their basenames to SRC_URI.
35 # Adding a signature (suffix .asc, .sig or .sign) or checksum file
36 # (suffix .md5, .sha1, .sha256 or .sha512) to SRC_URI will trigger
37 # an attempt at verification of the corresponding source. The
38 # result is printed to the output, but not used to abort the build
39 # even if verification fails.
41 # The basename of each URI is treated as the source filename, except that
42 # CGI query strings are dropped after downloading. If this would not yield
43 # a usable filename, then the file can be renamed by appending an artificial
44 # URI fragment in the form of #/FILENAME to the URI. Some examples where this
45 # may be useful or even necessary:
46 # * an unversioned source tarball
47 # * a file, patch, or snapshot from a gitweb interface (where all specific
48 # information is in the query string itself)
49 # * a patch from a cgit interface (normally /patch?id=COMMIT)
50 # * a file from a Bugzilla attachment (normally /attachment.cgi?id=NUMBER)
52 # This variable is required, but many cygclasses automatically define
53 # a default SRC_URI based on the values of PN and PV.
55 # bzr.cygclass, cvs.cygclass, fossil.cygclass, git.cygclass, hg.cygclass,
56 # mtn.cygclass, svn.cygclass, Mirrors.
59 #****v* Downloading/PATCH_URI
61 # Download address(es) for source patches which are to be applied immediately
62 # after unpacking sources, as a string.
64 # Individual source patches maintained locally may also be used by adding
65 # their basenames to PATCH_URI. This provides an easy way to carry
66 # Cygwin-specific patches forward between releases.
68 # Compressed patches and patch archives will be uncompressed on-the-fly.
69 # Supported compression formats are gzip, bzip2, xz and zstd.
73 # For historical reasons, patches with basenames of ${PF}.{cygwin,src}.patch
74 # should not be listed in PATCH_URI, as they are treated specially and are
75 # automatically applied, if present, and generated, if required.
79 # See SRC_URI for details about URI handling in cygport.
82 # downloads file(s) from Internet
91 urifile=${urifile%\?*};
92 urifile=${urifile##*/};
94 if [ -z "${urifile}" ]
96 error "Won't fetch URI '$1', as it doesn't have a basename. Please specify one by appending #/FILENAME. See SRC_URI in the reference manual for details."
99 if defined __DL_ONLY_MISSING && defined DISTDIR && [ -f ${DISTDIR}/${urifile} ]
101 inform "Using ${urifile} from DISTDIR"
106 wget --no-check-certificate -O ${urifile}.tmp ${uri}
111 curl -R -k --url ${uri} -o ${urifile}.tmp
114 error "Either wget or curl are required to fetch sources.";
119 mv -f ${urifile}.tmp ${urifile}
121 if defined __DL_MIRROR_LIST
126 error "${prog} ${uri} failed"
130 if defined DISTDIR && [ -f ${urifile} ]
132 [ -d ${DISTDIR} ] || mkdir -p ${DISTDIR}
133 mv ${urifile} ${DISTDIR}/
145 miruri=${1#mirror://};
146 mirname=${miruri%%/*};
147 mirvar=mirror_${mirname};
149 if ! defined ${mirvar}
151 error "unknown mirror ${mirname}";
154 mirlist=(${!mirvar});
156 if [ ${#mirlist[*]} -gt 1 ] # iterate thru list > 1
158 dl_mirrors=${#mirlist[*]}
162 while (( n < ${#mirlist[*]} ))
164 if __DL_MIRROR_LIST=${dl_mirrors} fetch ${mirlist[${n}]}/${miruri#*/}
171 error "Could not download ${1##*/} from ${mirname} mirror(s)";
174 # downloads all sources through method-specific functions
179 # FIXME: Versions < 0.3.1 would allow only one in any case.
180 # While theoretically possible to use more than one of the RCS_fetch cmds
181 # it's not assured because the tarball names could be the same.
182 # Unfortunately, changing the RCS tarball names would break existing
183 # source packages. So for now, follow the previous behavior.
184 for rcs in cvs svn git bzr hg mtn fossil
193 # the RCS_fetch functions change PWD
196 for uri in ${SRC_URI} ${PATCH_URI}
198 if defined __DL_ONLY_MISSING && [ -f ${uri##*/} ]
203 mirror:) __mirror_fetch ${uri} ;;
204 http:|https:|ftp:) fetch ${uri} || error "Download ${uri##*/} failed" ;;
205 file:) [ -f ${uri#file://} ] || error "${uri##*/}: does not exist" ;;
206 *:) error "Unsupported download protocol ${uri%%//*}" ;;
207 */*) [ -f ${uri#file://} ] || error "${uri##*/}: does not exist" ;;
208 ${uri}) ;; # file in working directory
209 *) error "Invalid download URI ${uri}" ;;
214 readonly -f fetch __mirror_fetch __src_fetch