Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 11 Feb 2003 08:17:12 +0900
From:      Kimura Fuyuki <fuyuki@hadaly.org>
To:        seanc@FreeBSD.ORG
Cc:        ports@FreeBSD.ORG
Subject:   Re: Randomizing master sites for distfile downloads...
Message-ID:  <86r8afohdz.wl%fuyuki@hadaly.org>
In-Reply-To: <86smuvohuo.wl%fuyuki@hadaly.org>
References:  <20030210021953.GT15936@perrin.int.nxad.com> <86smuvohuo.wl%fuyuki@hadaly.org>

next in thread | previous in thread | raw e-mail | index | archive | help
At Tue, 11 Feb 2003 08:07:11 +0900,
Kimura Fuyuki <fuyuki@hadaly.org> wrote:
> 
> Isn't it enough just to leave open the possibility that the users
> could define their own sites sorter/randomizer? (cf. ports/20678)

And an example of such a sorter...

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	geosort
#	geosort/Makefile
#	geosort/pkg-comment
#	geosort/pkg-descr
#	geosort/pkg-plist
#	geosort/files
#	geosort/files/geosort
#
echo c - geosort
mkdir -p geosort > /dev/null 2>&1
echo x - geosort/Makefile
sed 's/^X//' >geosort/Makefile << 'END-of-geosort/Makefile'
X# New ports collection makefile for:   geosort
X# Date created:                17 September 2002
X# Whom:                        Kimura Fuyuki <fuyuki@hadaly.org>
X#
X# $FreeBSD$
X#
X
XPORTNAME=	geosort
XPORTVERSION=	1.0
XCATEGORIES=	misc
XMASTER_SITES=	# none
XDISTFILES=	# none
X
XMAINTAINER=	fuyuki@hadaly.org
X
XRUN_DEPENDS=	geoiplookup:${PORTSDIR}/net/GeoIP
X
XUSE_RUBY=	yes
XRUBY_SHEBANG_FILES=	${WRKSRC}/geosort
XNO_BUILD=	yes
X
Xdo-extract:
X	${MKDIR} ${WRKSRC}
X	${CP} ${FILESDIR}/geosort ${WRKSRC}
X
Xdo-install:
X	${INSTALL_SCRIPT} ${WRKSRC}/geosort ${PREFIX}/sbin
X
X.include <bsd.port.mk>
END-of-geosort/Makefile
echo x - geosort/pkg-comment
sed 's/^X//' >geosort/pkg-comment << 'END-of-geosort/pkg-comment'
XA site sorter using GeoIP
END-of-geosort/pkg-comment
echo x - geosort/pkg-descr
sed 's/^X//' >geosort/pkg-descr << 'END-of-geosort/pkg-descr'
Xgeosort can be used to sort the master and patch sites according to a
Xpreference order for the country codes.  GeoIP is used for obtaining
Xthe countries of the sites.
X
X- Kimura Fuyuki
Xfuyuki@hadaly.org
END-of-geosort/pkg-descr
echo x - geosort/pkg-plist
sed 's/^X//' >geosort/pkg-plist << 'END-of-geosort/pkg-plist'
Xsbin/geosort
END-of-geosort/pkg-plist
echo c - geosort/files
mkdir -p geosort/files > /dev/null 2>&1
echo x - geosort/files/geosort
sed 's/^X//' >geosort/files/geosort << 'END-of-geosort/files/geosort'
X#!/usr/local/bin/ruby -w
X#
X# geosort - a site sorter using GeoIP
X#
X# Usage: geosort <country codes>
X#
X# e.g. add `SORT_SITES_CMD=geosort JP KR US CA' to /etc/make.conf.
X#
X
Xrequire 'getopts'
Xrequire 'uri'
X
Xclass Array
X  def select!
X    result = select { |o| yield(o) }
X    reject! { |o| yield(o) }
X    result
X  end
Xend
X
Xgetopts 'dv'
X
Xsites = []
Xwhile $stdin.gets
X  sites.concat split
Xend
X
Xthreads = []
Xcountries = {}
X
Xsplit.each { |site|
X  Thread.start {
X    host = URI.parse(site).host
X    if host
X      cc = `geoiplookup #{host}`.chop
X      countries[site] = cc
X      $stderr.print "#{cc}: #{site}\n" if $OPT_v
X      $stderr.print "Couldn't determine the country: #{host}\n" if cc == '--'
X    end
X  }
X}
X
X$stderr.print "Waiting for the replies...\n" if $OPT_v
X(ThreadGroup::Default.list - [Thread.current]).each { |t| t.join }
X
Xsites.reject! { |site| countries[site] == '--' } if $OPT_d
X
Xgood = []
XARGV.each { |cc|
X  good.concat sites.select! { |site| countries[site] == cc.upcase }
X}
Xgood.concat sites
X
Xprint good.join(' '), "\n"
X$stderr.print "RESULT:\t", good.join("\n\t"), "\n" if $OPT_v
END-of-geosort/files/geosort
exit

-- fuyuki


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86r8afohdz.wl%fuyuki>