Blame SOURCES/geoipupdate6.cron

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