summaryrefslogtreecommitdiffstats
path: root/time_wizard/scripts/NTPConf.pm
blob: fb37b8a64ace268866cc63f0c544dbc7fab47513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl

# NTP Config Parser

# Copyright (C) 2002 MandrakeSoft Arnaud Desmons <adesmons@mandrakesoft.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

package NTPConf;
require "__WIZ_HOME__/common/scripts/Vareqval.pm";
require "__WIZ_HOME__/common/scripts/DrakconnectConf.pm";
use MDK::Common;
use strict;
use standalone;

sub	chooser4 {
    if ($ENV{chooser4} eq "save_quit") {
	do_it();
	return 1;
    }
    2;
}

sub	test {
    system("/usr/sbin/ntpdate -q $ENV{server1} $ENV{server2}");
    if (!($? >> 8)) {
	do_it();
	return 1;
    }
    2;
}

sub	do_it {
    my $file = "/etc/sysconfig/clock";
    MDK::Common::cp_af($file, $file.".orig");
    open(NEW, "> $file") or die "can not open $file: $!";
    print NEW "UTC=true\n";
    print NEW "ZONE=$ENV{wiz_timezone}\n";
    print NEW "ARC=false\n";
    close NEW or die "can not close $file: $!";
    MDK::Common::cp_af("/usr/share/zoneinfo/$ENV{wiz_timezone}", "/etc/localtime");
    -f "/etc/ntp/step-tickers" and MDK::Common::cp_af("/etc/ntp/step-tickers", "/etc/ntp/step-tickers.orig");
    open(NEW, "> /etc/ntp/step-tickers") or die "can not open /etc/ntp/step-tickers: $!";
    print NEW $ENV{server1}."\n";
    print NEW $ENV{server2}."\n";
    close NEW or die "can not close /etc/ntp/step-tickers: $!";
    standalone::explanations("Wrote /etc/ntp/step-tickers, starting services");
    my @services = qw(crond atd ntpd);
    foreach (@services) {
	system("/etc/rc.d/init.d/$_ stop");
    }
    foreach (reverse @services) {
	system("/etc/rc.d/init.d/$_ start");
    }
    system("/sbin/hwclock --systohc --utc");
    10;
}
1;