Subject: Proposal: Sort order for MASTER_SITES
To: None <tech-pkg@netbsd.org>
From: Martin J. Laubach <mjl@emsi.priv.at>
List: tech-pkg
Date: 06/17/1999 02:35:11
  This has been on my wishlist for quite some time...

  The problem is that the MASTER_SITES list is in some arbitrary
order, and very probably far from optimal in terms of using the
topologically nearest mirror. For MASTER_SITE_{XCONTRIB,GNU,PERL_CPAN}
etc. this can be set, but a more general approach seems appropriate.

  Rene and I have worked out a small addition to bsd.pkg.mk which
allows for sorting the MASTER_SITES list according to some given
preference, based on regular expressions.

  To define the sort order, define a list of regular expressions
in order of decreasing preference, like this

	MASTER_SORT= //.*\.at\.netbsd\.org/ //.*\.at/ //.*\.(de|ch)/

  and the MASTER_SITES list will be adjusted accordingly.

  Comments?

	mjl


===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.mk,v
retrieving revision 1.280
diff -a -b -u -r1.280 bsd.pkg.mk
--- bsd.pkg.mk	1999/05/30 16:09:30	1.280
+++ bsd.pkg.mk	1999/06/17 00:22:29
@@ -836,11 +836,24 @@
 		exit 1;							\
 	fi
 
+#
+# Sort the master site list according to the patterns in MASTER_SORT
+#
+# MASTER_SORT= //.*\.at\.netbsd\.org/ //.*\.at/ 
+MASTER_SORT?=
+
+MASTER_SORT_AWK= BEGIN { RS = " "; ORS = " "; gl = "${MASTER_SORT}"; }
+.for srt in ${MASTER_SORT}
+MASTER_SORT_AWK+= /${srt:C/\//\\\//g}/ { good["${srt}"] = good["${srt}"] " " $$0 ; next; } 
+.endfor
+MASTER_SORT_AWK+= { rest = rest " " $$0; } END { split(gl, gla); for(x in gla) { print good[gla[x]] " "; } print rest; } 
+SORTED_MASTER_SITES=`echo ${MASTER_SITES} | awk '${MASTER_SORT_AWK}'`
+
 .if !target(do-fetch)
 do-fetch:
 	${_PKG_SILENT}${_PKG_DEBUG}${MKDIR} ${_DISTDIR}
 	${_PKG_SILENT}(${_PKG_DEBUG}cd ${_DISTDIR};			\
-	 sites="${MASTER_SITES}";					\
+	 sites="${SORTED_MASTER_SITES}";				\
 	 for file in "" ${_DISTFILES}; do				\
 		if [ "X$$file" = X"" ]; then continue; fi;		\
 		${_FETCH_FILE}						\



===================================================================