Merge remote-tracking branch 'flapflap/de-network_configuration'
[tails-test.git] / config / chroot_local-includes / usr / local / bin / tails-htp-notify-user
blob256e3dacd1926ad81f23a06ecb15cce5760a5727
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
5 use 5.10.1;
7 #man{{{
9 =head1 NAME
11 tails-htp-notify-user
13 =head1 VERSION
15 Version X.XX
17 =head1 AUTHOR
19 Tails dev team <tails@boum.org>
20 See https://tails.boum.org/.
22 =cut
24 #}}}
26 use Data::Dumper;
27 use Desktop::Notify;
28 use English '-no_match_vars';
29 use Locale::gettext;
30 use POSIX;
32 ### initialization
33 setlocale(LC_MESSAGES, "");
34 textdomain("tails");
35 my $htp_done_file = '/var/run/htpdate/done';
36 my $htp_success_file = '/var/run/htpdate/success';
37 my $htp_log_file = '/var/log/htpdate.log';
38 my $debug;
40 ### subroutines
42 sub debug { say STDERR $_[0] if $debug; }
44 ### main
46 exit 0 if -e $htp_success_file;
48 my $notify = Desktop::Notify->new()
49 or die "Failed creating Desktop::Notify object.";
50 debug('$notify:' . "\n" . Dumper($notify));
52 my $summary = gettext("Synchronizing the system's clock");
53 my $body = gettext("Tor needs an accurate clock to work properly, especially for Hidden Services. Please wait...");
55 my $notification = $notify->create(summary => $summary,
56 body => $body,
57 timeout => 0)
58 or die "Failed to create notification object";
59 debug('$notification:' . "\n" . Dumper($notification));
61 # Wait until notifications can be shown
62 until (system("pidof", "nm-applet") == 0) {
63 sleep 1
66 $notification->show() or warn "Failed showing notification.";
68 # Wait until htpdate is done
69 until ( -e $htp_done_file ) {
70 sleep 1;
73 $notification->close();
75 # in case htpdate failed, notify the user with the corresponding logs
76 unless (-e $htp_success_file) {
77 open(my $htp_log, '<', $htp_log_file)
78 or die "Can not open file '$htp_log_file': $OS_ERROR";
79 my $last_log;
80 while (<$htp_log>) {
81 if ($_ =~ /^Running htpdate\./) {
82 $last_log = '';
83 next;
85 $last_log .= $_;
87 my $failure_summary = gettext("Failed to synchronize the clock!");
88 my $failure_body = $last_log;
89 my $failure_notification = $notify->create(summary => $failure_summary,
90 body => $failure_body,
91 timeout => 0);
92 $failure_notification->show();