From rea-fbsd@codelabs.ru  Mon Nov 10 15:56:19 2008
Return-Path: <rea-fbsd@codelabs.ru>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 868EE1065690
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 10 Nov 2008 15:56:19 +0000 (UTC)
	(envelope-from rea-fbsd@codelabs.ru)
Received: from 0.mx.codelabs.ru (0.mx.codelabs.ru [144.206.177.45])
	by mx1.freebsd.org (Postfix) with ESMTP id 378DD8FC0A
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 10 Nov 2008 15:56:18 +0000 (UTC)
	(envelope-from rea-fbsd@codelabs.ru)
Received: from void.codelabs.ru (void.codelabs.ru [144.206.177.25])
	by 0.mx.codelabs.ru with esmtps (TLSv1:CAMELLIA256-SHA:256)
	id 1KzZ7h-000Mtc-8f for FreeBSD-gnats-submit@freebsd.org; Mon, 10 Nov 2008 18:56:17 +0300
Message-Id: <20081110155616.DA66A1AF424@void.codelabs.ru>
Date: Mon, 10 Nov 2008 18:56:16 +0300 (MSK)
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Reply-To: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [port infrastructure] implement master sites randomization
X-Send-Pr-Version: 3.113
X-GNATS-Notify: ports@freebsd.org, pav@freebsd.org, gabor@freebsd.org

>Number:         128754
>Category:       ports
>Synopsis:       bsd.port.mk: implement master sites randomization
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    portmgr
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Nov 10 16:00:09 UTC 2008
>Closed-Date:    
>Last-Modified:  Sun Nov 16 05:36:09 UTC 2008
>Originator:     Eygene Ryabinkin
>Release:        FreeBSD 7.1-PRERELEASE i386
>Organization:
Code Labs
>Environment:

System: FreeBSD 7.1-PRERELEASE i386

>Description:

Today I was hit by the very bad connectivity with twaren.net and
nchc.dl.sourceforge.net (the first site in the SF mirrors list in the
FreeBSD ports .mk files) is hosted by Taiwan REN.  So, I decided to
implement simple randomization that will enable to evenly distribute
the downloads between SF mirrors.

I had made it only for the SF mirrors, but it can be done for the other
well-known download locations as well.

>How-To-Repeat:

Look at ${PORTSDIR}/Mk/bsd.sites.mk: it uses statical assignment to
the MASTER_SITE_SOURCEFORGE.

>Fix:

The following patch works for me.  It places simple script rnd.awk to
the ${PORTSDIR}/Mk -- I don't think that this is the most appropriate
place to put it, but I can't think of another place now -- the script is
too ports-specific to put it into, for example, /usr/bin/.

--- 0001-Implement-randomization-of-main-SourceForge-sites.patch begins here ---
From d48aa3982a5ca6192fad561462c3ba9da2b38cfa Mon Sep 17 00:00:00 2001
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Date: Mon, 10 Nov 2008 18:38:01 +0300

The reasoning behind this is simple: today I had experienced very bad
connectivity with twaren.net and it is the first mirror in the list.
So, for automated upgrades of ports that are using SourceForge mirrors,
the download was very time-consuming.  Such round-robin randomization
of the download sites helps to improve the situation.

Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
---
 Mk/bsd.commands.mk |    1 +
 Mk/bsd.sites.mk    |    9 ++++++---
 Mk/rnd.awk         |   14 ++++++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)
 create mode 100644 Mk/rnd.awk

diff --git a/Mk/bsd.commands.mk b/Mk/bsd.commands.mk
index aa8bde8..0b2a58b 100644
--- a/Mk/bsd.commands.mk
+++ b/Mk/bsd.commands.mk
@@ -69,6 +69,7 @@ PASTE?=		/usr/bin/paste
 PAX?=		/bin/pax
 PRINTF?=	/usr/bin/printf
 PW?=		/usr/sbin/pw
+RANDLIST?=	${AWK} -f ${PORTSDIR}/Mk/rnd.awk
 REALPATH?=	/bin/realpath
 RM?=		/bin/rm
 RMDIR?=		/bin/rmdir
diff --git a/Mk/bsd.sites.mk b/Mk/bsd.sites.mk
index 41b3f93..bd9a2a6 100644
--- a/Mk/bsd.sites.mk
+++ b/Mk/bsd.sites.mk
@@ -1188,20 +1188,23 @@ MASTER_SITE_SAVANNAH+= \
 
 .if !defined(IGNORE_MASTER_SITE_SOURCEFORGE)
 .for mirror in nchc kent easynews ufpr umn mesh heanet
