3 #=======================================================================
5 # File ID: c524eb1a-f743-11dd-9167-000475e441b9
9 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
17 use Time
::HiRes
qw{ gettimeofday
};
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = "0.00";
36 Getopt
::Long
::Configure
("bundling");
39 "debug" => \
$Opt{'debug'},
40 "help|h" => \
$Opt{'help'},
41 "verbose|v+" => \
$Opt{'verbose'},
42 "version" => \
$Opt{'version'},
44 ) || die("$progname: Option error. Use -h for help.\n");
46 $Opt{'debug'} && ($Debug = 1);
47 $Opt{'help'} && usage
(0);
48 if ($Opt{'version'}) {
53 chomp(my $server_text = `ntpdate -q pool.ntp.org`);
55 D
("=== server_diff \x7B\x7B\x7B\n$server_text=== \x7D\x7D\x7D");
57 my $server_diff = $server_text;
58 D
("server_diff = '$server_diff'");
60 $server_diff =~ s/^\s*(.*?)\s*$/$1/s;
61 $server_diff =~ s/^.*?(\S+) sec$/$1/s;
62 D
("server_diff = '$server_diff'");
64 my $currtime = gettimeofday
();
65 D
("currtime = '$currtime'");
67 my $newtime = $currtime + $server_diff;
68 my $time_text = localtime($newtime);
70 D
("newtime = '$newtime'");
71 my $cmd_str = "date -s \"$time_text\"";
72 D
("cmd_str = '$cmd_str'");
74 printf("Old date: " . localtime(gettimeofday
) . "\n");
76 printf("New date: " . localtime(gettimeofday
) . "\n");
79 # Print program version {{{
80 print("$progname v$VERSION\n");
85 # Send the help message to stdout {{{
88 if ($Opt{'verbose'}) {
94 Usage: $progname [options] [file [files [...]]]
101 Increase level of verbosity. Can be repeated.
103 Print version information.
105 Print debugging messages.
113 # Print a status message to stderr based on verbosity level {{{
114 my ($verbose_level, $Txt) = @_;
116 if ($Opt{'verbose'} >= $verbose_level) {
117 print(STDERR
"$progname: $Txt\n");
123 # Print a debugging message {{{
125 my @call_info = caller;
126 chomp(my $Txt = shift);
127 my $File = $call_info[1];
129 $File =~ s
#^.*/(.*?)$#$1#;
130 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
137 # Plain Old Documentation (POD) {{{
147 [options] [file [files [...]]]
157 =item B<-h>, B<--help>
159 Print a brief help summary.
161 =item B<-v>, B<--verbose>
163 Increase level of verbosity. Can be repeated.
167 Print version information.
171 Print debugging messages.
181 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
185 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
186 This is free software; see the file F<COPYING> for legalese stuff.
190 This program is free software: you can redistribute it and/or modify it
191 under the terms of the GNU General Public License as published by the
192 Free Software Foundation, either version 2 of the License, or (at your
193 option) any later version.
195 This program is distributed in the hope that it will be useful, but
196 WITHOUT ANY WARRANTY; without even the implied warranty of
197 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
198 See the GNU General Public License for more details.
200 You should have received a copy of the GNU General Public License along
202 If not, see L<http://www.gnu.org/licenses/>.
210 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :