delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/11/06/19:01:44

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Message-ID: <436E995A.1F02F761@dessent.net>
Date: Sun, 06 Nov 2005 16:01:30 -0800
From: Brian Dessent <brian AT dessent DOT net>
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: where is setup.exe source?
References: <dklo7u$naf$1 AT sea DOT gmane DOT org> <436E6A0C DOT 5E565962 AT dessent DOT net> <Pine DOT GSO DOT 4 DOT 63 DOT 0511061603100 DOT 847 AT slinky DOT cs DOT nyu DOT edu> <436E7DCC DOT 6E27EA9 AT dessent DOT net> <Pine DOT GSO DOT 4 DOT 63 DOT 0511061717010 DOT 847 AT slinky DOT cs DOT nyu DOT edu> <436E891A DOT 489A09B5 AT dessent DOT net>
X-IsSubscribed: yes
Reply-To: cygwin AT cygwin DOT com

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

BEGIN {
    CygwinSite = "/inet/tcp/0/cygwin.com/80"
    MirrorsUrl = "http://cygwin.com/mirrors.lst"
    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
        exit
    }

    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]
                    break
                }
            }
            close(AwkFetch)
        }
    }
    close(CygwinSite)
}

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.

Brian

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019