-MASTER_SITE_SOURCEFORGE+= \
+MASTER_SITES_SOURCEFORGE+= \
 	http://${mirror}.dl.sourceforge.net/sourceforge/%SUBDIR%/
 .endfor
+MASTER_SITE_SOURCEFORGE != ${RANDLIST} ${MASTER_SITES_SOURCEFORGE}
 .endif
 
 # official sf.net mirrors that don't mirror all projects, check
 # http://prdownloads.sourceforge.net/%SUBDIR%/
 .if !defined(IGNORE_MASTER_SITE_SOURCEFORGE_EXTENDED)
 .for mirror in easynews switch puzzle belnet osdn ovh keihanna
-MASTER_SITE_SOURCEFORGE_EXTENDED+= \
+MASTER_SITES_SOURCEFORGE_EXTENDED+= \
 	http://${mirror}.dl.sourceforge.net/sourceforge/%SUBDIR%/
 .endfor
-MASTER_SITE_SOURCEFORGE_EXTENDED+= \
+MASTER_SITES_SOURCEFORGE_EXTENDED+= \
 	${MASTER_SITE_SOURCEFORGE}
+MASTER_SITE_SOURCEFORGE_EXTENDED != \
+	${RANDLIST} ${MASTER_SITES_SOURCEFORGE_EXTENDED}
 .endif
 
 .if !defined(IGNORE_MASTER_SITE_SOURCEFORGE_JP)
diff --git a/Mk/rnd.awk b/Mk/rnd.awk
new file mode 100644
index 0000000..fbfcad7
--- /dev/null
+++ b/Mk/rnd.awk
@@ -0,0 +1,14 @@
+BEGIN {
+# Need to drop a couple of initial rand() values: they tend
+# to be around 0.8 - 0.9, so for fairly small array lenght
+# they will produce identical values at the beginning.
+	srand(); rand(); rand(); rand(); rand();
+	for (i = ARGC - 1; i > 0; i--) {
+		j = int(10*ARGC*rand()) % i + 1;
+		if (j == i) continue;
+		t = ARGV[i]; ARGV[i] = ARGV[j]; ARGV[j] = t;
+	}
+
+	for (i = 1; i < ARGC; i++)
+		print ARGV[i];
+}
-- 
1.6.0.3
--- 0001-Implement-randomization-of-main-SourceForge-sites.patch ends here ---
>Release-Note:
>Audit-Trail:

From: Pav Lucistnik <pav@FreeBSD.org>
To: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: ports/128754: [port infrastructure] implement master sites
	randomization
Date: Mon, 10 Nov 2008 17:07:11 +0100

 You know there already is a RANDOMIZE_MASTER_SITES variable you can put
 into your /etc/make.conf?
 
 -- 
 Pav Lucistnik <pav@oook.cz>
               <pav@FreeBSD.org>
 
 I cannot be responsible for future messages as apparently my cats have
 learned to type.

From: Max Brazhnikov <makc@issp.ac.ru>
To: bug-followup@freebsd.org, rea-fbsd@codelabs.ru
Cc:  
Subject: Re: ports/128754: [port infrastructure] implement master sites randomization
Date: Mon, 10 Nov 2008 19:51:38 +0300

 It's already implemented in bsd.port.mk,
 look for RANDOMIZE_MASTER_SITES
 
 Max

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: Pav Lucistnik <pav@FreeBSD.org>
Cc: FreeBSD-gnats-submit@FreeBSD.org
Subject: Re: ports/128754: [port infrastructure] implement master sites
	randomization
