diff --git a/debian/control b/debian/control index 4467668d..d91d343b 100644 --- a/debian/control +++ b/debian/control @@ -9,6 +9,7 @@ Build-Depends: debhelper (>= 10), docbook-xsl, git, + libcapture-tiny-perl, libclone-perl, libconfig-tiny-perl, libdata-validate-ip-perl, @@ -39,6 +40,7 @@ Depends: etckeeper, file, git (>= 1:1.7.2.5-3~), + libcapture-tiny-perl, libclone-perl, libconfig-tiny-perl, libdata-validate-ip-perl, diff --git a/helper/sync-db b/helper/sync-db index d4e5d55f..28bb858b 100755 --- a/helper/sync-db +++ b/helper/sync-db @@ -9,6 +9,7 @@ use YAML::XS qw(LoadFile); use Template; use Hash::Merge qw(merge); use DBI; +use Capture::Tiny qw(capture); sub sync_extra_sockets; sub db_connect; @@ -64,6 +65,8 @@ exit 1 unless(sync_rtp_interfaces($dbh, exit 1 unless(sync_general_timezone($dbh, $config->{general}->{timezone})); +exit 1 unless(sync_db_timezones($dbh)); + $dbh->disconnect; exit 0; @@ -163,5 +166,73 @@ SQL return 1; } +## /usr/share/zoneinfo into MariaDB ############################## +sub sync_db_timezones { + my $dbh = shift; + + my ($out, $err, $rc) = capture { + system('/usr/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo'); + }; + + if ($rc) { + print "Error: $err\n"; + return; + } + + my ($tzinfo_version, undef, undef) = capture { + system('dpkg -s tzdata | grep Version:'); + }; + + unless ($tzinfo_version && $tzinfo_version =~ /Version:\s*(\S+)/) { + print "Error: Could not retreive tzdata package version\n"; + return; + } + $tzinfo_version = $1; + + my $pe = $dbh->{PrintError}; + $dbh->{PrintError} = 0; + my $sql = ''; + my $p_rs = $RS; + eval { + $dbh->begin_work() or die "Cannot start tx: ".$DBI::errstr; + my ($cur_tzinfo_version) = $dbh->selectrow_array(<do('USE mysql') + or die "Cannot use mysql database: $DBI::errstr\n"; + while ($sql = <$sql_stream>) { + map { + $dbh->do($_) or die "Cannot insert timezone data: $DBI::errstr\n"; + } split /;\s+/, $sql; # multiple one line statements + } + close $sql_stream; + $dbh->do(<{PrintError} = $pe; + if ($err) { + print $err,"sql: $sql\n"; + $dbh->rollback(); + return; + } + $dbh->commit(); + + return 1; +} + ## END OF FILE #################################################################