3 # Copyright © 2004-2017, 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://mirror.netcologne.de/gnu http://ftp.gnu.org/pub/gnu ftp://ftp.heanet.ie/pub/gnu ftp://mirror.jre655.com/GNU"
33 local origin
="$1" file="$2" destination
="$3"
37 if ! fetch_mirrored
"$origin" "${file}" "$destination" "GNU" "${gnu_mirrors}"; then
44 # Note: at time of writing, the main SF download server redirects to mirrors
45 # and corrects moved paths, so we retry this server multiple times (in one
47 sf_mirrors
="http://downloads.sourceforge.net"
51 local origin
="$1" file="$2" destination
="$3"
55 if ! fetch_mirrored
"$origin" "${file}" "$destination" "SourceForge" "${sf_mirrors}"; then
62 github_mirrors
="https://github.com"
66 local origin
="$1" file="$2" destination
="$3"
70 if ! fetch_mirrored
"$origin" "$file" "$destination" "Github" "${github_mirrors}"; then
79 local origin
="$1" file="$2" destination
="$3"
83 if echo $origin |
grep ":" >/dev
/null
; then
84 protocol
=`echo $origin | cut -d':' -f1`
89 trap 'rm -f "$destination/$file".tmp; exit' SIGINT SIGKILL SIGTERM
93 if ! wget
-t 3 --retry-connrefused -T 15 -c "$origin/$file" -O "$destination/$file".tmp
; then
96 mv "$destination/$file".tmp
"$destination/$file"
98 rm -f "$destination/$file".tmp
101 if ! fetch_gnu
"${origin:${#protocol}+3}" "$file" "$destination"; then
106 if ! fetch_sf
"${origin:${#protocol}+3}" "$file" "$destination"; then
111 if ! fetch_github
"${origin:${#protocol}+3}" "$file" "$destination"; then
116 if test "$origin" = "$destination"; then
117 ! test -f "$origin/$file" && ret
=false
119 if ! cp "$origin/$file" "$destination/$file".tmp
; then
122 mv "$destination/$file".tmp
"$destination/$file"
128 trap SIGINT SIGKILL SIGTERM
135 local origins
="$1" file="$2" destination
="$3"
136 for origin
in $origins; do
137 echo "Trying $origin/$file..."
138 fetch
"$origin" "$file" "$destination" && return 0
146 local origins
="$1" file="$2" suffixes
="$3" destination
="$4" foundvar
="$5"
149 foundvar
=${foundvar:-__dummy__}
153 test -e "$destination" -a ! -d "$destination" && \
154 echo "fetch_cached: \`$destination' is not a diretory." && return 1
156 if ! test -e "$destination"; then
157 echo "fetch_cached: \`$destination' does not exist. Making it."
158 ! mkdir
-p "$destination" && return 1
161 if test "x$suffixes" != "x"; then
162 for sfx
in $suffixes; do
163 fetch_multiple
"$destination" "$file".
$sfx "$destination" && \
164 export $foundvar="$file".
$sfx && return 0
167 for sfx
in $suffixes; do
168 fetch_multiple
"$origins" "$file".
$sfx "$destination" && \
169 export $foundvar="$file".
$sfx && return 0
172 fetch_multiple
"$destination $origins" "$file" "$destination" && \
173 export $foundvar="$file" && return 0
188 local location
="$1" archive
="$2" archivepath
="$3";
193 echo "Unpacking \`$archive'..."
198 if ! tar xfj
"$archivepath/$archive"; then ret
=false
; fi
201 if ! tar xfz
"$archivepath/$archive"; then ret
=false
; fi
204 if ! unzip "$archivepath/$archive"; then ret
=false
; fi
207 if ! tar xfJ
"$archivepath/$archive"; then ret
=false
; fi
210 echo "Unknown archive format for \`$archive'."
222 local location
="$1" archive
="$2" archivepath
="$3";
224 if ! test -e "$location"; then
225 echo "unpack_cached: \`$location' does not exist. Making it."
226 ! mkdir
-p "$location" && return 1
229 if ! test -f ${location}/.
${archive}.unpacked
; then
230 if unpack
"$location" "$archive" "$archivepath"; then
231 echo yes > ${location}/.
${archive}.unpacked
241 local location
="$1" patch_spec
="$2";
245 local abs_location
="$PWD"
247 local patch=`echo "$patch_spec": | cut -d: -f1`
248 local subdir
=`echo "$patch_spec": | cut -d: -f2`
249 local patch_opt
=`echo "$patch_spec": | cut -d: -f3 | sed -e "s/,/ /g"`
255 if ! patch $patch_opt < $abs_location/$patch; then
266 local location
="$1" patch="$2";
268 local patchname
=`echo $patch | cut -d: -f1`
270 if test "x$patchname" != "x"; then
271 if ! test -f ${location}/.
${patchname}.applied
; then
272 if do_patch
"$location" "$patch"; then
273 echo yes > ${location}/.
${patchname}.applied
284 while test "x$1" != "x"; do
285 if test "x${1:0:1}" == "x-" -a "x${2:0:1}" == "x-"; then
290 -ao) archive_origins
="$2";;
293 -d) destination
="$2";;
294 -po) patches_origins
="$2";;
297 *) echo "fetch: Unknown option \`$1'."; usage
"$0";;
304 test -z "$archive" && usage
"$0"
306 archive_origins
=${archive_origins:-.}
307 destination
=${destination:-.}
308 location
=${location:-.}
309 patches_origins
=${patches_origins:-.}
311 fetch_cached
"$archive_origins" "$archive" "$suffixes" "$location" archive2
312 test -z "$archive2" && error
"fetch: Error while fetching the archive \`$archive'."
315 for patch in $patches; do
316 patch=`echo $patch | cut -d: -f1`
317 if test "x$patch" != "x"; then
318 if ! fetch_cached
"$patches_origins" "$patch" "" "$destination"; then
319 fetch_cached
"$patches_origins" "$patch" "tar.bz2 tar.gz zip" "$destination" patch2
320 test -z "$patch2" && error
"fetch: Error while fetching the patch \`$patch'."
321 if ! unpack_cached
"$destination" "$patch2" "$destination"; then
322 error
"fetch: Error while unpacking \`$patch2'."
328 if test "x$suffixes" != "x"; then
329 if ! unpack_cached
"$destination" "$archive" "$location"; then
330 error
"fetch: Error while unpacking \`$archive'."
334 for patch in $patches; do
335 if ! patch_cached
"$destination" "$patch"; then
336 error
"fetch: Error while applying the patch \`$patch'."