]>
Commit | Line | Data |
---|---|---|
2132f071 FG |
1 | #!/usr/bin/perl -w |
2 | ||
3 | use PVE::Tools; | |
4 | ||
5 | use IO::File; | |
6 | ||
a4ed0977 | 7 | sub usage { |
eae1bbd4 | 8 | die "USAGE: $0 INFILE OUTFILE [ABI INFILE-IS-DEB]\n"; |
a4ed0977 TL |
9 | } |
10 | ||
11 | my $input_file = shift // usage(); | |
12 | my $output_file = shift // usage(); | |
eae1bbd4 | 13 | my $abi = shift; |
2132f071 FG |
14 | my $extract_deb = shift; |
15 | ||
16 | die "input file '$input_file' does not exist\n" if ! -e $input_file; | |
17 | ||
18 | my $modules_symver_fh; | |
19 | ||
20 | if ($extract_deb) { | |
eae1bbd4 | 21 | usage() if !defined($abi); |
2132f071 FG |
22 | my $cmd = []; |
23 | push @$cmd, ['dpkg', '--fsys-tarfile', $input_file]; | |
24 | push @$cmd, ['tar', '-xOf', '-', "./usr/src/linux-headers-${abi}/Module.symvers"]; | |
25 | $modules_symver_fh = IO::File->new_tmpfile(); | |
26 | PVE::Tools::run_command($cmd, output => '>&'.fileno($modules_symver_fh)); | |
27 | seek($modules_symver_fh, 0, 0); | |
28 | } else { | |
29 | open($modules_symver_fh, '<', $input_file) or die "can't open '$input_file' - $!\n"; | |
30 | } | |
31 | ||
32 | my $lines = []; | |
33 | while(my $line = <$modules_symver_fh>) { | |
34 | if ($line =~ /^(.+)\s+(.+)\s+(.+)$/) { | |
35 | push @$lines, "$3 $2 $1"; | |
36 | } else { | |
37 | warn "malformed symvers line: '$line'\n"; | |
38 | } | |
39 | } | |
40 | close($modules_symver_fh); | |
41 | ||
42 | PVE::Tools::file_set_contents($output_file, join("\n", sort @$lines)); |