Gestion des miroirs pour makepkg et pacman.
Publié : lun. 12 mai 2008, 20:48
Je viens de coder entre deux siestes un petit script en lua pour télécharger des fichiers sur des miroirs choisis de façon pseudo-aléatoire.
La liste de miroirs est purement pondues à l'arrache et non testée. Vous verrez qu'il est très simple d'ajouter ou modifier des miroirs.
Pour que pacman et makepkg (donc indirectement yaourt) le prenne en compte il faut modifier makepkg.conf et pacman.conf
Modif. pour makepkg.conf
Modif. pour pacman.conf
Le script, download_helper, à placer dans /etc/pacman.d
Voilou. La gestion des erreurs est simple mais si vous arrivez à tomber sur une séquence de 5 fois le même miroir en erreur il faut aller acheter immédiatement un grigri pour conjurer le mauvais œil.
Si vous avez des miroirs à ajouter, je suis preneur.
La liste de miroirs est purement pondues à l'arrache et non testée. Vous verrez qu'il est très simple d'ajouter ou modifier des miroirs.
Pour que pacman et makepkg (donc indirectement yaourt) le prenne en compte il faut modifier makepkg.conf et pacman.conf
Modif. pour makepkg.conf
Code : Tout sélectionner
DLAGENTS=('ftp::/etc/pacman.d/download_helper'
'http::/etc/pacman.d/download_helper'
'https::/usr/bin/wget -c -t 3 --waitretry=3 --no-check-certificate'
'rsync::/usr/bin/rsync -z'
'scp::/usr/bin/scp -C')
Code : Tout sélectionner
XferCommand = /etc/pacman.d/download_helper %o %u
Code : Tout sélectionner
#!/usr/bin/lua
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.
gnu = {
"ftp://ftp.belnet.be/mirror/ftp.gnu.org",
"ftp://ftp.cs.tu-berlin.de/pub/gnu/",
"ftp://ftp.cs.univ-paris8.fr/mirrors/ftp.gnu.org/gnu/",
"ftp://ftp.easynet.be/gnu/",
"ftp://ftp.ironie.org/ftp.gnu.org/pub/gnu/",
"ftp://gd.tuwien.ac.at/gnu/gnusrc/",
"http://gnuftp.miroir-francais.fr/",
"ftp://mirror.cict.fr/gnu/"
}
sourceforge = {
"http://easynews.dl.sourceforge.net/",
"http://internap.dl.sourceforge.net/",
"http://jaist.dl.sourceforge.net/",
"http://kent.dl.sourceforge.net/",
"http://mesh.dl.sourceforge.net/",
"http://puzzle.dl.sourceforge.net/",
"http://osdn.dl.sourceforge.net/",
"http://ovh.dl.sourceforge.net/",
"http://superb-east.dl.sourceforge.net/",
"http://surfnet.dl.sourceforge.net/",
"http://switch.dl.sourceforge.net/"
}
gnome = {
"http://fr2.rpmfind.net/linux/gnome.org/",
"http://ftp.unina.it/pub/linux/GNOME/",
"ftp://ftp.dit.upm.es/pub/GNOME/",
"ftp://ftp.no.gnome.org/pub/GNOME/",
"http://ftp.acc.umu.se/pub/GNOME/",
"http://ftp.belnet.be/mirror/ftp.gnome.org/"
}
kernel = {
"http://www.fr.kernel.org/",
"http://kernel.miroir-francais.fr/"
}
mirrors ={
{pattern="ftp://ftp\.gnu\.org/gnu/", list=gnu},
{pattern="http://.*\.sourceforge\.net/", list=sourceforge},
{pattern=".*\.gnome\.org/pub/.*/", list=gnome},
{pattern=".*\.kernel\.org/", list=kernel},
}
function download_wget(dest, url)
if dest == nil then
return os.execute("wget --passive-ftp -c "..url)
else
return os.execute("wget --passive-ftp -c -O "..dest.." "..url)
end
end
if #arg == 1 then
source=arg[1]
dest=nil
elseif #arg == 2 then
source=arg[2]
dest=arg[1]
else
print("download_helper arg1 [arg2]")
os.exit(1)
end
for _,mirror in pairs(mirrors) do
if string.match(source, mirror.pattern) then
math.randomseed(os.time())
for url in string.gmatch(source, mirror.pattern.."(.*)") do
local try=0
while try < 5 do
if download_wget(dest, mirror.list[math.random(#mirror.list)]..url) == 0 then
os.exit(0)
end
try = try + 1
end
return 1
end
end
end
return download_wget(dest, source)
Si vous avez des miroirs à ajouter, je suis preneur.