include %(grml_flavour)s_grml.cfg
menu hide
menu end
-""" % {'grml_flavour': grml_flavour, 'display_name' : grml_flavour.replace('_', '-') } )
+""" % {'grml_flavour': grml_flavour, 'display_name' : get_flavour_filename(grml_flavour) } )
def install_grub(device):
execute(mkdir, conf_target)
return write_uuid(uuid_file_name)
+def get_shortname(grml_flavour):
+ """Get shortname based from grml_flavour name. The rules applied are the same as in grml-live
+ @grml_flavour: flavour name which shold be translated to shortname"""
+
+ return re.sub(r'[,._-]', '', grml_flavour)
def copy_system_files(grml_flavour, iso_mount, target):
"""copy grml's main files (like squashfs, kernel and initrd) to a given target
else:
exec_rsync(filesystem_module, squashfs_target + 'filesystem.module')
- kernel = search_file('vmlinuz', iso_mount)
- if kernel is None:
- # compat for releases < 2011.12
- kernel = search_file('linux26', iso_mount)
- if kernel is None:
- logging.critical("Fatal: kernel not found")
- raise CriticalException("error locating kernel file")
+ shortname = get_shortname(grml_flavour)
+ if os.path.isdir(iso_mount + '/boot/' + shortname):
+ exec_rsync(iso_mount + '/boot/' + shortname, target + '/boot')
+ else:
+ kernel = search_file('vmlinuz', iso_mount)
+ if kernel is None:
+ # compat for releases < 2011.12
+ kernel = search_file('linux26', iso_mount)
+
+ if kernel is None:
+ logging.critical("Fatal: kernel not found")
+ raise CriticalException("error locating kernel file")
- source = os.path.dirname(kernel) + '/'
- dest = target + '/' + os.path.dirname(kernel).replace(iso_mount,'') + '/'
- execute(mkdir, dest)
- exec_rsync(source, dest)
+ source = os.path.dirname(kernel) + '/'
+ dest = target + '/' + os.path.dirname(kernel).replace(iso_mount,'') + '/'
+ execute(mkdir, dest)
+ exec_rsync(source, dest)
def update_grml_versions(iso_mount, target):
else:
return False
-def copy_grml_files(iso_mount, target):
+def copy_grml_files(grml_flavour, iso_mount, target):
"""copy some minor grml files to a given target
+ @grml_flavour: the current grml_flavour
@iso_mount: path where a grml ISO is mounted on
@target: path where grml's main files should be copied to"""
grml_target = target + '/grml/'
execute(mkdir, grml_target)
- copy_files = [ 'grml-cheatcodes.txt', 'LICENSE.txt', 'md5sums', 'README.txt' ]
- # handle grml-version
- if not update_grml_versions(iso_mount, target):
- copy_files.append('grml-version')
-
- for myfile in copy_files:
- grml_file = search_file(myfile, iso_mount)
- if grml_file is None:
- logging.warn("Warning: file %s could not be found - can not install it", myfile)
- else:
- exec_rsync(grml_file, grml_target + myfile)
-
- grml_web_target = grml_target + '/web/'
- execute(mkdir, grml_web_target)
-
- for myfile in 'index.html', 'style.css':
- grml_file = search_file(myfile, iso_mount)
- if grml_file is None:
- logging.warn("Warning: file %s could not be found - can not install it", myfile)
- else:
- exec_rsync(grml_file, grml_web_target + myfile)
-
- grml_webimg_target = grml_web_target + '/images/'
- execute(mkdir, grml_webimg_target)
-
- for myfile in 'button.png', 'favicon.png', 'linux.jpg', 'logo.png':
- grml_file = search_file(myfile, iso_mount)
- if grml_file is None:
- logging.warn("Warning: file %s could not be found - can not install it", myfile)
- else:
- exec_rsync(grml_file, grml_webimg_target + myfile)
+ grml_prefixe = ["GRML", "grml"]
+ for prefix in grml_prefixe:
+ filename = "{0}/{1}/{2}".format(iso_mount, prefix, grml_flavour)
+ if os.path.exists(filename):
+ exec_rsync(filename, grml_target)
+ break
+ else:
+ logging.warn("Warning: could not find flavour directory for %s ", grml_flavour)
def handle_addon_copy(filename, dst, iso_mount, ignore_errors=False):
logging.info("Copying files. This might take a while....")
try:
copy_system_files(grml_flavour, iso_mount, target)
- copy_grml_files(iso_mount, target)
+ copy_grml_files(grml_flavour, iso_mount, target)
except CriticalException, error:
logging.critical("Execution failed: %s", error)
sys.exit(1)
for regex in options.removeoption:
remove_regexes.append(re.compile(regex))
+ shortname = get_shortname(grml_flavour)
for filename in glob.glob(grub_target + '*.cfg'):
for line in fileinput.input(filename, inplace=1):
line = line.rstrip("\r\n")
if option_re.search(line):
line = bootid_re.sub('', line)
- line = live_media_path_re.sub('', line)
- line = line.rstrip() + r' live-media-path=/live/%s/ bootid=%s %s ' % (grml_flavour, UUID, bootopt)
+ if shortname in filename:
+ line = live_media_path_re.sub('', line)
+ line = line.rstrip() + ' live-media-path=/live/%s/ ' % (grml_flavour)
+ line = line.rstrip() + r' bootid=%s %s ' % (UUID, bootopt)
for regex in remove_regexes:
line = regex.sub(' ', line)
print line
@target: directory where the files are located
@filenames: list of filenames to alter
"""
- grml_filename = grml_flavour.replace('-', '_')
+ grml_filename = get_flavour_filename(grml_flavour)
for filename in filenames:
old_filename = "%s/%s" % (target, filename)
new_filename = "%s/%s_%s" % (target, grml_filename, filename)
prompt_name.close()
initial_syslinux_config(syslinux_target)
- flavour_filename = grml_flavour.replace('-', '_')
+ flavour_filename = get_flavour_filename(grml_flavour)
if search_file('default.cfg', syslinux_target):
modify_filenames(grml_flavour, syslinux_target, ['grml.cfg', 'default.cfg'])
logging.critical("Fatal: rsync not available, can not continue - sorry.")
sys.exit(1)
+def load_loop():
+ """Runs modprobe loop and throws away it's output"""
+ proc = subprocess.Popen(["modprobe", "loop"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ proc.wait()
+
def main():
"""Main function [make pylint happy :)]"""
check_options(options)
+ load_loop()
+
logging.info("Executing grml2usb version %s", PROG_VERSION)
if options.dryrun:
check_programs()
# specified arguments
- device = args[len(args) - 1]
+ device = os.path.realpath(args[len(args) - 1])
isos = args[0:len(args) - 1]
if not os.path.isdir(device):