File grubby-compat.diff of Package cobbler

Index: scripts/grubby-compat
===================================================================
--- /dev/null
+++ scripts/grubby-compat
@@ -0,0 +1,57 @@
+#! /usr/bin/perl
+
+use POSIX;
+use Getopt::Long;
+use Pod::Usage;
+use Bootloader::Tools;
+use strict;
+
+my %oper;
+my ($opt_args, $opt_update, $opt_initrd, $opt_add_image, $opt_default, $opt_title)
+    = ("",0,'','',undef,'');
+
+# dummy option - we need it always as 0 but koan may set it.
+my $opt_copydefault = 0;
+
+GetOptions (\%oper,
+    'add-kernel=s' => \$opt_add_image,
+    'bootloader-probe' ,
+    'update-kernel' => \$opt_update,
+    'make-default',
+    'args=s'      => \$opt_args,
+    'initrd=s'      => \$opt_initrd,
+    'title=s' => \$opt_title,
+    'copy-default' => \$opt_copydefault)
+    or pod2usage(2);
+
+if (defined $oper{'bootloader-probe'}){
+  print Bootloader::Tools::GetBootloader();
+  exit 0;
+}
+
+my $lib = InitLibrary();
+
+if ($opt_add_image ne ''){
+  print "add kernel\n";
+  my @sections = @{$lib->GetSections ()};
+  my $section = { 'name' => $opt_title,
+                  'append' => $opt_args,
+                  'type' => "image",
+                  'initrd' => $opt_initrd,
+                  'image' => $opt_add_image,
+                  'original_name' => 'linux',
+                  '__modified' => '1',
+                  'root' => $lib->GetMountPoints()->{"/"}};
+  unshift @sections, $section;
+  $lib->SetSections (\@sections);
+  print "set sections\n";
+  if (defined $oper{'make-default'}){
+    my $glob_ref = $lib->GetGlobalSettings();
+    $glob_ref->{"default"} = $section->{"name"};
+    $lib->SetGlobalSettings ($glob_ref);
+  }
+  $lib->WriteSettings(1);
+  $lib->UpdateBootloader (1);
+  print "bootloader updated\n";
+  Bootloader::Tools::DumpLog($lib->{"loader"});
+}
Index: koan/app.py
===================================================================
--- koan/app.py.orig
+++ koan/app.py
@@ -1035,7 +1035,11 @@ class Koan:
                return (0, "grub")
             else:
                return (0, "lilo") 
-        cmd = [ "/sbin/grubby", "--bootloader-probe" ]
+        (make, version) = utils.os_release()
+        grubby_bin = "/sbin/grubby"
+        if (make == "suse"):
+            grubby_bin = "/usr/sbin/grubby-compat"
+        cmd = [ grubby_bin, "--bootloader-probe" ]
         probe_process = sub_process.Popen(cmd, stdout=sub_process.PIPE)
         which_loader = probe_process.communicate()[0]
         return probe_process.returncode, which_loader
@@ -1061,11 +1065,16 @@ class Koan:
         def after_download(self, profile_data):
             use_grubby = False
             use_grub2 = False
+            use_grubby_compat = False
             (make, version) = utils.os_release()
             if make in ['ubuntu', 'debian']:
                 if not os.path.exists("/usr/sbin/update-grub"):
                     raise InfoException, "grub2 is not installed"
                 use_grub2 = True
+            elif (make == "suse"):
+                if not os.path.exists("/usr/sbin/grubby-compat"):
+                    raise InfoException, "grub2 is not installed"
+                use_grubby_compat = True
             else:
                 if not os.path.exists("/sbin/grubby"):
                     raise InfoException, "grubby is not installed"
@@ -1123,7 +1132,7 @@ class Koan:
                     cmd.append("--copy-default")
 
                 boot_probe_ret_code, probe_output = self.get_boot_loader_info()
-                if boot_probe_ret_code == 0 and string.find(probe_output, "lilo") >= 0:
+                if boot_probe_ret_code == 0 and string.find(probe_output, "lilo") >= 0 and make != "suse":
                     cmd.append("--lilo")
 
                 if self.add_reinstall_entry:
@@ -1173,10 +1182,32 @@ class Koan:
                 else:
                     # if grubby --bootloader-probe returns lilo,
                     #    apply lilo changes
-                    if boot_probe_ret_code == 0 and string.find(probe_output, "lilo") != -1:
+                    if boot_probe_ret_code == 0 and probe_output.startswith("lilo"):
                         print "- applying lilo changes"
                         cmd = [ "/sbin/lilo" ]
-                        utils.subprocess_call(cmd)
+                    elif boot_probe_ret_code == 0 and probe_output.startswith("elilo"):
+                        print "- applying elilo changes"
+                        cmd = [ "/sbin/elilo" ]
+                    utils.subprocess_call(cmd)
+
+            elif use_grubby_compat:
+                kargs_string = "%s" % k_args
+                cmd = [ "/usr/sbin/grubby-compat",
+                        "--add-kernel", self.safe_load(profile_data,'kernel_local'),
+                        "--initrd", self.safe_load(profile_data,'initrd_local'),
+                        "--args", kargs_string
+                ]
+
+                if self.add_reinstall_entry:
+                    cmd.append("--title=Reinstall")
+                else:
+                    cmd.append("--make-default")
+                    cmd.append("--title=kick%s" % int(time.time()))
+
+                if self.live_cd:
+                    raise InfoException, "Live CD not supported by grubby-compat"
+
+                utils.subprocess_call(cmd)
 
             elif use_grub2:
                 # Use grub2 for --replace-self
Index: setup.py
===================================================================
--- setup.py.orig
+++ setup.py
@@ -605,7 +605,7 @@ if __name__ == "__main__":
         ],
         data_files = [
             # tftpd, hide in /usr/sbin
-            ("sbin", ["bin/tftpd.py"]),
+            ("sbin", ["bin/tftpd.py", "scripts/grubby-compat"]),
 
             ("%s" % webconfig,              ["build/config/cobbler.conf"]),
             ("%s" % webconfig,              ["build/config/cobbler_web.conf"]),
openSUSE Build Service is sponsored by