You are not logged in.

#1 2008-04-04 21:50:34

hamlet
Member
Registered: 2007-11-25
Posts: 12

netselect-pacman in ruby

I needed a script to find the nearest mirror and put it at the top of mirrorlist, because I often go from France to Ireland !

So here it is, it needs ruby and netselect...
(and I just can't understand there isn't something like that by default with pacman, or at least with the netselect package !)

#!/usr/bin/env ruby
#
# Using netselect to find the best mirror from /etc/pacman.d/mirrorlist and put it at the top
#
file = File.readlines('/etc/pacman.d/mirrorlist')

mirrors = file.map{ |line|
        if not line =~ /^#/ then
                line[/^Server = (.*)$/, 1]
        end
}.compact.join(" ")

puts "Testing all the mirrors, can take a while..."
res = `netselect #{mirrors}`[/\s*\d*\s*(.*)$/, 1]

puts "And the winner is :"
puts line = "Server = "+res.sub('//os', '/$repo/os')

if file[0] =~ /netselect-pacman/ then
        file[1] = line+"\n"
else
        file.insert 0, "# Server choosen by netselect-pacman. Just comment out if you don't like !\n", line+"\n", "\n"
end

File.new('/etc/pacman.d/mirrorlist', 'w').write file.join

Hope it will be useful for someone !

Offline

#2 2008-04-04 23:28:43

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: netselect-pacman in ruby

hamlet wrote:

I just can't understand there isn't something like that by default with pacman

/usr/bin/rankmirrors is owned by pacman

Run it with no arguments to get the available options. It's in python, btw.

Offline

#3 2008-04-05 13:54:22

hamlet
Member
Registered: 2007-11-25
Posts: 12

Re: netselect-pacman in ruby

Oh, cool, I didn't knew it...
But I don't like it too much, because I just want to use the best server available !
And to update my mirrorlist in one command, without messing all the comments.
And since I don't know python, I can't tweak it for doing that...
So I'll stick on using my netselect script ! ;-)

Perhaps we could add it to the netselect package, since there is netselect-apt in it !!

Offline

Board footer

Powered by FluxBB