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