Upgrade yt-dlp from version stable@2023.07.06 to stable@2023.09.24
[sunny256-utils.git] / pmsetdate
blob8fd4626eb9ff33d44997c9cc5f358af0ec1b9a57
1 #!/usr/bin/env perl
3 #=======================================================================
4 # pmsetdate
5 # File ID: c524eb1a-f743-11dd-9167-000475e441b9
6 # [Description]
8 # Character set: UTF-8
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 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
17 use Time::HiRes qw{ gettimeofday };
19 $| = 1;
21 our $Debug = 0;
23 our %Opt = (
25 'debug' => 0,
26 'help' => 0,
27 'verbose' => 0,
28 'version' => 0,
32 our $progname = $0;
33 $progname =~ s/^.*\/(.*?)$/$1/;
34 our $VERSION = "0.00";
36 Getopt::Long::Configure("bundling");
37 GetOptions(
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'}) {
49 print_version();
50 exit(0);
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");
75 system($cmd_str);
76 printf("New date: " . localtime(gettimeofday) . "\n");
78 sub print_version {
79 # Print program version {{{
80 print("$progname v$VERSION\n");
81 # }}}
82 } # print_version()
84 sub usage {
85 # Send the help message to stdout {{{
86 my $Retval = shift;
88 if ($Opt{'verbose'}) {
89 print("\n");
90 print_version();
92 print(<<END);
94 Usage: $progname [options] [file [files [...]]]
96 Options:
98 -h, --help
99 Show this help.
100 -v, --verbose
101 Increase level of verbosity. Can be repeated.
102 --version
103 Print version information.
104 --debug
105 Print debugging messages.
108 exit($Retval);
109 # }}}
110 } # usage()
112 sub msg {
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");
119 # }}}
120 } # msg()
122 sub D {
123 # Print a debugging message {{{
124 $Debug || return;
125 my @call_info = caller;
126 chomp(my $Txt = shift);
127 my $File = $call_info[1];
128 $File =~ s#\\#/#g;
129 $File =~ s#^.*/(.*?)$#$1#;
130 print(STDERR "$File:$call_info[2] $$ $Txt\n");
131 return("");
132 # }}}
133 } # D()
135 __END__
137 # Plain Old Documentation (POD) {{{
139 =pod
141 =head1 NAME
145 =head1 SYNOPSIS
147 [options] [file [files [...]]]
149 =head1 DESCRIPTION
153 =head1 OPTIONS
155 =over 4
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.
165 =item B<--version>
167 Print version information.
169 =item B<--debug>
171 Print debugging messages.
173 =back
175 =head1 BUGS
179 =head1 AUTHOR
181 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
183 =head1 COPYRIGHT
185 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
186 This is free software; see the file F<COPYING> for legalese stuff.
188 =head1 LICENCE
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
201 with this program.
202 If not, see L<http://www.gnu.org/licenses/>.
204 =head1 SEE ALSO
206 =cut
208 # }}}
210 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :