This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: where is setup.exe source?

Brian Dessent wrote:

> Maybe a starting point would be a awk[1] script that lives in the
> base-files package that grabs mirrors.lst and downloads some relatively
> small package from every mirror, and generates a report.  That way, we
> could at least say "try running mirror-check.awk" when users have
> problems with mirrors, rather than just "play around until you find a
> mirror you like."

Here is a first stab at such a script.  It gets mirrors.lst and then downloads
setup.bz2 from each http mirror and reports the elapsed time.  It doesn't sort
the results or anything, but I just wanted to see if it was possible to do this
in gawk.

#!/usr/bin/awk -f

    CygwinSite = "/inet/tcp/0/"
    MirrorsUrl = "";
    RS = ORS = "\r\n\r\n"

    print "GET " MirrorsUrl " HTTP/1.0" |& CygwinSite
    CygwinSite |& getline Header
    if (Header !~ /^HTTP\/1\.[10] 2[0-9][0-9]/) {
        printf "Error fetching %s. Response was:\n%s\n", MirrorsUrl, Header

    RS = ORS = "\n"
    while ((CygwinSite |& getline Mirror) > 0) {
        split(Mirror, Fields, ";")
        if (Fields[1] ~ /^http:\/\//) {

            AwkFetch = "/bin/time /bin/awk 'BEGIN { site = \"/inet/tcp/0/" \
              Fields[2] "/80\"; RS = ORS = \"\\r\\n\\r\\n\"; print \"GET " \
              Fields[1] "/setup.bz2 HTTP/1.0\" |& site; while " \
              "((site |& getline) > 0); close (site); }' 2>&1"

            while((AwkFetch | getline Output) > 0) {
                if (match(Output, /([0-9]+:[0-9]+\.[0-9]+)elapsed/, Elap)) {
                    printf "Mirror %s (located in %s, %s) time %s\n", \
                           Fields[2], Fields[4], Fields[3], Elap[1]

Obviously this is pretty rough (no ftp: support, assumes port :80 instead of
parsing it from the URL, etc.)  And it would be a lot prettier in perl or
something but the whole reason for this exercise was to see if it was possible
to write a script in pure awk that could do this.


Unsubscribe info:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]