X-Git-Url: https://git.grml.org/?p=grml2usb.git;a=blobdiff_plain;f=grml2usb;h=de95e5a4e1b0a2cead3bebf4c81b66dd9d692096;hp=9709ad5d692e56ae9b9cc7097be2da7781429d44;hb=refs%2Ftags%2Fv0.9.6;hpb=3d119415a53423cdc75f5ae9434bff713c0876be diff --git a/grml2usb b/grml2usb index 9709ad5..de95e5a 100755 --- a/grml2usb +++ b/grml2usb @@ -18,7 +18,7 @@ from inspect import isroutine, isclass import datetime, logging, os, re, subprocess, sys, tempfile, time # global variables -PROG_VERSION = "0.9.5" +PROG_VERSION = "0.9.6" MOUNTED = set() # register mountpoints TMPFILES = set() # register tmpfiles DATESTAMP = time.mktime(datetime.datetime.now().timetuple()) # unique identifier for syslinux.cfg @@ -315,6 +315,13 @@ menuentry "%(grml_flavour)s" { } ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s] +menuentry "%(grml_flavour)s-persistent" { + set root=(hd0,%(install_partition)s) + linux /boot/release/%(grml_flavour)s/linux26 apm=power-off boot=live nomce vga=791 quiet persistent live-media-path=/live/%(grml_flavour)s/ %(bootoptions)s + initrd /boot/release/%(grml_flavour)s/initrd.gz +} + +## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s] menuentry "%(grml_flavour)s2ram" { set root=(hd0,%(install_partition)s) linux /boot/release/%(grml_flavour)s/linux26 apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ toram=%(grml_flavour)s %(bootoptions)s @@ -383,6 +390,11 @@ kernel (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/linux26 apm=pow initrd (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/initrd.gz ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s] +title %(grml_flavour)s-persistent +kernel (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/linux26 apm=power-off boot=live nomce vga=791 quiet persistent live-media-path=/live/%(grml_flavour)s/ %(bootoptions)s +initrd (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/initrd.gz + +## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s] title %(grml_flavour)s2ram kernel (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/linux26 apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ toram=%(grml_flavour)s %(bootoptions)s initrd (hd0,%(install_partition)s)/boot/release/%(grml_flavour)s/initrd.gz @@ -557,6 +569,11 @@ KERNEL /boot/release/%(grml_flavour)s/linux26 APPEND initrd=/boot/release/%(grml_flavour)s/initrd.gz apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ %(bootoptions)s # flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s] +LABEL %(grml_flavour)s-persistent +KERNEL /boot/release/%(grml_flavour)s/linux26 +APPEND initrd=/boot/release/%(grml_flavour)s/initrd.gz apm=power-off boot=live nomce vga=791 quiet persistent live-media-path=/live/%(grml_flavour)s/ %(bootoptions)s + +# flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s] LABEL %(grml_flavour)s2ram KERNEL /boot/release/%(grml_flavour)s/linux26 APPEND initrd=/boot/release/%(grml_flavour)s/initrd.gz apm=power-off boot=live nomce vga=791 quiet live-media-path=/live/%(grml_flavour)s/ toram=%(grml_flavour)s %(bootoptions)s @@ -612,7 +629,7 @@ def install_grub(device): proc.wait() if proc.returncode != 0: # raise Exception("error executing grub-install") - logging.critical("Fatal: error executing grub-install (please check FAQ)" % error) + logging.critical("Fatal: error executing grub-install (please check the grml2usb FAQ)" % error) cleanup() sys.exit(1) except CriticalException, error: @@ -959,6 +976,7 @@ def copy_system_files(grml_flavour, iso_mount, target): squashfs = search_file(grml_flavour + '.squashfs', iso_mount) if squashfs is None: logging.critical("Fatal: squashfs file not found") + raise CriticalException("error locating squashfs file") else: squashfs_target = target + '/live/' + grml_flavour + '/' execute(mkdir, squashfs_target) @@ -1173,8 +1191,12 @@ def install_iso_files(grml_flavour, iso_mount, device, target): return 0 elif not options.bootloaderonly: logging.info("Copying files. This might take a while....") - copy_system_files(grml_flavour, iso_mount, target) - copy_grml_files(iso_mount, target) + try: + copy_system_files(grml_flavour, iso_mount, target) + copy_grml_files(iso_mount, target) + except CriticalException, error: + logging.critical("Execution failed: %s", error) + sys.exit(1) if not options.skipaddons: if grml_flavour.endswith('-small'): @@ -1420,6 +1442,47 @@ def handle_bootloader_config(grml_flavour, device, target): logging.critical("Fatal: %s" % error) sys.exit(1) +def handle_dir(live_image, device): + """Main logic for copying files of the currently running grml system. + + @live_image: directory where currently running live system resides (usually /live/image) + @device: partition where the specified ISO should be installed to""" + + logging.info("Using %s as install base" % live_image) + + if os.path.isdir(device): + logging.info("Specified target is a directory, not mounting therefor.") + device_mountpoint = device + remove_device_mountpoint = False + else: + device_mountpoint = tempfile.mkdtemp(prefix="grml2usb") + register_tmpfile(device_mountpoint) + remove_device_mountpoint = True + try: + mount(device, device_mountpoint, "") + except CriticalException, error: + logging.critical("Fatal: %s" % error) + cleanup() + sys.exit(1) + + try: + grml_flavour = identify_grml_flavour(live_image) + logging.info("Identified grml flavour \"%s\"." % grml_flavour) + install_iso_files(grml_flavour, live_image, device, device_mountpoint) + except TypeError: + logging.critical("Fatal: a critical error happend during execution (not a grml ISO?), giving up") + sys.exit(1) + finally: + if remove_device_mountpoint: + try: + unmount(device_mountpoint, "") + if os.path.isdir(device_mountpoint): + os.rmdir(device_mountpoint) + unregister_tmpfile(device_mountpoint) + except CriticalException, error: + logging.critical("Fatal: %s" % error) + cleanup() + def handle_iso(iso, device): """Main logic for mounting ISOs and copying files. @@ -1429,10 +1492,6 @@ def handle_iso(iso, device): logging.info("Using ISO %s" % iso) - if os.path.isdir(iso): - logging.critical("TODO: /live/image handling not yet implemented - sorry") - sys.exit(1) - iso_mountpoint = tempfile.mkdtemp(prefix="grml2usb") register_tmpfile(iso_mountpoint) remove_iso_mountpoint = True @@ -1657,7 +1716,10 @@ def main(): # main operation (like installing files) for iso in isos: - handle_iso(iso, device) + if os.path.isdir(iso): + handle_dir(iso, device) + else: + handle_iso(iso, device) # install mbr if not os.path.isdir(device):