diff options
Diffstat (limited to 'perl-install/timezone.pm')
| -rw-r--r-- | perl-install/timezone.pm | 38 |
1 files changed, 13 insertions, 25 deletions
diff --git a/perl-install/timezone.pm b/perl-install/timezone.pm index cfbaf98a1..1f4bbb419 100644 --- a/perl-install/timezone.pm +++ b/perl-install/timezone.pm @@ -26,44 +26,32 @@ sub read() { { timezone => $t{ZONE}, UTC => text2bool($t{UTC}) }; } -our $ntp = "ntp"; -my $servername_config_suffix = ""; -unless (-f $::prefix . "/etc/" . $ntp . ".conf") { - $ntp = "chrony"; - $servername_config_suffix = " iburst"; +our $ntpd = 'chronyd'; +our $ntp_conf = '/etc/chrony.conf'; +unless (-f "$::prefix$ntp_conf") { + $ntpd = 'ntpd'; + $ntp_conf = '/etc/ntp.d/use-pool' } -sub ntp_server() { - find { $_ ne '127.127.1.0' } map { if_(/^\s*server\s+(\S*)/, $1) } cat_($::prefix . "/etc/" . $ntp . ".conf"); +sub ntp_pool() { + find { $_ ne '' } map { (/^\s*pool\s+(\S*)/, $1) } cat_("$::prefix$ntp_conf"); } -sub set_ntp_server { - my ($server) = @_; - my $f = $::prefix . "/etc/" . $ntp . ".conf"; +sub set_ntp_pool { + my ($pool) = @_; + my $f = "$::prefix$ntp_conf"; -f $f or return; - my $pool_match = qr/\.pool\.ntp\.org$/; - my @servers = $server =~ $pool_match ? (map { "$_.$server" } 0 .. 2) : $server; - - my $added = 0; - substInFile { - if (/^#?\s*server\s+(\S*)/ && $1 ne '127.127.1.0') { - $_ = $added ? $_ =~ $pool_match ? undef : "#server $1\n" : join('', map { "server $_$servername_config_suffix\n" } @servers); - $added = 1; - } - } $f; - if ($ntp eq "ntp") { - output_p("$::prefix/etc/ntp/step-tickers", join('', map { "$_\n" } @servers)); - } + substInFile { s/^#?\s*pool\s+.*/pool $pool iburst/ } $f if $pool; require services; - services::set_status($ntp . 'd', to_bool($server), $::isInstall); + services::set_status($ntpd, to_bool($pool), $::isInstall); } sub write { my ($t) = @_; - set_ntp_server($t->{ntp}); + set_ntp_pool($t->{ntp}); my $tz_prefix = get_timezone_prefix(1); eval { symlinkf($tz_prefix . '/' . $t->{timezone}, "$::prefix/etc/localtime") }; |
