+
+ # TODO
+ # * provide alternative search_file() if file information is stored in a config.ini file?
+ # * catch "install: .. No space left on device" & CO
+ # * abstract copy logic to make the code shorter and get rid of spaghettis ;)
+
+ if options.dryrun:
+ logging.info("Would copy files to %s", iso_mount)
+ return 0
+ elif not options.bootloaderonly:
+ logging.info("Copying files. This might take a while....")
+
+ squashfs = search_file(grml_flavour + '.squashfs', iso_mount)
+ if squashfs is None:
+ logging.critical("Fatal: squashfs file not found")
+ else:
+ squashfs_target = target + '/live/'
+ execute(mkdir, squashfs_target)
+ # use install(1) for now to make sure we can write the files afterwards as normal user as well
+ logging.debug("cp %s %s" % (squashfs, target + '/live/' + grml_flavour + '.squashfs'))
+ proc = subprocess.Popen(["install", "--mode=664", squashfs, squashfs_target + grml_flavour + ".squashfs"])
+ proc.wait()
+
+ filesystem_module = search_file('filesystem.module', iso_mount)
+ if filesystem_module is None:
+ logging.critical("Fatal: filesystem.module not found")
+ else:
+ logging.debug("cp %s %s" % (filesystem_module, squashfs_target + grml_flavour + '.module'))
+ proc = subprocess.Popen(["install", "--mode=664", filesystem_module, squashfs_target + grml_flavour + '.module'])
+ proc.wait()
+
+ release_target = target + '/boot/release/' + grml_flavour
+ execute(mkdir, release_target)
+
+ kernel = search_file('linux26', iso_mount)
+ if kernel is None:
+ logging.critical("Fatal kernel not found")
+ else:
+ logging.debug("cp %s %s" % (kernel, release_target + '/linux26'))
+ proc = subprocess.Popen(["install", "--mode=664", kernel, release_target + '/linux26'])
+ proc.wait()
+
+ initrd = search_file('initrd.gz', iso_mount)
+ if initrd is None:
+ logging.critical("Fatal: initrd not found")
+ else:
+ logging.debug("cp %s %s" % (initrd, release_target + '/initrd.gz'))
+ proc = subprocess.Popen(["install", "--mode=664", initrd, release_target + '/initrd.gz'])
+ proc.wait()
+
+ grml_target = target + '/grml/'
+ execute(mkdir, grml_target)
+
+ for myfile in 'grml-cheatcodes.txt', 'grml-version', 'LICENSE.txt', 'md5sums', 'README.txt':
+ grml_file = search_file(myfile, iso_mount)
+ if grml_file is None:
+ logging.warn("Warning: myfile %s could not be found - can not install it", myfile)
+ else:
+ logging.debug("cp %s %s" % (grml_file, grml_target + grml_file))
+ proc = subprocess.Popen(["install", "--mode=664", grml_file, grml_target + myfile])
+ proc.wait()
+
+ 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: myfile %s could not be found - can not install it")
+ else:
+ logging.debug("cp %s %s" % (grml_file, grml_web_target + grml_file))
+ proc = subprocess.Popen(["install", "--mode=664", grml_file, grml_web_target + myfile])
+ proc.wait()
+
+ 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: myfile %s could not be found - can not install it")
+ else:
+ logging.debug("cp %s %s" % (grml_file, grml_webimg_target + grml_file))
+ proc = subprocess.Popen(["install", "--mode=664", grml_file, grml_webimg_target + myfile])
+ proc.wait()
+
+ if not options.skipaddons:
+ addons = target + '/boot/addons/'
+ execute(mkdir, addons)
+
+ # grub all-in-one image
+ allinoneimg = search_file('allinone.img', iso_mount)
+ if allinoneimg is None:
+ logging.warn("Warning: allinone.img not found - can not install it")
+ else:
+ logging.debug("cp %s %s" % (allinoneimg, addons + '/allinone.img'))
+ proc = subprocess.Popen(["install", "--mode=664", allinoneimg, addons + 'allinone.img'])
+ proc.wait()
+
+ # freedos image
+ balderimg = search_file('balder10.imz', iso_mount)
+ if balderimg is None:
+ logging.warn("Warning: balder10.imz not found - can not install it")
+ else:
+ logging.debug("cp %s %s" % (balderimg, addons + '/balder10.imz'))
+ proc = subprocess.Popen(["install", "--mode=664", balderimg, addons + 'balder10.imz'])
+ proc.wait()
+
+ # memtest86+ image
+ memdiskimg = search_file('memdisk', iso_mount)
+ if memdiskimg is None:
+ logging.warn("Warning: memdisk not found - can not install it")
+ else:
+ logging.debug("cp %s %s" % (memdiskimg, addons + '/memdisk'))
+ proc = subprocess.Popen(["install", "--mode=664", memdiskimg, addons + 'memdisk'])
+ proc.wait()
+
+ if not options.copyonly:
+ syslinux_target = target + '/boot/syslinux/'
+ execute(mkdir, syslinux_target)
+
+ logo = search_file('logo.16', iso_mount)
+ logging.debug("cp %s %s" % (logo, syslinux_target + 'logo.16'))
+ proc = subprocess.Popen(["install", "--mode=664", logo, syslinux_target + 'logo.16'])
+ proc.wait()
+
+ for ffile in 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'f10':
+ bootsplash = search_file(ffile, iso_mount)
+ logging.debug("cp %s %s" % (bootsplash, syslinux_target + ffile))
+ proc = subprocess.Popen(["install", "--mode=664", bootsplash, syslinux_target + ffile])
+ proc.wait()
+
+ grub_target = target + '/boot/grub/'
+ execute(mkdir, grub_target)
+
+ if not os.path.isfile("/usr/share/grml2usb/grub/splash.xpm.gz"):
+ logging.critical("Error: /usr/share/grml2usb/grub/splash.xpm.gz can not be read.")
+ raise
+ else:
+ logging.debug("cp /usr/share/grml2usb/grub/splash.xpm.gz %s" % grub_target + 'splash.xpm.gz')
+ proc = subprocess.Popen(["install", "--mode=664", '/usr/share/grml2usb/grub/splash.xpm.gz', grub_target + 'splash.xpm.gz'])
+ proc.wait()
+
+ if not os.path.isfile("/usr/share/grml2usb/grub/stage2_eltorito"):
+ logging.critical("Error: /usr/share/grml2usb/grub/stage2_eltorito can not be read.")
+ raise
+ else:
+ logging.debug("cp /usr/share/grml2usb/grub/stage2_eltorito to %s" % grub_target + 'stage2_eltorito')
+ proc = subprocess.Popen(["install", "--mode=664", '/usr/share/grml2usb/grub/stage2_eltorito', grub_target + 'stage2_eltorito'])
+ proc.wait()
+
+ if not options.dryrun:
+ logging.debug("Generating grub configuration")
+ #with open("...", "w") as f:
+ #f.write("bla bla bal")
+ grub_config_file = open(grub_target + 'menu.lst', 'w')
+ grub_config_file.write(generate_grub_config(grml_flavour))
+ grub_config_file.close()
+
+ logging.info("Generating syslinux configuration")
+ syslinux_cfg = syslinux_target + 'syslinux.cfg'
+
+ # install main configuration only *once*, no matter how many ISOs we have:
+ if os.path.isfile(syslinux_cfg):
+ string = open(syslinux_cfg).readline()
+ main_identifier = re.compile(".*main config generated at: %s.*" % re.escape(str(datestamp)))
+ if not re.match(main_identifier, string):
+ syslinux_config_file = open(syslinux_cfg, 'w')
+ logging.info("Notice: grml flavour %s is being installed as the default booting system." % grml_flavour)
+ syslinux_config_file.write(generate_main_syslinux_config(grml_flavour, options.bootoptions))
+ syslinux_config_file.close()
+ else:
+ syslinux_config_file = open(syslinux_cfg, 'w')
+ syslinux_config_file.write(generate_main_syslinux_config(grml_flavour, options.bootoptions))
+ syslinux_config_file.close()
+
+ # install flavour specific configuration only *once* as well
+ # kind of ugly - I'm pretty sure this could be smoother...
+ flavour_config = True
+ if os.path.isfile(syslinux_cfg):
+ string = open(syslinux_cfg).readlines()
+ logging.info("Notice: you can boot flavour %s using '%s' on the commandline." % (grml_flavour, grml_flavour))
+ flavour = re.compile("grml2usb for %s: %s" % (re.escape(grml_flavour), re.escape(str(datestamp))))
+ for line in string:
+ if flavour.match(line):
+ flavour_config = False
+
+
+ if flavour_config:
+ syslinux_config_file = open(syslinux_cfg, 'a')
+ syslinux_config_file.write(generate_flavour_specific_syslinux_config(grml_flavour, options.bootoptions))
+ syslinux_config_file.close( )
+
+ logging.debug("Generating isolinux/syslinux splash %s" % syslinux_target + 'boot.msg')
+ isolinux_splash = open(syslinux_target + 'boot.msg', 'w')
+ isolinux_splash.write(generate_isolinux_splash(grml_flavour))
+ isolinux_splash.close( )
+
+
+ # make sure we sync filesystems before returning
+ proc = subprocess.Popen(["sync"])
+ proc.wait()