aboutsummaryrefslogtreecommitdiffstats
ModeNameSize
-rw-r--r--CHANGES8812logstatsplain
-rw-r--r--MANIFEST.in249logstatsplain
d---------MgaRepo550logstatsplain
-rw-r--r--README512logstatsplain
-rw-r--r--README.BINREPO14365logstatsplain
-rw-r--r--README.LDAP2391logstatsplain
-rwxr-xr-xcreate-srpm4620logstatsplain
-rw-r--r--default.chlog1000logstatsplain
-rwxr-xr-xmgarepo2996logstatsplain
-rw-r--r--mgarepo-example.conf2049logstatsplain
-rwxr-xr-xmgarepo-ssh36logstatsplain
-rw-r--r--mgarepo.812798logstatsplain
-rw-r--r--mgarepo.conf621logstatsplain
-rw-r--r--revno.chlog831logstatsplain
-rw-r--r--setup.cfg65logstatsplain
-rwxr-xr-xsetup.py1035logstatsplain
a id='n219' href='#n219'>219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
package timezone;

use diagnostics;
use strict;

use common;
use log;

sub get_timezone_prefix() {
    my $prefix = $::testing ? '' : $::prefix;
    $prefix . "/usr/share/zoneinfo";
}

sub getTimeZones() {
    my $tz_prefix = get_timezone_prefix();
    open(my $F, "cd $tz_prefix && find [A-Z]* -noleaf -type f |");
    my @l = difference2([ chomp_(<$F>) ], [ 'ROC', 'PRC' ]);
    close $F or die "cannot list the available zoneinfos";
    sort @l;
}

sub read() {
    my %t = getVarsFromSh("$::prefix/etc/sysconfig/clock") or return {};
    { 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";
}

sub ntp_server() {
    find { $_ ne '127.127.1.0' } map { if_(/^\s*server\s+(\S*)/, $1) } cat_($::prefix . "/etc/" . $ntp . ".conf");
}

sub set_ntp_server {
    my ($server) = @_;
    my $f = $::prefix . "/etc/" . $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));
    }

    require services;
    services::set_status($ntp . 'd', to_bool($server), $::isInstall);
}

sub write {
    my ($t) = @_;

    set_ntp_server($t->{ntp});

    my $tz_prefix = get_timezone_prefix();
    eval { cp_af($tz_prefix . '/' . $t->{timezone}, "$::prefix/etc/localtime") };
    $@ and log::l("installing /etc/localtime failed");
    setVarsInSh("$::prefix/etc/sysconfig/clock", {
	ZONE => $t->{timezone},
	UTC  => bool2text($t->{UTC}),
	ARC  => "false",
    });

    my $adjtime_file = $::prefix . '/etc/adjtime';
    my @adjtime = cat_($adjtime_file);
    @adjtime or @adjtime = ("0.0 0 0.0\n", "0\n");
    $adjtime[2] = $t->{UTC} ? "UTC\n" : "LOCAL\n";
    output_p($adjtime_file, @adjtime);
}

sub reload_sys_clock {
    my ($t) = @_;
    require run_program;
    any::disable_x_screensaver();
    run_program::run('hwclock', '--hctosys', ($t->{UTC} ? '--utc' : '--localtime'));
    any::enable_x_screensaver();
}

#- best guesses for a given country
my %c2t = (
'AM' => 'Asia/Yerevan',
'AR' => 'America/Buenos_Aires',
'AT' => 'Europe/Vienna',
'AU' => 'Australia/Sydney',
'BA' => 'Europe/Sarajevo',
'BE' => 'Europe/Brussels',
'BG' => 'Europe/Sofia',
'BR' => 'America/Sao_Paulo', #- most brazilians live on this time zone
'BY' => 'Europe/Minsk',
'CA' => 'Canada/Eastern',
'CH' => 'Europe/Zurich',
'CN' => 'Asia/Beijing',
'CZ' => 'Europe/Prague',
'DE' => 'Europe/Berlin',
'DK' => 'Europe/Copenhagen',
'EE' => 'Europe/Tallinn',
'ES' => 'Europe/Madrid',
'FI' => 'Europe/Helsinki',
'FR' => 'Europe/Paris',
'GB' => 'Europe/London',
'GE' => 'Asia/Yerevan',
'GL' => 'Arctic/Longyearbyen',
'GR' => 'Europe/Athens',
'HR' => 'Europe/Zagreb',
'HU' => 'Europe/Budapest',
'ID' => 'Asia/Jakarta',
'IE' => 'Europe/Dublin',
'IL' => 'Asia/Tel_Aviv',
'IN' => 'Asia/Kolkata',
'IR' => 'Asia/Tehran',
'IS' => 'Atlantic/Reykjavik',
'IT' => 'Europe/Rome',
'JP' => 'Asia/Tokyo',
'KR' => 'Asia/Seoul',
'LT' => 'Europe/Vilnius',
'LV' => 'Europe/Riga',
'MK' => 'Europe/Skopje',
'MT' => 'Europe/Malta',