-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpar2-verify
More file actions
executable file
·76 lines (59 loc) · 1.59 KB
/
par2-verify
File metadata and controls
executable file
·76 lines (59 loc) · 1.59 KB
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
75
76
#!/usr/bin/env perl
use strict;
use warnings;
use File::Copy::Recursive qw(dircopy);
use File::Temp;
use Getopt::Std;
use POSIX qw(EXIT_SUCCESS EXIT_FAILURE);
sub signature {
# FIXME: We're not verifying who really signed it
my $exitCode = system('gpg --verify CHECKSUM.SHA512.asc');
if ($exitCode != 0) {
print(STDERR "Signature verification failed\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
sub checksum {
my $exitCode = system('sha512sum -c CHECKSUM.SHA512');
if ($exitCode != 0) {
print(STDERR "Hash verification failed\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
sub indirect {
my $template = "/var/tmp/$ENV{USER}/verify-par2-parity_XXXXXXXXXX";
my $tmpdir = File::Temp->newdir($template, CLEANUP => 1);
system("file $tmpdir");
$File::Copy::Recursive::CPRFComp = 1;
dircopy('.', "$tmpdir/") or die $!;
chdir("$tmpdir") or die $!;
return $tmpdir;
}
sub par2 {
my ($args) = @_;
my ($indirection) = @{$args}{qw(indirection)};
# hold temporary directory reference open until we're finished, it will self-destruct
my $tmpdir;
$tmpdir = indirect() if ($indirection);
my $exitCode = system('par2 v parity.par2');
chdir('/');
if ($exitCode != 0) {
print(STDERR "PAR2 verification failed\n");
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
sub main {
my %opts;
if (!getopts('t', \%opts)) {
return EXIT_FAILURE;
}
return EXIT_FAILURE if (signature() == EXIT_FAILURE);
return EXIT_FAILURE if (checksum() == EXIT_FAILURE);
return EXIT_FAILURE if (par2({ indirection => $opts{t} }) == EXIT_FAILURE);
system('beep');
return EXIT_SUCCESS;
}
exit(main());