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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# This file is part of the Mageia project
# Copyright (C) 2011 Damien Lallement <dams@mageia.org>
# (C) 2011 Romain D'Alverny <rda@mageia.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public License
# along with this library; see the file COPYING.LIB. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
use Test::Most;
use File::Basename;
use MDK::ISOcheck;
my ($image_path) = @ARGV;
my $name = basename($image_path);
my %info;
bail_on_fail;
%info = parse_image_file_name($name);
if (scalar %info) {
pass 'Image has a valid filename.';
while (my ($k, $v) = each %info) {
note uc($k), "=$v\n" if defined $v;
}
} else {
fail 'Image has a valid filename.';
diag 'See https://wiki.mageia.org/en/Product_naming for more information.';
}
# is file size correct?
my $du = `du --apparent-size --block-size=MB $image_path`;
my @size_name = split(/\t/, $du);
my $size = $size_name[0];
my %max_sizes = ("CD" => "700MB", "DVD" => "4700MB");
ok($size le $max_sizes{$info{medium}}, "File has a valid size.");
diag(sprintf("File is %s. Max size for %s is %s.", $size, $info{medium}, $max_sizes{$info{medium}}));
# verify checksums
ok -r $image_path . '.md5', 'MD5 checksum is available.';
ok -r $image_path . '.sha1', 'SHA1 checkum is available.';
my $md5file = $image_path . '.md5';
my $sha1file = $image_path . '.sha1';
my @ts = split(/ /, `md5sum $image_path`);
my $md5 = $ts[0];
@ts = split(/ /, `cat $md5file`);
$md5file = $ts[0];
is($md5, $md5file, 'MD5/.md5 checksums match.');
@ts = split(/ /, `sha1sum $image_path`);
my $sha1 = $ts[0];
@ts = split(/ /, `cat $sha1file`);
$sha1file = $ts[0];
is($sha1, $sha1file, 'SHA1/.sha1 checksums match.');
if (!defined $info{'release'}) {
ok -r $image_path . '.md5.gpg', 'MD5.gpg is available.';
ok -r $image_path . '.sha1.gpg', 'SHA1.gpg is available.';
# TODO check signature are valid!
}
# check ISO header info
# Check (see http://wiki.mandriva.com/en/Product_id)
my $isoinfo = `isoinfo -d -i $image_path`;
my %isoValues = (
"System id", 'LINUX',
"Volume id", sprintf('%s %s %s',
$info{name}, $info{version},
(defined $info{release}) ? $info{release} : ''),
"Volume set id", sprintf('%s %s %s %s %s %s',
$info{name}, $info{version},
(defined $info{release}) ? $info{release} : '',
$info{variant}, $info{arch}, $info{medium}),
"Publisher id", 'Mageia.org',
"Data preparer id", 'Mageia BCD',
"Copyright File id", sprintf('http://www.mageia.org/%s/license/',
$info{version}),
"Abstract File id", sprintf('http://www.mageia.org/%s/',
$info{version})
);
my $testval;
while (my ($k, $v) = each(%isoValues)) {
$testval = `printf "%s\n" "$isoinfo" | grep -i "$k:" |tr -d '\n'`;
# not testing right now, all expected values are not sure yet.
# is $testval, "$k: $v", "$k is correct. Found $testval.";
note "Found: $testval \nExpected: $k: $v";
}
# bootable?
ok(`isoinfo -d -i $image_path | grep bootable`, 'ISO is bootable.');
# TODO check burnable?
my $burner = "/dev/sr0";
# FIXME is -eject really needed?
my $_burning = `cdrecord -dummy speed=42 dev=$burner -v -eject -data $image_path 2> is_burnable.log`;
my $result = `cat is_burnable.log | grep overburn | wc -l | tr -d '\n'`;
-r "is_burnable.log" and system "rm is_burnable.log";
is($result, 0, "ISO can be burnt.");
done_testing();
|