#!/home/ben/software/install/bin/perl
use warnings;
use strict;
use utf8;
use FindBin '$Bin';
use Geolite ':all';
use Deploy qw/batch_edit do_system/;
use File::Slurper qw/read_text write_text/;
BEGIN: {
#    do_system ("./build.pl");
    use lib "$Bin/blib/lib";
    use lib "$Bin/blib/arch";
    use IP::China;
};
my $verbose = 1;
my $current = $IP::China::VERSION;
my $version = get_best_date ();
if ($current ne $version) {
    my $pm = "$Bin/lib/IP/China.pm";
    if ($verbose) {
	print "Version of $pm is $current, changing to $version.\n";
    }
    batch_edit ({$current => $version}, $pm, \my $out);
    write_text ($pm, $out);
}
else {
    if ($verbose) {
	print "PM version is current.\n";
    }
}
my $date = sprintf ("%.4s-%.2s-%.2s", substr ($version, 0, 4),
		    substr ($version, 4, 6), substr ($version, 6, 8));
my $update = <<EOF;
$version $date

* Data update

EOF
my $chg = "$Bin/Changes";
my $text = read_text ($chg);
if ($text =~ /\Q$version/) {
    warn "$chg already updated";
}
else {
    $text = $update . $text;
    write_text ($chg, $text);
}
if ($verbose) {
    print "Finished updating.\n";
}

# Local variables:
# mode: perl
# End:
