From 2dee8e17ce94c29744a8d097b2bf6b3165f52659 Mon Sep 17 00:00:00 2001 From: Matt Housh Date: Sun, 2 Dec 2007 12:25:25 -0600 Subject: [PATCH] added PKGMK_SOURCE_MIRRORS support --- pkgmk.conf | 1 + pkgmk.in | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/pkgmk.conf b/pkgmk.conf index 6e70f1b..5d76a6a 100644 --- a/pkgmk.conf +++ b/pkgmk.conf @@ -5,6 +5,7 @@ export CFLAGS="-O2 -march=i686 -pipe" export CXXFLAGS="-O2 -march=i686 -pipe" +# PKGMK_SOURCE_MIRRORS=() # PKGMK_SOURCE_DIR="$PWD" # PKGMK_PACKAGE_DIR="$PWD" # PKGMK_WORK_DIR="$PWD/work" diff --git a/pkgmk.in b/pkgmk.in index 67425e0..da9b303 100755 --- a/pkgmk.in +++ b/pkgmk.in @@ -43,6 +43,11 @@ get_filename() { echo $FILE } +get_basename() { + local FILE="`echo $1 | sed 's|^.*://.*/||g'`" + echo $FILE +} + check_pkgfile() { if [ ! "$name" ]; then error "Variable 'name' not specified in $PKGMK_PKGFILE." @@ -82,25 +87,40 @@ download_file() { LOCAL_FILENAME=`get_filename $1` LOCAL_FILENAME_PARTIAL="$LOCAL_FILENAME.partial" - DOWNLOAD_CMD="--passive-ftp --no-directories --tries=3 --waitretry=3 \ - --directory-prefix=$PKGMK_SOURCE_DIR --output-document=$LOCAL_FILENAME_PARTIAL $1" + DOWNLOAD_OPTS="--passive-ftp --no-directories --tries=3 --waitretry=3 \ + --directory-prefix=$PKGMK_SOURCE_DIR \ + --output-document=$LOCAL_FILENAME_PARTIAL" if [ -f "$LOCAL_FILENAME_PARTIAL" ]; then info "Partial download found, trying to resume" RESUME_CMD="-c" fi - while true; do - wget $RESUME_CMD $DOWNLOAD_CMD + error=1 + + BASENAME=`get_basename $1` + for REPO in ${PKGMK_SOURCE_MIRRORS[@]}; do + REPO="`echo $REPO | sed 's|/$||'`" + wget $RESUME_CMD $DOWNLOAD_OPTS $REPO/$BASENAME error=$? - if [ $error != 0 ] && [ "$RESUME_CMD" ]; then - info "Partial download failed, restarting" - rm -f "$LOCAL_FILENAME_PARTIAL" - RESUME_CMD="" - else + if [ $error == 0 ]; then break fi done + + if [ $error != 0 ]; then + while true; do + wget $RESUME_CMD $DOWNLOAD_OPTS $1 + error=$? + if [ $error != 0 ] && [ "$RESUME_CMD" ]; then + info "Partial download failed, restarting" + rm -f "$LOCAL_FILENAME_PARTIAL" + RESUME_CMD="" + else + break + fi + done + fi if [ $error != 0 ]; then error "Downloading '$1' failed." @@ -633,6 +653,7 @@ PKGMK_FOOTPRINT=".footprint" PKGMK_MD5SUM=".md5sum" PKGMK_NOSTRIP=".nostrip" +PKGMK_SOURCE_MIRRORS=() PKGMK_SOURCE_DIR="$PWD" PKGMK_PACKAGE_DIR="$PWD" PKGMK_WORK_DIR="$PWD/work" -- 2.26.2