Date: Tue, 11 Nov 2008 08:54:58 +0300

 --AKkMM/tm2Mk6Yn/s
 Content-Type: multipart/mixed; boundary="Y4VYWfdFdHwFhC6D"
 Content-Disposition: inline
 
 
 --Y4VYWfdFdHwFhC6D
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Pav, good day.
 
 Mon, Nov 10, 2008 at 05:07:11PM +0100, Pav Lucistnik wrote:
 > You know there already is a RANDOMIZE_MASTER_SITES variable you can put
 > into your /etc/make.conf?
 
 Now I know ;))  Thanks for the pointer!
 
 Anyway, may be the modified awk script can be used as the drop-in
 replacement for the /usr/games/random -- not every system has games
 installed.  One can leave the current behaviour intact, but use awk
 script when /usr/games/random is unexistent.
 
 The new patch is attached.
 --=20
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual  =20
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook=20
     {_.-``-'         {_/            #
 
 --Y4VYWfdFdHwFhC6D
 Content-Type: text/x-diff; charset=koi8-r
 Content-Disposition: attachment; filename="0001-Add-awk-randomization-script.patch"
 Content-Transfer-Encoding: quoted-printable
 
 =46rom 84c116afbd5afdf1c25823bf5a5498ae695b8ae2 Mon Sep 17 00:00:00 2001
 =46rom: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 Date: Mon, 10 Nov 2008 18:38:01 +0300
 Subject: [PATCH] Add awk randomization script
 
 Currently port download sites can be randomized only if the system
 has /usr/games/random installed.  I introduce the script that acts
 as the replacement for /usr/games/random and needs no parts that are
 not exists in the base system (only AWK is needed ;))
 
 Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 ---
  Mk/bsd.port.mk |    5 ++++-
  Mk/rnd.awk     |   21 +++++++++++++++++++++
  2 files changed, 25 insertions(+), 1 deletions(-)
  create mode 100644 Mk/rnd.awk
 
 diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
 index 85ec297..078634a 100644
 --- a/Mk/bsd.port.mk
 +++ b/Mk/bsd.port.mk
 @@ -2172,8 +2172,11 @@ FETCH_CMD?=3D		${FETCH_BINARY} ${FETCH_ARGS}
  .if exists(/usr/games/random)
  RANDOM_CMD?=3D	/usr/games/random
  RANDOM_ARGS?=3D	"-w -f -"
 -_RANDOMIZE_SITES=3D	" |${RANDOM_CMD} ${RANDOM_ARGS}"
 +.else
 +RANDOM_CMD?=3D	${AWK}
 +RANDOM_ARGS?=3D	"-f ${PORTSDIR}/Mk/rnd.awk"
  .endif
 +_RANDOMIZE_SITES=3D	" |${RANDOM_CMD} ${RANDOM_ARGS}"
  .endif
 =20
  TOUCH?=3D			/usr/bin/touch
 diff --git a/Mk/rnd.awk b/Mk/rnd.awk
 new file mode 100644
 index 0000000..cc7e60d
 --- /dev/null
 +++ b/Mk/rnd.awk
 @@ -0,0 +1,21 @@
 +BEGIN {
 +	count =3D 0;
 +}
 +{
 +	for (i =3D 1; i <=3D NF; i++)
 +		array[count++] =3D $i;
 +}
 +END {
 +# Need to drop a couple of initial rand() values: they tend
 +# to be around 0.8 - 0.9, so for fairly small array lenght
 +# they will produce identical values at the beginning.
 +	srand(); rand(); rand(); rand(); rand();
 +	for (i =3D count - 1; i > 0; i--) {
 +		j =3D int(10*count*rand()) % i;
 +		if (j =3D=3D i) continue;
 +		t =3D array[i]; array[i] =3D array[j]; array[j] =3D t;
 +	}
 +
 +	for (i =3D 0; i < count; i++)
 +		print array[i];
 +}
 --=20
 1.6.0.3
 
 
 --Y4VYWfdFdHwFhC6D--
 
 --AKkMM/tm2Mk6Yn/s
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.9 (FreeBSD)
 
 iEYEARECAAYFAkkZHjIACgkQthUKNsbL7Yh9GACfavtQMyMWNvStR3cUEwyoX56C
 vkAAnjbS2jitZg2V12y5EgZWWJpcJpzT
 =MvWz
 -----END PGP SIGNATURE-----
 
 --AKkMM/tm2Mk6Yn/s--

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/128754: [port infrastructure] implement master sites
	randomization
