#!/usr/bin/perl # -- # $Id$ # use strict; use LWP::Simple; use Getopt::Long; # Global var my %list_source; my %param; my $softver="0.0.1"; sub help() { print "Urpmi config $softver (GPL): Olivier Thauvin options (*= can be set in /etc/urpmi/mirror.config): -h|--help Give this message -t|--test Only show what it do * -v|--verbose Make it verbose * -u|--url url Url to use to retrieve list * |--mdkver ver force mdk version to ver * |--arch arch force architecture to arch "; } sub info() { print "you\'re using url: $param{'url'} Mandrake version: $param{'mdkver'} Arch: $param{'arch'} "; } sub get_current_ver() { open (VER,"/etc/mandrake-release") or die 'Can\'t open mandrake-release'; @_=split(" ",); if ( $_[4] =~ /\(Cooker\)/ ) { $param{'mdkver'}='cooker';} else { $param{'mdkver'}=$_[3];}; $param{'arch'}=$_[6]; close(VER); print "Mandrake version is $param{'mdkver'}\n" if ($param{'verbose'}); } sub parse_config() { if (open(CONF, "/etc/urpmi/mirror.config")) { while (my $line = ) { chomp($line); # no newline $line =~ s/#.*//; # no comments $line =~ s/^\s+//; # no leading white $line =~ s/\s+$//; # no trailing white next unless length($line); # anything left? my ($option, $value) = split(/\s*=\s*/, $line, 2); $param{$option}=$value; } close(CONF); } else { warn "Can't open configuration file: $!, skipping.\n"; } } sub info_mirror($) { my ($mach)=@_; my @mirror=split(':',$mach,5); $mach=$mirror[4]; #$mach =~ s/with/\//; #$mach =~ s/ //g; $mach =~ s/^.*:\/\///; $mach =~ s/\/.*$//; # $mach =~ s/hdlist.*$//; #print $mach."\n"; # my $r=system("wget -q --delete-after -t 1 $mach 2> /dev/null"); print ":location=".$mach.":".$mirror[3]."\n"; #print join(':',@mirror)."\n" if (!$mirror[2]); } sub parse_url () { my $list=get($param{'url'}) or die 'Can\'t read mirror list'; print "Getting from $param{'url'}\n" if ($param{'verbose'}); foreach my $line (split(/^/,$list)) { $line =~ s/#.*//; # no comments $line =~ s/^\s+//; # no leading white $line =~ s/\s+$//; # no trailing white next unless length($line); # anything left? info_mirror($line); } } # Begin main parse_config; GetOptions ( "url=s" => \$param{'url'}, ); parse_url;