Blame SOURCES/geoipupdate6.cron

90632b
#!/usr/bin/perl
90632b
90632b
# This script is based on geolite-mirror-simple.pl from Maxmind's Geo::IP perl module
90632b
90632b
use strict;
90632b
our $VERSION = '0.01';
90632b
use LWP::Simple qw/ mirror RC_NOT_MODIFIED RC_OK $ua /;
90632b
use File::Copy qw/ mv /;
90632b
use File::Spec;
90632b
use PerlIO::gzip;
90632b
90632b
# Make sure the directories exist
90632b
-d ( my $download_dir = '/usr/share/GeoIP/download' ) or die $!;
90632b
-d ( my $dest_dir     = '/usr/share/GeoIP' )          or die $!;
90632b
90632b
my %mirror = (    # local-filename       geolite-name
90632b
    'GeoIPv6.dat.gz'       => 'http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz',
90632b
    'GeoLiteCityv6.dat.gz' => 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz',
90632b
    'GeoIPASNumv6.dat.gz'  => 'http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNumv6.dat.gz'
90632b
);
90632b
90632b
$ua->agent("geoipupdate6.cron/$VERSION");
90632b
90632b
chdir $download_dir or die $!;
90632b
for my $f ( keys %mirror ) {
90632b
    my $rc = mirror( $mirror{$f}, $f );
90632b
    next if $rc == RC_NOT_MODIFIED;
90632b
    if ( $rc == RC_OK ) {
90632b
        ( my $outfile = $f ) =~ s/\.gz$//;
90632b
        open my $in,  '<:gzip', $f       or die $!;
90632b
        open my $out, '>',      $outfile or die $!;
90632b
        print $out $_ or die $! while <$in>;
90632b
        mv( $outfile, File::Spec->catfile( $dest_dir, $outfile ) ) or die $!;
90632b
    }
90632b
}
90632b
exit 0;
90632b