+ # display only if the grml flavour isn't the default
+ if not grub_flavour_is_default:
+ GRML_FLAVOURS.add(grml_flavour)
+ grub2_config_file.write(generate_flavour_specific_grub2_config(grml_flavour, bootopt))
+ grub2_config_file.close()
+
+
+def handle_grub_config(grml_flavour, device, target):
+ """Main handler for generating grub (v1 and v2) configuration
+
+ @grml_flavour: name of grml flavour the configuration should be generated for
+ @device: device/partition where grub should be installed to
+ @target: path of grub's configuration files"""
+
+ logging.debug("Generating grub configuration")
+
+ grub_target = target + '/boot/grub/'
+ execute(mkdir, grub_target)
+
+ if os.path.isdir(device):
+ install_grub1_partition = None
+ else:
+ if device[-1:].isdigit():
+ install_grub1_partition = int(device[-1:]) - 1
+ else:
+ raise CriticalException("error validating partition schema (raw device?)")
+
+ # do NOT write "None" in kernel cmdline
+ if options.bootoptions is None:
+ bootopt = ""
+ else:
+ bootopt = options.bootoptions
+
+ # write menu.lst
+ handle_grub1_config(grml_flavour, install_grub1_partition, grub_target, bootopt)
+ # write grub.cfg
+ handle_grub2_config(grml_flavour, grub_target, bootopt)
+
+
+def initial_syslinux_config(target):
+ """Generates intial syslinux configuration
+
+ @target path of syslinux's configuration files"""
+
+ target = target + "/"
+ filename = target + "grmlmain.cfg"
+ if os.path.isfile(target + "grmlmain.cfg"):
+ return
+ data = open(filename, "w")
+ data.write(generate_main_syslinux_config())
+ data.close
+
+def adjust_syslinux_bootoptions(src_name, dst_name, flavour):
+ append_re = re.compile("^(\s*append.*)$", re.I)
+ boot_re = re.compile("/boot/([a-zA-Z0-9_]+/)+([a-zA-Z0-9._]+)")
+ flavour_re = re.compile("(label.*)(grml\w+)")
+ default_re = re.compile("(default.cfg)")
+ src = open(src_name, "r")
+ dst = open(dst_name, "w")
+
+ for line in src:
+ line = boot_re.sub(r'/boot/release/%s/\2 ' % flavour, line)
+ line = flavour_re.sub(r'\1 %s-\2' % flavour, line)
+ line = default_re.sub(r'%s-\1' % flavour, line)
+ line = append_re.sub(r'\1 live-media-path=/live/%s/ ' % flavour, line)
+ dst.write(line)
+ src.close()
+ dst.close()
+
+
+def add_syslinux_entry(filename, grml_flavour):
+ data = open(filename, "a+")
+ entry_filename = "option-%s.cfg" % grml_flavour
+ entry = "include %s\n" % entry_filename
+ path = os.path.dirname(filename)
+ for line in data:
+ if line == entry:
+ break
+ else:
+ data.write(entry)
+
+ data.close()
+ data = open(path + "/" + entry_filename, "w")
+ data.write(generate_flavour_specific_syslinux_config(grml_flavour))
+ data.close()
+
+