pghmcfc pushed to geoipupdate (epel7). "Improve geoipupdate6 (..more)"
notifications at fedoraproject.org
notifications at fedoraproject.org
Mon Apr 13 21:22:03 UTC 2015
>From 2b5aaf80df028802ffcf935a92442e53ffe7541c Mon Sep 17 00:00:00 2001
From: Paul Howarth <paul at city-fan.org>
Date: Tue, 10 Feb 2015 21:58:05 +0000
Subject: Improve geoipupdate6
New geoipupdate6 cron script written in Perl that doesn't download the data
if it hasn't changed.
diff --git a/geoipupdate.spec b/geoipupdate.spec
index c8fd442..f346da2 100644
--- a/geoipupdate.spec
+++ b/geoipupdate.spec
@@ -5,7 +5,7 @@
Name: geoipupdate
Version: 2.1.0
-Release: 3%{?dist}
+Release: 4%{?dist}
Summary: Update GeoIP2 and GeoIP Legacy binary databases from MaxMind
Group: Development/Tools
License: GPLv2
@@ -15,6 +15,12 @@ Source1: geoipupdate.cron
Source2: geoipupdate6.cron
BuildRequires: libcurl-devel
BuildRequires: zlib-devel
+# Perl modules used by IPv6 cron script
+BuildRequires: perl(File::Copy)
+BuildRequires: perl(File::Spec)
+BuildRequires: perl(LWP::Simple)
+BuildRequires: perl(PerlIO::gzip)
+BuildRequires: perl(strict)
%description
The GeoIP Update program performs automatic updates of GeoIP2 and GeoIP
@@ -32,7 +38,7 @@ Obsoletes: GeoIP-update < 1.6.0
Provides: GeoIP-update = 1.6.0
%description cron
-Cron job for weekly updates to GeoIP2 and GeoIP Legacy database from MaxMind.
+Cron job for weekly updates to GeoIP Legacy database from MaxMind.
%package cron6
Summary: Cron job to do weekly updates of GeoIP IPv6 databases
@@ -47,8 +53,7 @@ Obsoletes: GeoIP-update6 < 1.6.0
Provides: GeoIP-update6 = 1.6.0
%description cron6
-Cron job for weekly updates to GeoIP2 and GeoIP IPv6 Legacy database from
-MaxMind.
+Cron job for weekly updates to GeoIP IPv6 Legacy database from MaxMind.
%prep
%setup -q
@@ -70,6 +75,12 @@ sed -i \
install -D -m 755 %{SOURCE1} %{buildroot}%{_sysconfdir}/cron.weekly/geoipupdate
install -D -m 755 %{SOURCE2} %{buildroot}%{_sysconfdir}/cron.weekly/geoipupdate6
+# Make the download directory for the IPv6 data cron job and soem ghost files
+mkdir -p %{buildroot}%{_datadir}/GeoIP/download/
+: > %{buildroot}%{_datadir}/GeoIP/download/GeoIPv6.dat.gz
+: > %{buildroot}%{_datadir}/GeoIP/download/GeoLiteCityv6.dat.gz
+: > %{buildroot}%{_datadir}/GeoIP/download/GeoIPASNumv6.dat.gz
+
# LICENSE file is being omitted from release tarball. As soon as this issue:
# https://github.com/maxmind/geoipupdate/issues/25
# is resolved we'll amend the spec file to include it in the packaging.
@@ -89,8 +100,17 @@ install -D -m 755 %{SOURCE2} %{buildroot}%{_sysconfdir}/cron.weekly/geoipupdate6
%files cron6
%config(noreplace) %{_sysconfdir}/cron.weekly/geoipupdate6
+%dir %{_datadir}/GeoIP/
+%dir %{_datadir}/GeoIP/download/
+%ghost %{_datadir}/GeoIP/download/GeoIPv6.dat.gz
+%ghost %{_datadir}/GeoIP/download/GeoLiteCityv6.dat.gz
+%ghost %{_datadir}/GeoIP/download/GeoIPASNumv6.dat.gz
%changelog
+* Tue Feb 10 2015 Paul Howarth <paul at city-fan.org> - 2.1.0-4
+- New geoipupdate6 cron script written in Perl that doesn't download the data
+ if it hasn't changed
+
* Fri Feb 6 2015 Paul Howarth <paul at city-fan.org> - 2.1.0-3
- Add cron6 subpackage, equivalent to old GeoIP-update6 package
- Revise obsoletes/provides
diff --git a/geoipupdate6.cron b/geoipupdate6.cron
index 4273968..112d8b8 100644
--- a/geoipupdate6.cron
+++ b/geoipupdate6.cron
@@ -1,20 +1,37 @@
-#!/bin/sh
+#!/usr/bin/perl
-# Update IPv6 free databases
+# This script is based on geolite-mirror-simple.pl from Maxmind's Geo::IP perl module
-# It would be much better if we could use geoipupdate for this as it only
-# downloads the data if it has changed and checks it after download
+use strict;
+our $VERSION = '0.01';
+use LWP::Simple qw/ mirror RC_NOT_MODIFIED RC_OK $ua /;
+use File::Copy qw/ mv /;
+use File::Spec;
+use PerlIO::gzip;
-DB_LOC=http://geolite.maxmind.com/download/geoip/database
-ASDB_LOC=http://download.maxmind.com/download/geoip/database/asnum
+# Make sure the directories exist
+-d ( my $download_dir = '/usr/share/GeoIP/download' ) or die $!;
+-d ( my $dest_dir = '/usr/share/GeoIP' ) or die $!;
-cd /usr/share/GeoIP
+my %mirror = ( # local-filename geolite-name
+ 'GeoIPv6.dat.gz' => 'http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz',
+ 'GeoLiteCityv6.dat.gz' => 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz',
+ 'GeoIPASNumv6.dat.gz' => 'http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNumv6.dat.gz'
+);
-# IPv6 Country database
-wget --quiet $DB_LOC/GeoIPv6.dat.gz && mv -f GeoIPv6.dat GeoIPv6.dat.old && gunzip GeoIPv6.dat
+$ua->agent("geoipupdate6.cron/$VERSION");
-# IPv6 City database
-wget --quiet $DB_LOC/GeoLiteCityv6-beta/GeoLiteCityv6.dat.gz && mv -f GeoLiteCityv6.dat GeoLiteCityv6.dat.old && gunzip GeoLiteCityv6.dat
+chdir $download_dir or die $!;
+for my $f ( keys %mirror ) {
+ my $rc = mirror( $mirror{$f}, $f );
+ next if $rc == RC_NOT_MODIFIED;
+ if ( $rc == RC_OK ) {
+ ( my $outfile = $f ) =~ s/\.gz$//;
+ open my $in, '<:gzip', $f or die $!;
+ open my $out, '>', $outfile or die $!;
+ print $out $_ or die $! while <$in>;
+ mv( $outfile, File::Spec->catfile( $dest_dir, $outfile ) ) or die $!;
+ }
+}
+exit 0;
-# IPv6 AS Number database
-wget --quiet $ASDB_LOC/GeoIPASNumv6.dat.gz && mv -f GeoIPASNumv6.dat GeoIPASNumv6.dat.old && gunzip GeoIPASNumv6.dat
--
cgit v0.10.2
http://pkgs.fedoraproject.org/cgit/geoipupdate.git/commit/?h=epel7&id=2b5aaf80df028802ffcf935a92442e53ffe7541c
More information about the scm-commits
mailing list