diff options
| author | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2026-01-04 16:20:57 +0000 |
|---|---|---|
| committer | Martin Whitaker <mageia@martin-whitaker.me.uk> | 2026-01-04 21:30:53 +0000 |
| commit | bf9e1e4eb48e07bf9e36e165443a0ee68609dd0b (patch) | |
| tree | 38b5c1eb580e1660ba9b4f0c4f1bf2ced64fbae9 /perl-install | |
| parent | dd7c30bd6b30a6ac3cf23b5460e8337f147b13a2 (diff) | |
| download | drakx-bf9e1e4eb48e07bf9e36e165443a0ee68609dd0b.tar drakx-bf9e1e4eb48e07bf9e36e165443a0ee68609dd0b.tar.gz drakx-bf9e1e4eb48e07bf9e36e165443a0ee68609dd0b.tar.bz2 drakx-bf9e1e4eb48e07bf9e36e165443a0ee68609dd0b.tar.xz drakx-bf9e1e4eb48e07bf9e36e165443a0ee68609dd0b.zip | |
drakclock: simplify and tidy up
Diffstat (limited to 'perl-install')
| -rwxr-xr-x | perl-install/standalone/drakclock | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/perl-install/standalone/drakclock b/perl-install/standalone/drakclock index 310701dbe..b05faaa63 100755 --- a/perl-install/standalone/drakclock +++ b/perl-install/standalone/drakclock @@ -23,9 +23,6 @@ my $its_reset = 0; $ugtk3::wm_icon = "/usr/share/mcc/themes/default/time-mdk.png"; -my $ntpd = $timezone::ntpd; -my $ntpfile = $timezone::ntp_conf; - my $my_win = ugtk3->new(N("Date, Clock & Time Zone Settings")); $my_win->{window}->signal_connect(delete_event => sub { ugtk3->exit(0) }); @@ -60,7 +57,7 @@ my $adjh = Gtk3::Adjustment->new(0.0, 0.0, 23.0, 1.0, 5.0, 0.0); my $adjm = Gtk3::Adjustment->new(0.0, 0.0, 59.0, 1.0, 5.0, 0.0); my $adjs = Gtk3::Adjustment->new(0.0, 0.0, 59.0, 1.0, 5.0, 0.0); -my ($button_reset, $check_ntp, $hb_ntp, $combo_ntpserver, $ntp); +my ($button_reset, $check_ntp, $hb_ntp, $combo_ntp_pool, $ntp); my $mode = is_ntp_daemon_running(); my (undef, undef, $h_old, $old_day, $old_month, $old_year) = localtime(time()); @@ -84,7 +81,7 @@ $my_win->{window}->add( }), 0, $hb_ntp = gtknew('HBox', border_width => 5, children => [ 0, gtknew('Label', text => N("Server:")), - 1, $combo_ntpserver = Gtk3::ComboBoxText->new + 1, $combo_ntp_pool = Gtk3::ComboBoxText->new ]) ])) ]), @@ -109,28 +106,29 @@ $my_win->{window}->add( cancel_clicked => sub { ugtk3->exit(0) }, ok_clicked => sub { my $need_date = 1; + my $ntp_service = $timezone::ntpd . '.service'; any::disable_x_screensaver(); if ($check_ntp->get_active) { - my $choosed_serv = $combo_ntpserver->entry->get_text; - $choosed_serv =~ s/^[^:]+: (.+)/$1/; - if (!$choosed_serv) { - err_dialog(N("Error"), N("Please enter a valid NTP server address.")); + my $chosen_pool = $combo_ntp_pool->entry->get_text; + $chosen_pool =~ s/^[^:]+: (.+)/$1/; + if (!$chosen_pool) { + err_dialog(N("Error"), N("Please enter a valid NTP server pool.")); return; } - timezone::set_ntp_pool($choosed_serv); - system('systemctl', 'enable', "$ntpd.service"); - system('systemctl', 'stop', "$ntpd.service"); + timezone::set_ntp_pool($chosen_pool); + system('systemctl', 'enable', $ntp_service); + system('systemctl', 'stop', $ntp_service); #verify that we have a valid hostname (thx sam) - $choosed_serv =~ s/[^-a-zA-Z0-9.]//g; + $chosen_pool =~ s/[^-a-zA-Z0-9.]//g; my $sync_ok; - if ($ntpd eq "chronyd") { - system('systemctl', 'start', "$ntpd.service"); + if ($ntp_service eq 'chronyd.service') { + system('systemctl', 'start', $ntp_service); # Wait up to 30s for sync $sync_ok = !system('chronyc', 'waitsync', '30', '0.1'); - system('systemctl', 'stop', "$ntpd.service") if !$sync_ok; + system('systemctl', 'stop', $ntp_service) if !$sync_ok; } else { - $sync_ok = !system('/usr/sbin/ntpd', '-gqc', '/dev/null', $choosed_serv); - system('systemctl', 'start', "$ntpd.service") if $sync_ok; + $sync_ok = !system('/usr/sbin/ntpd', '-gqc', '/dev/null', $chosen_pool); + system('systemctl', 'start', $ntp_service) if $sync_ok; } if ($sync_ok) { update_time(); #- get the new time before updating the hwclock @@ -138,15 +136,15 @@ $my_win->{window}->add( } else { $in->ask_from_no_check({ title => N("Error"), - messages => N("Could not synchronize with %s.", $choosed_serv), + messages => N("Could not synchronize with %s.", $chosen_pool), ok => N("Quit"), cancel => N("Retry"), }, []) or return; } } else { if (is_ntp_daemon_running()) { - system('systemctl', 'stop', "$ntpd.service"); - system('systemctl', 'disable', "$ntpd.service"); + system('systemctl', 'stop', $ntp_service); + system('systemctl', 'disable', $ntp_service); } } if ($need_date) { @@ -177,9 +175,9 @@ $button_reset = $w->{buttons}{N("Reset")}; $time_box->set_direction('ltr'); -my $servers = get_server(); -$combo_ntpserver->set_popdown_strings(@$servers); -if (-e $ntpfile && is_ntp_daemon_running()) { +my $servers = get_servers(); +$combo_ntp_pool->set_popdown_strings(@$servers); +if (-e $timezone::ntp_conf && is_ntp_daemon_running()) { $ntp = timezone::ntp_pool(); $ntp and ntp_widget_state(1); my $fullntp = $ntp; @@ -189,7 +187,7 @@ if (-e $ntpfile && is_ntp_daemon_running()) { foreach (@$servers) { /^[^:]+: \Q$short_ntp\E$/ and $fullntp = $_, last; } - $combo_ntpserver->entry->set_text($fullntp); + $combo_ntp_pool->entry->set_text($fullntp); } else { ntp_widget_state(0) } my $pressed; @@ -242,9 +240,10 @@ sub install_ntp() { $my_win->{window}->set_sensitive(1); } sub is_ntp_daemon_running() { - !system("systemctl is-active $ntpd.service >/dev/null"); + my $ntp_service = $timezone::ntpd . '.service'; + !system("systemctl is-active $ntp_service >/dev/null"); } -sub get_server() { +sub get_servers() { my $servs = timezone::ntp_servers(); [ map { "$servs->{$_}: $_" } sort { $servs->{$a} cmp $servs->{$b} || $a cmp $b } keys %$servs ]; } |