Date: Tue, 11 Nov 2008 09:51:58 +0300

 --YiEDa0DAkWCtVeE4
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Tue, Nov 11, 2008 at 08:54:58AM +0300, Eygene Ryabinkin wrote:
 > The new patch is attached.
 
 Trying to properly reattach the patch to be properly displayed
 by query-pr.cgi.
 
 --- 0001-Add-awk-randomization-script.patch begins here ---
 =46rom 84c116afbd5afdf1c25823bf5a5498ae695b8ae2 Mon Sep 17 00:00:00 2001
 =46rom: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 Date: Mon, 10 Nov 2008 18:38:01 +0300
 Subject: [PATCH] Add awk randomization script
 
 Currently port download sites can be randomized only if the system
 has /usr/games/random installed.  I introduce the script that acts
 as the replacement for /usr/games/random and needs no parts that are
 not exists in the base system (only AWK is needed ;))
 
 Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 ---
  Mk/bsd.port.mk |    5 ++++-
  Mk/rnd.awk     |   21 +++++++++++++++++++++
  2 files changed, 25 insertions(+), 1 deletions(-)
  create mode 100644 Mk/rnd.awk
 
 diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
 index 85ec297..078634a 100644
 --- a/Mk/bsd.port.mk
 +++ b/Mk/bsd.port.mk
 @@ -2172,8 +2172,11 @@ FETCH_CMD?=3D		${FETCH_BINARY} ${FETCH_ARGS}
  .if exists(/usr/games/random)
  RANDOM_CMD?=3D	/usr/games/random
  RANDOM_ARGS?=3D	"-w -f -"
 -_RANDOMIZE_SITES=3D	" |${RANDOM_CMD} ${RANDOM_ARGS}"
 +.else
 +RANDOM_CMD?=3D	${AWK}
 +RANDOM_ARGS?=3D	"-f ${PORTSDIR}/Mk/rnd.awk"
  .endif
 +_RANDOMIZE_SITES=3D	" |${RANDOM_CMD} ${RANDOM_ARGS}"
  .endif
 =20
  TOUCH?=3D			/usr/bin/touch
 diff --git a/Mk/rnd.awk b/Mk/rnd.awk
 new file mode 100644
 index 0000000..cc7e60d
 --- /dev/null
 +++ b/Mk/rnd.awk
 @@ -0,0 +1,21 @@
 +BEGIN {
 +	count =3D 0;
 +}
 +{
 +	for (i =3D 1; i <=3D NF; i++)
 +		array[count++] =3D $i;
 +}
 +END {
 +# Need to drop a couple of initial rand() values: they tend
 +# to be around 0.8 - 0.9, so for fairly small array lenght
 +# they will produce identical values at the beginning.
 +	srand(); rand(); rand(); rand(); rand();
 +	for (i =3D count - 1; i > 0; i--) {
 +		j =3D int(10*count*rand()) % i;
 +		if (j =3D=3D i) continue;
 +		t =3D array[i]; array[i] =3D array[j]; array[j] =3D t;
 +	}
 +
 +	for (i =3D 0; i < count; i++)
 +		print array[i];
 +}
 --=20
 1.6.0.3
 --- 0001-Add-awk-randomization-script.patch ends here ---
 --=20
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual  =20
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook=20
     {_.-``-'         {_/            #
 
 --YiEDa0DAkWCtVeE4
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.9 (FreeBSD)
 
 iEYEARECAAYFAkkZK44ACgkQthUKNsbL7YihmgCbBcNB9tpJodL79RJhv+DBJ57a
 jNcAoK3SVaSyymNmCxEdrVgZE9ONNvEu
 =52zH
 -----END PGP SIGNATURE-----
 
 --YiEDa0DAkWCtVeE4--

From: Pav Lucistnik <pav@FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/128754: [port infrastructure] implement master sites
	randomization
Date: Fri, 14 Nov 2008 10:47:14 +0100

 I think we can reasonably expect that /usr/games/random exists.
 If you do custom install, you should be aware of consequences.
 (Bottom line: I don't like adding a new odd looking file to Mk/)
 
 -- 
 Pav Lucistnik <pav@oook.cz>
               <pav@FreeBSD.org>
 
 The Novice rogue. A rather shifty individual

From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To: freebsd-ports@freebsd.org, bug-followup@freebsd.org
Cc:  
Subject: Re: ports/128754: [port infrastructure] implement master sites
	randomization
Date: Fri, 14 Nov 2008 23:42:14 +0300

 --CUfgB8w4ZwR/yMy5
 Content-Type: multipart/mixed; boundary="tThc/1wpZn/ma/RB"
 Content-Disposition: inline
 
 
 --tThc/1wpZn/ma/RB
 Content-Type: text/plain; charset=koi8-r
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 Tue, Nov 11, 2008 at 07:19:03PM +0300, Eygene Ryabinkin wrote:
 > > On Tue, Nov 11, 2008 at 03:23:50AM +0000, RW wrote:
 > > > On Mon, 10 Nov 2008 18:56:16 +0300 (MSK)
 > > > I think it would be sensible to seed srand from a hash of something
 > > > reproducible to make better use of caches - maybe DISTNAME+DISTVERSIO=
 N.
 > > >
 >=20
 > For the feeding the hashes: RW, do you mean HTTP caches?  In principle,
 > this is a neat idea: it will achieve load-balancing between the sites.
 > But as it will use the same master sites order for the given port, this
 > will be failing when the first download site is almost down: the
 > download will take very long.  But probably stable order of the sites
 > can be made settable via the variable, e.g.
 > RANDOMIZE_MASTER_SITE_REPRODUCIBLY.  Will it be fine?  Please, note that
 > this can be achievable only for the awk script: random(6) can not be
 > currently directed to do this.
 
 OK, I reworked the patch to add RANDOMIZE_MASTER_SITE_REPRODUCIBLY:
 it guarantees the same order of master sites for the given combination
 of the port name and version.
 
 Please, give it a shot and comment.
 
 Thanks!
 --=20
 Eygene
  _                ___       _.--.   #
  \`.|\..----...-'`   `-._.-'_.-'`   #  Remember that it is hard
  /  ' `         ,       __.--'      #  to read the on-line manual  =20
  )/' _/     \   `-_,   /            #  while single-stepping the kernel.
  `-'" `"\_  ,_.-;_.-\_ ',  fsc/as   #
      _.-'_./   {_.'   ; /           #    -- FreeBSD Developers handbook=20
     {_.-``-'         {_/            #
 
 --tThc/1wpZn/ma/RB
 Content-Type: text/x-diff; charset=koi8-r
 Content-Disposition: attachment; filename="0001-Add-awk-randomization-script.patch"
 Content-Transfer-Encoding: quoted-printable
 
 =46rom 40644084ccdb42bd34bf85cf43088c3ecb3e205f Mon Sep 17 00:00:00 2001
 =46rom: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 Date: Mon, 10 Nov 2008 18:38:01 +0300
 Subject: [PATCH] Add awk randomization script
 
 Currently port download sites can be randomized only if the system has
 /usr/games/random installed.  I introduce the script that acts as the
 replacement for /usr/games/random and needs no parts that are not exists
 in the base system (only AWK is needed ;))
 
 I had also added new directive, RANDOMIZE_MASTER_SITE_REPRODUCIBLY.  It
 applies randomization, but guarantees that the site order for the given
 portname and portversion will be the same.  Might be useful when one
 uses HTTP caching and have many FreeBSD servers behind the cache.
 
 Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 ---
  Mk/bsd.port.mk |   15 +++++++++++++--
  Mk/rnd.awk     |   26 ++++++++++++++++++++++++++
  2 files changed, 39 insertions(+), 2 deletions(-)
  create mode 100644 Mk/rnd.awk
 
 diff --git a/Mk/bsd.port.mk b/Mk/bsd.port.mk
 index 85ec297..dcc2d31 100644
 --- a/Mk/bsd.port.mk
 +++ b/Mk/bsd.port.mk
 @@ -2169,11 +2169,22 @@ FETCH_REGET?=3D	0
  FETCH_CMD?=3D		${FETCH_BINARY} ${FETCH_ARGS}
 =20
  .if defined(RANDOMIZE_MASTER_SITES)
 -.if exists(/usr/games/random)
 +.if defined(RANDOMIZE_MASTER_SITES_REPRODUCIBLY)
 +RANDOM_CMD?=3D	${AWK}
 +RANDOM_SEED!=3D	${ECHO} ${DISTNAME} | ${MD5}
 +RANDOM_ARGS?=3D	"-v value=3D'${RANDOM_SEED}' -f ${PORTSDIR}/Mk/rnd.awk"
 +.elif exists(/usr/games/random)
  RANDOM_CMD?=3D	/usr/games/random
  RANDOM_ARGS?=3D	"-w -f -"
 -_RANDOMIZE_SITES=3D	" |${RANDOM_CMD} ${RANDOM_ARGS}"
 +.else
 +RANDOM_CMD?=3D	${AWK}
 +RANDOM_ARGS?=3D	"-v value=3D'' -f ${PORTSDIR}/Mk/rnd.awk"
  .endif
 +.if defined(RANDOMIZE_MASTER_SITES_REPRODUCIBLY)
 +RANDOM_CMD?=3D	${AWK}
 +RANDOM_ARGS?=3D	"-v value=3D`echo ${DISTNAME}-${DISTVERSION} | md5` -f ${P=
 ORTSDIR}/Mk/rnd.awk"
 +.endif
 +_RANDOMIZE_SITES=3D	" |${RANDOM_CMD} ${RANDOM_ARGS}"
  .endif
 =20
  TOUCH?=3D			/usr/bin/touch
 diff --git a/Mk/rnd.awk b/Mk/rnd.awk
 new file mode 100644
 index 0000000..ce9943f
 --- /dev/null
 +++ b/Mk/rnd.awk
 @@ -0,0 +1,26 @@
 +BEGIN {
 +	count =3D 0;
 +	if (length(value) !=3D 0)
 +		srand(value);
 +	else
 +		srand();
 +}
 +{
 +	for (i =3D 1; i <=3D NF; i++)
 +		array[count++] =3D $i;
 +}
 +END {
 +# Need to drop a couple of initial rand() values: they tend
 +# to be around 0.8 - 0.9, so for fairly small array length
 +# they will produce identical values at the beginning.
 +	rand(); rand(); rand(); rand();
 +
 +	for (i =3D count - 1; i > 0; i--) {
 +		j =3D int(10*count*rand()) % i;
 +		if (j =3D=3D i) continue;
 +		t =3D array[i]; array[i] =3D array[j]; array[j] =3D t;
 +	}
 +
 +	for (i =3D 0; i < count; i++)
 +		print array[i];
 +}
 --=20
 1.6.0.3
 
 
 --tThc/1wpZn/ma/RB
 Content-Type: text/x-diff; charset=koi8-r
 Content-Disposition: attachment; filename="0001-ports-7-document-new-option-RANDOMIZE_MASTER_SITES.patch"
 Content-Transfer-Encoding: quoted-printable
 
 =46rom ffcaf1247756f403dc1e7308b1c68f6d6fcea524 Mon Sep 17 00:00:00 2001
 =46rom: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 Date: Fri, 14 Nov 2008 23:33:39 +0300
 Subject: [PATCH] ports(7): document new option RANDOMIZE_MASTER_SITES_REPRO=
 DUCIBLY
 
 Applies master site randomization, but guarantees that for the given
 combination of the port name and version, the order of the download
 sites will be the same at the each invocation.
 
 Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
 ---
  share/man/man7/ports.7 |    6 ++++++
  1 files changed, 6 insertions(+), 0 deletions(-)
 
 diff --git a/share/man/man7/ports.7 b/share/man/man7/ports.7
 index 7f8fb07..08c109b 100644
 --- a/share/man/man7/ports.7
 +++ b/share/man/man7/ports.7
 @@ -420,6 +420,12 @@ Try going to these sites for all files and patches, fi=
 rst.
  Try going to these sites for all files and patches, last.
  .It Va RANDOMIZE_MASTER_SITES
  Try the download locations in a random order.
 +.It Va RANDOMIZE_MASTER_SITES_REPRODUCIBLY
 +Try the download locations in a random order, but keep the same order
 +for each combination of port name and version.
 +Useful if you have a bunch of hosts that are sitting behind the
 +HTTP cache and you want to save some traffic, but still want to
 +randomize the list of master sites.
  .It Va MASTER_SORT
  Sort the download locations according to user supplied pattern.
  Example:
 --=20
 1.6.0.3
 
 
 --tThc/1wpZn/ma/RB--
 
 --CUfgB8w4ZwR/yMy5
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.9 (FreeBSD)
 
 iEYEARECAAYFAkkd4qUACgkQthUKNsbL7YheFwCeJWnhgk8bMTw5xdzrX+hjTVHo
 Y0EAnRIr8OubMchkXjuqdqlOFD0DPE/8
 =xBZi
 -----END PGP SIGNATURE-----
 
 --CUfgB8w4ZwR/yMy5--
Responsible-Changed-From-To: freebsd-ports-bugs->portmgr 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Sun Nov 16 05:36:08 UTC 2008 
Responsible-Changed-Why:  
bsd.port.mk is portmgr territory (via the GNATS Auto Assign Tool) 

http://www.freebsd.org/cgi/query-pr.cgi?pr=128754 
>Unformatted:
