CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
added PKGMK_SOURCE_MIRRORS support
[pkgutils-cross.git] / pkgmk.in
index 62a74188f61c2bd1340128f106b277bec9e7c6d7..da9b3036627496fcbaf98c59062d26aa73653b7e 100755 (executable)
--- a/pkgmk.in
+++ b/pkgmk.in
@@ -3,6 +3,7 @@
 #  pkgutils
 # 
 #  Copyright (c) 2000-2005 Per Liden
+#  Copyright (c) 2006-2007 by CRUX team (http://crux.nu)
 # 
 #  This program is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
@@ -25,11 +26,11 @@ info() {
 }
 
 warning() {
-       info "WARNING: $1"
+       info "WARNING: $1" >&2
 }
 
 error() {
-       info "ERROR: $1"
+       info "ERROR: $1" >&2
 }
 
 get_filename() {
@@ -42,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."
@@ -81,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."
@@ -194,7 +215,7 @@ check_md5sum() {
                        sed 's/^-/MISSING   /g' > $FILE.md5sum.diff
                if [ -s $FILE.md5sum.diff ]; then
                        error "Md5sum mismatch found:"
-                       cat $FILE.md5sum.diff
+                       cat $FILE.md5sum.diff >&2
 
                        if [ "$PKGMK_KEEP_WORK" = "no" ]; then
                                rm -rf $PKGMK_WORK_DIR
@@ -242,13 +263,16 @@ strip_files() {
        fi
 
        find . -type f -printf "%P\n" | $FILTER | while read FILE; do
-               if file -b "$FILE" | grep '^.*ELF.*executable.*not stripped$' &> /dev/null; then
+               case $(file -b "$FILE") in
+               *ELF*executable*not\ stripped)
                        strip --strip-all "$FILE"
-               elif file -b "$FILE" | grep '^.*ELF.*shared object.*not stripped$' &> /dev/null; then
+                       ;;
+               *ELF*shared\ object*not\ stripped)
                        strip --strip-unneeded "$FILE"
-               elif file -b "$FILE" | grep '^current ar archive$' &> /dev/null; then
+                       ;;
+               current\ ar\ archive)
                        strip --strip-debug "$FILE"
-               fi
+               esac
        done
 }
 
@@ -294,7 +318,7 @@ check_footprint() {
                                sed 's/^-/MISSING   /g' > $FILE.footprint.diff
                        if [ -s $FILE.footprint.diff ]; then
                                error "Footprint mismatch found:"
-                               cat $FILE.footprint.diff
+                               cat $FILE.footprint.diff >&2
                                BUILD_SUCCESSFUL="no"
                        fi
                else
@@ -629,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"