Sunday, November 18, 2007

Fixing netselect-apt

netselect-apt efficiently chooses the fastest download mirror for Debian packages out of a list of several hundred mirrors worldwide.

Unfortunately, I noticed after installing a new version of Debian Etch that netselect-apt failed with the message:

netselect was unable to find a mirror, this probably means that
you are behind a firewall and it is blocking traceroute.

It turns out netselect-apt::run_netselect() produces this error when it fails to parse the HTML of the Debian worldwide mirror sites page at http://www.debian.org/mirror/mirrors_full. This page no longer contains \n\n delimiters.

Last week, I resolved the problem by modifying run_netselect() to use "<br><br>" instead (highlighted):

run_netselect()
{
        SEARCH="$1"
    PROTO="$2"
    netselect -v -s 1 $(cat "$infile" \
        | perl -n -e '
            $/="<br><br>";
            while(<>){
              next if $_ !~ /Site:/;
              if( m@'"$SEARCH"':.*<a href="('"$PROTO"'://.*?)">@i ){
                    print("$1\n");
              }
            }') \
        | awk '{print $2}'
}


I also removed the check for Archive Architectures, since the phrase no longer appears on the page.

Also, I noticed after patching netselect-apt that running netselect-apt occasionally fails due to negative values for netselect field host->num_out, but this is a bug for the netselect package, not netselect-apt .

No comments:

Post a Comment