diff --git a/scripts/pkgmeek b/scripts/pkgmeek index 9eaf54a..74ceecf 100755 --- a/scripts/pkgmeek +++ b/scripts/pkgmeek @@ -70,8 +70,7 @@ here="${_local_[$u]}"; url="${source[$u]}"; # appropriate name in the current directory [ -e "$here" ] || [ "$src_dir" = "" ] || [ ! -e "$src_dir/$here" ] || ln -sf "$src_dir/$here" ; [ -e "$here" ] || [ ! -e "$PKGMK_ROOT/$here" ] || ln -sf "$PKGMK_ROOT/$here" . ; -[ -e "$here" ] || fetch_source "$url" "$here"; -# but if not, exit with an informative error message +[ -e "$here" ] || fetch_source "$url" "$here"; # <-- should also be able to resume partial downloads [ -e "$here" ] || { error "failed to download $here. Check connection and try again."; errDL+=1; } done ; } @@ -366,28 +365,40 @@ check_pkg_mtime() { # can be called even if some sources are missing } fetch_source() { - local u="$1"; local h="$2"; local SAVE_AS OCONTINUE OOUT; + local u="$1"; local h="$2"; local m=0; local REPO SAVE_AS OCONTINUE OOUT; local finished=0; # Determine whether git can be used to obtain sources - PKGMK_GIT_COMMAND="/usr/bin/git" + local PKGMK_GIT_COMMAND="/usr/bin/git" [ -x "$PKGMK_GIT_COMMAND" ] || PKGMK_GIT_COMMAND="/bin/false" - [[ $u =~ ^(https|http|ssh|git)://.*/(.+)\.git$ ]] && SAVE_AS="$PKGMK_GIT_COMMAND clone $u" + [[ $u =~ ^(https|http|ssh|git)://.*/(.+)\.git$ ]] && \ + { "$PKGMK_GIT_COMMAND clone $u $h"; return $?; } - [[ "$PKGMK_DOWNLOAD_PROG" =~ wget$ ]] && { OCONTINUE="-c"; OOUT="-O"; } - [[ "$PKGMK_DOWNLOAD_PROG" =~ curl$ ]] && { OCONTINUE="-C -"; OOUT="-o"; } + [[ "$PKGMK_DOWNLOAD_PROG" =~ wget$ ]] && { OCONTINUE="-c"; OOUT="$PKGMK_WGET_OPTIONS -O"; } + [[ "$PKGMK_DOWNLOAD_PROG" =~ curl$ ]] && { OCONTINUE="-C -"; OOUT="$PKGMK_CURL_OPTIONS -o"; } [[ "$PKGMK_DOWNLOAD_PROG" =~ (wget|curl)$ ]] || SAVE_AS=/bin/false - [ -s "$src_dir/$h.partial" ] && { ln -s "$src_dir/$h.partial" . ; - SAVE_AS="$PKGMK_DOWNLOAD_PROG $u $OCONTINUE $OOUT"; } \ - || SAVE_AS="$PKGMK_DOWNLOAD_PROG $u $OOUT" + while [ $m -le ${#PKGMK_SOURCE_MIRRORS[@]} ] && [ $finished = 0 ] && [[ ! $SAVE_AS =~ false$ ]]; do + # when the index goes past the last element of PKGMK_SOURCE_MIRRORS, + # switch to using the url in the 'source' array. + [ "${PKGMK_SOURCE_MIRRORS[m]}" = "" ] && um=$u || \ + { REPO=$(echo ${PKGMK_SOURCE_MIRRORS[m]} | sed 's,/$,,'); + um=$REPO/$(echo $u | sed 's,.*/,,'); } + m=$(( m+1 )) - if $SAVE_AS "$h.partial"; then - [ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] || { mv "$h.partial" "$src_dir/$h"; - ln -sf "$src_dir/$h" . ; } - else # an interrupted download should not have its efforts destroyed by cleanup_work() - [ ! -e "$h.partial" ] || [ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] \ - || mv "$h.partial" "$src_dir" - fi + # interrupted downloads from a previous run should be put where wget or curl will find them + [ -s "$src_dir/$h.partial" ] && { ln -s "$src_dir/$h.partial" . ; + SAVE_AS="$PKGMK_DOWNLOAD_PROG $um $OCONTINUE $OOUT"; } \ + || SAVE_AS="$PKGMK_DOWNLOAD_PROG $um $OOUT" + + if $SAVE_AS "$h.partial"; then + finished=1 + [ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] || { mv "$h.partial" "$src_dir/$h"; + ln -sf "$src_dir/$h" . ; } + else # an interrupted download should not have its efforts destroyed by cleanup_work() + [ ! -e "$h.partial" ] || [ "$src_dir" = "" ] || [ ! -w "$src_dir"/ ] \ + || mv "$h.partial" "$src_dir" + fi + done } cat_manifest() {