diff options
-rw-r--r-- | rules/archive.mk | 5 | ||||
-rw-r--r-- | rules/common.mk | 5 | ||||
-rwxr-xr-x | scripts/download-archive | 41 |
3 files changed, 39 insertions, 12 deletions
diff --git a/rules/archive.mk b/rules/archive.mk index 411ca27..12dd6d7 100644 --- a/rules/archive.mk +++ b/rules/archive.mk @@ -43,12 +43,13 @@ validate: validate-stamp archive-downloader := /usr/share/cibs/scripts/download-archive +downloader-mirrors = $(mirrors:%=-m %) download-%-stamp: if ! [ -f '$*' ]; then \ if [ -n '$(download_$*)' ]; then \ - $(archive-downloader) '$*' '$(download_$*)'; \ + $(archive-downloader) -a '$*' $(downloader-mirrors) -d '$(download_$*)'; \ elif [ -n '$(download)' ]; then \ - $(archive-downloader) '$*' '$(download)'; \ + $(archive-downloader) -a '$*' $(downloader-mirrors) -d '$(download)'; \ else \ echo '** ERROR: No "dowload" variable is set'; false; \ fi; \ diff --git a/rules/common.mk b/rules/common.mk index c0d1c6c..afbe0cb 100644 --- a/rules/common.mk +++ b/rules/common.mk @@ -53,11 +53,6 @@ export PATH := \ /usr/gcc/4.4/bin:/usr/gcc/4.3/bin:/usr/gnu/bin:/usr/sbin:/usr/bin:/sbin export CFLAGS = -O2 -# Define LOCAL_MIRROR in environment, e. g. in ~/.bash_profile: -mirrors := $(LOCAL_MIRROR) \ - http://mirror.yandex.ru/gentoo-distfiles/distfiles \ - http://mirror.ovh.net/gentoo-distfiles/distfiles - prefix = /usr libdir.32 = $(prefix)/lib/$(mach32) libdir.64 = $(prefix)/lib/$(mach64) diff --git a/scripts/download-archive b/scripts/download-archive index a32d052..c4aa965 100755 --- a/scripts/download-archive +++ b/scripts/download-archive @@ -8,18 +8,49 @@ fatal () { exit 1 } -archive="$1" -url="$2" -shift 2 +archive='' +download='' +mirrors='' + +while getopts m:a:d: opt; do + case $opt in + m) mirrors="$mirrors $OPTARG";; + a) archive="$OPTARG";; + d) download="$OPTARG";; + *) fatal "Unknown option: $opt";; + esac +done +shift `expr $OPTIND - 1` + wget=`type -p wget || true` curl=`type -p curl || true` +download_wget () { + (set -x; $wget -O "$1" "$2") || rm -f "$1" +} + +download_curl () { + (set -x $curl -L -v "$2" > "$1") || rm -f "$1" +} + + +download_tool='' if [ -n "$wget" ]; then - $wget -O "$archive" "$url" || ( rm -f "$archive"; fatal "download failed" ) + download_tool=download_wget elif [ -n "$curl" ]; then - $curl -L -v "$url" > "$archive" || ( rm -f "$archive"; fatal "download failed" ) + download_tool=download_curl else fatal "Don't know how to download" fi +for m in $mirrors; do + $download_tool "$archive" "$m/$archive" + [ ! -e "$archive" ] || break; +done + +[ -e "$archive" ] || $download_tool "$archive" "$download" +[ -e "$archive" ] || fatal "Failed to get \`$archive'" + +exit 0 + |