Update debian/watch, debian/lilo.* and debian/lilo-doc.*
[rrq/maintain_lilo.git] / debian / lilo_find_mbr
1 #!/usr/bin/perl
2
3 my $root_part;
4 if($#ARGV != -1)
5 {
6   $root_part = $ARGV[0];
7 }
8 else
9 {
10   $root_part = `awk '{ if (\$2=="/") print \$1}' </etc/fstab`;
11 }
12 my $lilo_root_part;
13 foreach $item (split("\n", $root_part))
14 {
15   if(not $item =~ /#/)
16   {
17     $lilo_root_part = $item;
18   }
19 }
20 if($lilo_root_part =~ /\/dev\/md/)
21 {
22   my $mdname = $lilo_root_part;
23   $mdname =~ s/\/dev\///;
24   $mdname =~ s/\///;
25   my $md = `grep $mdname /proc/mdstat`;
26   my @devices = split(" ", $md);
27   @devices = sort(@devices[4..$#devices]);
28   $lilo_root_part = "/dev/" . $devices[0];
29   $lilo_root_part =~ s/\[.*$//;
30 }
31 my $lilo_root_disk = $lilo_root_part;
32 $lilo_root_disk =~ s/\d+$//;
33 $lilo_root_disk =~ s/part$/disc/;
34
35 print $lilo_root_disk . "\n";