]> rtime.felk.cvut.cz Git - l4.git/blob - l4/tool/lib/L4/Grub.pm
9cc51aa4824dfa92c6abebc6357d706d5977581c
[l4.git] / l4 / tool / lib / L4 / Grub.pm
1 package L4::Grub;
2
3 use Exporter;
4 use vars qw(@ISA @EXPORT);
5 @ISA    = qw(Exporter);
6
7 use Getopt::Long;
8
9 sub parse_gengrub_args()
10 {
11   my %a = ( timeout => undef,
12             serial  => undef
13            );
14   my @opts = ("timeout=i", \$a{timeout},
15               "serial",    \$a{serial});
16
17   if (!GetOptions(@opts))
18     {
19       print "Command line parsing failed.\n";
20     }
21
22   if (0)
23     {
24       print "Options:\n";
25       print "timeout: $a{timeout}\n" if defined $a{timeout};
26       print "serial : $a{serial}\n" if defined $a{serial};
27     }
28
29   %a;
30 }
31
32 sub prepare_grub1_dir($)
33 {
34   my $dir = shift;
35
36   return if -e "$dir/boot/grub/stage2_eltorito";
37
38   my $copypath;
39   my @grub_path = ("/usr/lib/grub/i386-pc", "/usr/share/grub/i386-pc",
40                    "/boot/grub", "/usr/local/lib/grub/i386-pc",
41                    "/usr/lib/grub/x86_64-pc");
42   unshift @grub_path, $ENV{GRUB_PATH} if defined $ENV{GRUB_PATH};
43
44   foreach my $p (@grub_path) {
45     $copypath=$p if -e "$p/stage2_eltorito";
46   }
47   die "Cannot find a stage2_eltorito file..." unless defined $copypath;
48
49   # copy files
50   mkdir "$dir/boot";
51   mkdir "$dir/boot/grub";
52   system("cp $copypath/stage2_eltorito $dir/boot/grub");
53   chmod 0644, "$dir/boot/grub/stage2_eltorito";
54 }
55
56 sub grub1_mkisofs($$@)
57 {
58   my ($isofilename, $dir, @morefiles) = @_;
59   system("cp -v ".join(' ', @morefiles)." $dir") if @morefiles;
60   my $cmd = "mkisofs -f -R -b boot/grub/stage2_eltorito".
61             " -no-emul-boot -boot-load-size 4 -boot-info-table".
62             " -hide-rr-moved -J -joliet-long -o \"$isofilename\" \"$dir\"";
63
64   print "Generating GRUB1 image with cmd: $cmd\n";
65   system("$cmd");
66   die "Failed to create ISO" if $?;
67 }
68
69 sub prepare_grub2_dir($)
70 {
71   my $dir = shift;
72   mkdir "$dir/boot";
73   mkdir "$dir/boot/grub";
74 }
75
76 sub grub2_mkisofs($$@)
77 {
78   my ($isofilename, $dir, @morefiles) = @_;
79   my $cmd = "grub_mkisofs_arguments=-f grub-mkrescue"
80             ." --output=\"$isofilename\" $dir ".join(' ', @morefiles);
81   system("$cmd");
82   die "Failed to create ISO" if $?;
83 }