File timestamp.pl of Package shim
147
1
#!/usr/bin/perl -w
2
# Copyright (c) 2012-2021 SUSE LLC
3
#
4
# Permission is hereby granted, free of charge, to any person obtaining a copy
5
# of this software and associated documentation files (the "Software"), to deal
6
# in the Software without restriction, including without limitation the rights
7
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
# copies of the Software, and to permit persons to whom the Software is
9
# furnished to do so, subject to the following conditions:
10
#
11
# The above copyright notice and this permission notice shall be included in
12
# all copies or substantial portions of the Software.
13
#
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
# SOFTWARE.
21
22
= .
23
24
. - or
25
26
=
27
28
. [ ] ...
29
30
=
31
32
= 4
33
34
=item B<--set-form-file=FILE>
35
36
parse timestamp, checksum, and linker version from file
37
38
=item B<--help, -h>
39
40
print help
41
42
=back
43
44
=head1 DESCRIPTION
45
46
lorem ipsum ...
47
48
=cut
49
50
use ;
51
use :: ;
52
:::: ("no_ignore_case");
53
use qw/strftime/;
54
55
my %options;
56
57
sub ($) {
58
my $r = shift;
59
eval "use Pod::Usage; pod2usage($r);";
60
if ($@) {
61
die "cannot display help, install perl(Pod::Usage)\n";
62
}
63
}
64
65
(
66
\%options,
67
"set-from-file=s",
68
"verbose|v",
69
"help|h",
70
) or (1);
71
72
1) unless @ARGV; (
73
0) if ($options{'help'}); (
74
75
my $set_timestamp;
76
my $set_checksum;
77
my $set_linker;
78
79
if ($options{'set-from-file'}) {
80
die "$options{'set-from-file'}: $!\n" unless open(my $fh, '<', $options{'set-from-file'});
81
while (<$fh>) {
82
chomp;
83
if (/^: ([0-9- ]+)/) {
84
$set_timestamp = pack('L', hex($1));
85
next;
86
} elsif (/^: ([0-9- ]+)/) {
87
$set_linker = pack('S', hex($1));
88
next;
89
} elsif (/^: ([0-9- ]+)/) {
90
$set_checksum = pack('S', hex($1));
91
next;
92
}
93
last if $set_timestamp && $set_checksum && $set_linker;
94
}
95
close($fh);
96
die "file didn't contain timestamp, checksum, or linker\n" unless $set_timestamp && $set_checksum && $set_linker;
97
}
98
99
sub ($)
100
{
101
my $file = shift;
102
die "$file: $!\n" unless open(my $fh, '<', $file);
103
die "seek $file: $!\n" unless seek($fh, 136, 0);
104
my $value;
105
die "read $file: $!\n" unless read($fh, $value, 4);
106
107
my $timestamp = unpack('L', $value);
108
print ("# %Y-%m-%d %H:%M:%S\n", gmtime($timestamp));
109
printf ("timestamp: %x\n", $timestamp);
110
111
die "seek $file: $!\n" unless seek($fh, 154, 0);
112
die "read $file: $!\n" unless read($fh, $value, 2);
113
114
printf ("linker: %x\n", unpack('S', $value));
115
116
die "seek $file: $!\n" unless seek($fh, 216, 0);
117
die "read $file: $!\n" unless read($fh, $value, 2);
118
119
printf ("checksum: %x\n", unpack('S', $value));
120
121
close($fh);
122
}
123
124
sub ($)
125
{
126
my $file = shift;
127
die "$file: $!\n" unless open(my $fh, '+<', $file);
128
die "seek $file: $!\n" unless seek($fh, 136, 0);
129
die "write $file: $!\n" unless print $fh $set_timestamp;
130
131
die "seek $file: $!\n" unless seek($fh, 154, 0);
132
die "write $file: $!\n" unless print $fh $set_linker;
133
134
die "seek $file: $!\n" unless seek($fh, 216, 0);
135
die "read $file: $!\n" unless print $fh $set_checksum;
136
close($fh);
137
}
138
139
for my $file (@ARGV) {
140
if ($options{'set-from-file'}) {
141
($file);
142
} else {
143
($file);
144
}
145
146
}
147