File: get_signature

package info (click to toggle)
lcov 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,412 kB
  • sloc: perl: 27,615; xml: 6,982; sh: 6,977; python: 1,147; makefile: 593; cpp: 455; ansic: 167
file content (74 lines) | stat: -rwxr-xr-x 2,126 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env perl
#   Copyright (c) MediaTek USA Inc., 2022
#
#   This program is free software;  you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or (at
#   your option) any later version.
#
#   This program is distributed in the hope that it will be useful, but
#   WITHOUT ANY WARRANTY;  without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#   General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program;  if not, see
#   <http://www.gnu.org/licenses/>.
#
#
# get_signature
#
#   This is a sample script which uses uses md5sum to compare file versions
#   If the checksum is not the same - then line numbers, etc. may be different
#   and some very strange errors may occur.
#   md5sum is not secure - so could use sha512sum or some other program, if we
#   really wanted to

use POSIX qw(strftime);
use Getopt::Long;
use Cwd qw(abs_path);

sub usage
{
    print(STDERR "usage: $0 --compare old_version new_version filename OR\n" .
          "       $0 [--allow-missing] filename\n");
}

my $compare;
my $allow_missing;
my $help;
if (!GetOptions("--compare"       => \$compare,
                '--allow-missing' => \$allow_missing,
                '--help'          => \$help) ||
    $help ||
    ($compare && scalar(@ARGV) != 3) ||
    (!$compare && scalar(@ARGV) != 1)
) {
    usage();
    exit(defined($help) ? 0 : 1);
}

my $filename = $ARGV[$compare ? 2 : 0];

if ($compare) {
    my ($old, $new) = @ARGV;
    exit($old ne $new);    # for the moment, just look for exact match
}

unless (-e $filename) {
    if ($allow_missing) {
        print("\n");       # empty string
        exit 0;
    }
    die("Error: $filename does not exist - perhaps you need the '--allow-missing' flag"
    );
}
$pathname = abs_path($filename);

#my $sum = `sha512sum $pathname`;
my $sum = `md5sum $pathname`;
my $rtn = $?;
$sum =~ /^(\S+)/;
print($1 . "\n");
exit $rtn;