3 # Copyright © 2004-2014, The AROS Development Team. All rights reserved.
9 error
"Usage: $1 -a archive [-s suffixes] [-ao archive_origins...] [-l location to download to] [-d dir to unpack to] [-po patches_origins...] [-p patch[:subdir][:patch options]...]"
14 local origin
="$1" file="$2" destination
="$3" mirrosgroup
="$4" mirrors
="$5"
18 for mirror
in $mirrors; do
19 echo "Downloading from ${mirrosgroup}... "
20 if fetch
"${mirror}/$origin" "${file}" "$destination"; then
29 gnu_mirrors
="http://ftp.gnu.org/pub/gnu http://mirror.mcs.anl.gov/pub/gnu ftp://ftp.cise.ufl.edu/pub/mirrors/GNU/gnu"
33 local origin
="$1" file="$2" destination
="$3"
37 if ! fetch_mirrored
"$origin" "${file}" "$destination" "GNU" "${gnu_mirrors}"; then
44 sf_mirrors
="http://download.sourceforge.net http://aleron.dl.sourceforge.net http://voxel.dl.sourceforge.net http://heanet.dl.sourceforge.net http://avh.dl.sourceforge.net http://umn.dl.sourceforge.net http://unc.dl.sourceforge.net http://puzzle.dl.sourceforge.net http://mesh.dl.sourceforge.net"
48 local origin
="$1" file="$2" destination
="$3"
52 if ! fetch_mirrored
"$origin" "${file}" "$destination" "SourceForge" "${sf_mirrors}"; then
59 github_mirrors
="https://github.com"
63 local origin
="$1" file="$2" destination
="$3"
67 if ! fetch_mirrored
"$origin" "$file" "$destination" "Github" "${github_mirrors}"; then
76 local origin
="$1" file="$2" destination
="$3"
80 if echo $origin |
grep ":" >/dev
/null
; then
81 protocol
=`echo $origin | cut -d':' -f1`
86 trap 'rm -f "$destination/$file".tmp; exit' SIGINT SIGKILL SIGTERM
90 if ! wget
-t 5 -T 15 -c "$origin/$file" -O "$destination/$file".tmp
; then
93 mv "$destination/$file".tmp
"$destination/$file"
95 rm -f "$destination/$file".tmp
98 if ! fetch_gnu
"${origin:${#protocol}+3}" "$file" "$destination"; then
103 if ! fetch_sf
"${origin:${#protocol}+3}" "$file" "$destination"; then
108 if ! fetch_github
"${origin:${#protocol}+3}" "$file" "$destination"; then
113 if test "$origin" = "$destination"; then
114 ! test -f "$origin/$file" && ret
=false
116 if ! cp "$origin/$file" "$destination/$file".tmp
; then
119 mv "$destination/$file".tmp
"$destination/$file"
125 trap SIGINT SIGKILL SIGTERM
132 local origins
="$1" file="$2" destination
="$3"
133 for origin
in $origins; do
134 echo "Trying $origin/$file..."
135 fetch
"$origin" "$file" "$destination" && return 0
143 local origins
="$1" file="$2" suffixes
="$3" destination
="$4" foundvar
="$5"
146 foundvar
=${foundvar:-__dummy__}
150 test -e "$destination" -a ! -d "$destination" && \
151 echo "fetch_cached: \`$destination' is not a diretory." && return 1
153 if ! test -e "$destination"; then
154 echo "fetch_cached: \`$destination' does not exist. Making it."
155 ! mkdir
-p "$destination" && return 1
158 if test "x$suffixes" != "x"; then
159 for sfx
in $suffixes; do
160 fetch_multiple
"$destination" "$file".
$sfx "$destination" && \
161 export $foundvar="$file".
$sfx && return 0
164 for sfx
in $suffixes; do
165 fetch_multiple
"$origins" "$file".
$sfx "$destination" && \
166 export $foundvar="$file".
$sfx && return 0
169 fetch_multiple
"$destination $origins" "$file" "$destination" && \
170 export $foundvar="$file" && return 0
185 local location
="$1" archive
="$2" archivepath
="$3";
190 echo "Unpacking \`$archive'..."
195 if ! tar xfj
"$archivepath/$archive"; then ret
=false
; fi
198 if ! tar xfz
"$archivepath/$archive"; then ret
=false
; fi
201 if ! unzip "$archivepath/$archive"; then ret
=false
; fi
204 if ! tar xfJ
"$archivepath/$archive"; then ret
=false
; fi
207 echo "Unknown archive format for \`$archive'."
219 local location
="$1" archive
="$2" archivepath
="$3";
221 if ! test -e "$location"; then
222 echo "unpack_cached: \`$location' does not exist. Making it."
223 ! mkdir
-p "$location" && return 1
226 if ! test -f ${location}/.
${archive}.unpacked
; then
227 if unpack
"$location" "$archive" "$archivepath"; then
228 echo yes > ${location}/.
${archive}.unpacked
238 local location
="$1" patch_spec
="$2";
242 local abs_location
="$PWD"
244 local patch=`echo "$patch_spec": | cut -d: -f1`
245 local subdir
=`echo "$patch_spec": | cut -d: -f2`
246 local patch_opt
=`echo "$patch_spec": | cut -d: -f3 | sed -e "s/,/ /g"`
252 if ! patch $patch_opt < $abs_location/$patch; then
263 local location
="$1" patch="$2";
265 local patchname
=`echo $patch | cut -d: -f1`
267 if test "x$patchname" != "x"; then
268 if ! test -f ${location}/.
${patchname}.applied
; then
269 if do_patch
"$location" "$patch"; then
270 echo yes > ${location}/.
${patchname}.applied
281 while test "x$1" != "x"; do
282 if test "x${1:0:1}" == "x-" -a "x${2:0:1}" == "x-"; then
287 -ao) archive_origins
="$2";;
290 -d) destination
="$2";;
291 -po) patches_origins
="$2";;
294 *) echo "fetch: Unknown option \`$1'."; usage
"$0";;
301 test -z "$archive" && usage
"$0"
303 archive_origins
=${archive_origins:-.}
304 destination
=${destination:-.}
305 location
=${location:-.}
306 patches_origins
=${patches_origins:-.}
308 fetch_cached
"$archive_origins" "$archive" "$suffixes" "$location" archive2
309 test -z "$archive2" && error
"fetch: Error while fetching the archive \`$archive'."
312 for patch in $patches; do
313 patch=`echo $patch | cut -d: -f1`
314 if test "x$patch" != "x"; then
315 if ! fetch_cached
"$patches_origins" "$patch" "" "$destination"; then
316 fetch_cached
"$patches_origins" "$patch" "tar.bz2 tar.gz zip" "$destination" patch2
317 test -z "$patch2" && error
"fetch: Error while fetching the patch \`$patch'."
318 if ! unpack_cached
"$destination" "$patch2" "$destination"; then
319 error
"fetch: Error while unpacking \`$patch2'."
325 if test "x$suffixes" != "x"; then
326 if ! unpack_cached
"$destination" "$archive" "$location"; then
327 error
"fetch: Error while unpacking \`$archive'."
331 for patch in $patches; do
332 if ! patch_cached
"$destination" "$patch"; then
333 error
"fetch: Error while applying the patch \`$patch'."