+ # 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()
+
+ modify_grub_config(grub2_cfg)
+
+
+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
+
+ filename = target + "hiddens.cfg"
+ data = open(filename, "w")
+ data.write("include hidden.cfg\n")
+ data.close()
+
+def add_entry_if_not_present(filename, entry):
+ data = open(filename, "a+")
+ for line in data:
+ if line == entry:
+ break
+ else:
+ data.write(entry)
+
+ data.close()
+
+def flavour_filename(flavour):
+ return flavour.replace('-', '_')
+
+def adjust_syslinux_bootoptions(src, flavour):
+ append_re = re.compile("^(\s*append.*/boot/release.*)$", 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)")
+ bootid_re = re.compile("bootid=[\w_-]+")
+ live_media_path_re = re.compile("live-media-path=[\w_/-]+")
+
+ # do NOT write "None" in kernel cmdline
+ if options.bootoptions is None:
+ bootopt = ""
+ else:
+ bootopt = options.bootoptions
+
+ regexe = []
+ option_re = None
+ if options.removeoption:
+ option_re = re.compile(r'/boot/release/.*/initrd.gz')
+
+ for regex in options.removeoption:
+ regexe.append(re.compile(r'%s' % regex))
+
+ global UUID
+ for line in fileinput.input(src, inplace=1):
+ line = boot_re.sub(r'/boot/release/%s/\2 ' % flavour.replace('-', ''), line)
+ # line = flavour_re.sub(r'\1 %s-\2' % flavour, line)
+ line = default_re.sub(r'%s-\1' % flavour, line)
+ line = bootid_re.sub('', line)
+ line = live_media_path_re.sub('', line)
+ line = append_re.sub(r'\1 live-media-path=/live/%s/ ' % flavour, line)
+ line = append_re.sub(r'\1 boot=live %s ' % bootopt, line)
+ line = append_re.sub(r'\1 %s=%s ' % ("bootid", UUID), line)
+ if option_re and option_re.search(line):
+ for regex in regexe:
+ line = regex.sub(' ', line)
+ sys.stdout.write(line)
+ fileinput.close()
+
+def adjust_labels(src, replacement):
+ label_re = re.compile("^(\s*label\s*) ([a-zA-Z0-9_-]+)", re.I)
+ for line in fileinput.input(src, inplace=1):
+ line = label_re.sub(replacement, line)
+ sys.stdout.write(line)
+ fileinput.close()
+
+
+def add_syslinux_entry(filename, grml_flavour):
+ entry_filename = "option_%s.cfg" % grml_flavour
+ entry = "include %s\n" % entry_filename
+
+ add_entry_if_not_present(filename, entry)
+ path = os.path.dirname(filename)
+
+ data = open(path + "/" + entry_filename, "w")
+ data.write(generate_flavour_specific_syslinux_config(grml_flavour))
+ data.close()
+
+def modify_filenames(grml_flavour, target, filenames):
+ grml_filename = grml_flavour.replace('-', '_')
+ for filename in filenames:
+ old_filename = "%s/%s" % (target, filename)
+ new_filename = "%s/%s_%s" % (target, grml_filename, filename)
+ os.rename(old_filename, new_filename)
+
+
+def remove_default_entry(filename):
+ default_re = re.compile("^(\s*menu\s*default\s*)$", re.I)
+ for line in fileinput.input(filename, inplace=1):
+ if default_re.match(line): continue
+ sys.stdout.write(line)
+ fileinput.close()