Mimic /boot/%SHORT_NAME% like on the ISO
[grml2usb.git] / grml2usb
index 4b706cc..39e441f 100755 (executable)
--- a/grml2usb
+++ b/grml2usb
@@ -21,8 +21,10 @@ import glob
 import uuid
 import struct
 
+# The line following this line is patched by debian/rules and tarball.sh.
+PROG_VERSION='***UNRELEASED***'
+
 # global variables
-PROG_VERSION = "0.9.31"
 MOUNTED = set()  # register mountpoints
 TMPFILES = set() # register tmpfiles
 DATESTAMP = time.mktime(datetime.datetime.now().timetuple()) # unique identifier for syslinux.cfg
@@ -339,7 +341,7 @@ fi
 
 menuentry "%(grml_flavour)s (default)" {
     set gfxpayload=1024x768x16,1024x768
-    linux   /boot/release/%(flavour_filename)s/linux26 apm=power-off quiet boot=live nomce live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
+    linux   /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
     initrd  /boot/release/%(flavour_filename)s/initrd.gz
 }
 
@@ -420,56 +422,56 @@ def generate_flavour_specific_grub2_config(grml_flavour, bootoptions):
 
     return("""\
 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
-menuentry "%(grml_flavour)s            - boot in default mode" {
+menuentry "%(grml_flavour)s - boot in default mode" {
     set gfxpayload=1024x768x16,1024x768
-    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
+    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
     initrd /boot/release/%(flavour_filename)s/initrd.gz
 }
 
 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
-menuentry "%(grml_flavour)s-persistent - enable persistency feature" {
+menuentry "%(grml_flavour)s - enable persistent mode" {
     set gfxpayload=1024x768x16,1024x768
-    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet persistent live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
+    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce persistent live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s
     initrd /boot/release/%(flavour_filename)s/initrd.gz
 }
 
 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
-menuentry "%(grml_flavour)s2ram        - copy compressed grml file to RAM" {
+menuentry "%(grml_flavour)s - copy Grml to RAM" {
     set gfxpayload=1024x768x16,1024x768
-    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ toram=%(grml_flavour)s.squashfs bootid=%(uid)s %(bootoptions)s
+    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce live-media-path=/live/%(grml_flavour)s/ toram=%(grml_flavour)s.squashfs bootid=%(uid)s %(bootoptions)s
     initrd /boot/release/%(flavour_filename)s/initrd.gz
 }
 
 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
-menuentry "%(grml_flavour)s-debug      - enable debugging options" {
+menuentry "%(grml_flavour)s - start X Window System" {
     set gfxpayload=1024x768x16,1024x768
-    linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ debug bootid=%(uid)s initcall_debug %(bootoptions)s
+    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce live-media-path=/live/%(grml_flavour)s/ startx bootid=%(uid)s %(bootoptions)s
     initrd /boot/release/%(flavour_filename)s/initrd.gz
 }
 
 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
-menuentry "%(grml_flavour)s-x          - start X Window System" {
-    set gfxpayload=1024x768x16,1024x768
-    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ startx=wm-ng bootid=%(uid)s %(bootoptions)s
+menuentry "%(grml_flavour)s - disable framebuffer" {
+    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce live-media-path=/live/%(grml_flavour)s/ vga=normal video=ofonly bootid=%(uid)s %(bootoptions)s
     initrd /boot/release/%(flavour_filename)s/initrd.gz
 }
 
 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
-menuentry "%(grml_flavour)s-nofb       - disable framebuffer" {
-    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal video=ofonly bootid=%(uid)s %(bootoptions)s
+menuentry "%(grml_flavour)s - disable Kernel Mode-Setting" {
+    linux  /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce live-media-path=/live/%(grml_flavour)s/ bootid=%(uid)s %(bootoptions)s radeon.modeset=0 i915.modeset=0 nouveau.modeset=0 nomodeset
     initrd /boot/release/%(flavour_filename)s/initrd.gz
 }
 
 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
-menuentry "%(grml_flavour)s-failsafe   - disable hardware detection" {
-    linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ vga=normal noautoconfig atapicd noapic noacpi acpi=off nomodules nofirewire noudev nousb nohotplug noapm nopcmcia nosmp maxcpus=0 noscsi noagp nodma ide=nodma noswap nofstab nosound nogpm nosyslog nodhcp nocpu nodisc nomodem xmodule=vesa noraid nolvm noresume selinux=0 edd=off pci=nomsi bootid=%(uid)s %(bootoptions)s
+menuentry "%(grml_flavour)s - forensic mode" {
+    set gfxpayload=1024x768x16,1024x768
+    linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce live-media-path=/live/%(grml_flavour)s/ nofstab noraid nolvm noautoconfig noswap raid=noautodetect forensic readonly bootid=%(uid)s %(bootoptions)s
     initrd /boot/release/%(flavour_filename)s/initrd.gz
 }
 
 ## flavour specific configuration for %(grml_flavour)s [grml2usb for %(grml_flavour)s: %(local_datestamp)s]
-menuentry "%(grml_flavour)s-forensic   - do not touch harddisks during hw recognition" {
+menuentry "%(grml_flavour)s - enable debugging options" {
     set gfxpayload=1024x768x16,1024x768
-    linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce quiet live-media-path=/live/%(grml_flavour)s/ nofstab noraid nolvm noautoconfig noswap raid=noautodetect forensic readonly bootid=%(uid)s %(bootoptions)s
+    linux /boot/release/%(flavour_filename)s/linux26 apm=power-off boot=live nomce live-media-path=/live/%(grml_flavour)s/ debug bootid=%(uid)s initcall_debug %(bootoptions)s
     initrd /boot/release/%(flavour_filename)s/initrd.gz
 }
 
@@ -941,28 +943,19 @@ def copy_system_files(grml_flavour, iso_mount, 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)
 
-    release_path = 'boot/release/' + grml_flavour.replace('-', '')
-    release_target = target + "/" + release_path
-    execute(mkdir, release_target)
-
-    prefix = ""
-    if os.path.isdir(iso_mount + '/boot/release'):
-        prefix = release_path + '/'
-
-    kernel = search_file(prefix + 'linux26', iso_mount)
     if kernel is None:
-        logging.critical("Fatal kernel not found")
+        logging.critical("Fatal: kernel not found")
         raise CriticalException("error locating kernel file")
-    else:
-        exec_rsync(kernel, release_target + '/linux26')
 
-    initrd = search_file(prefix + 'initrd.gz', iso_mount)
-    if initrd is None:
-        logging.critical("Fatal: initrd not found")
-        raise CriticalException("error locating initrd file")
-    else:
-        exec_rsync(initrd, release_target + '/initrd.gz')
+    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):
@@ -1202,27 +1195,12 @@ def copy_bootloader_files(iso_mount, target, grml_flavour):
 
     search_and_copy('hidden.cfg', iso_mount + source_dir, syslinux_target + "new_" + 'hidden.cfg')
 
-
-    grub_target = target + '/boot/grub/'
-    execute(mkdir, grub_target)
-
-    if not os.path.isfile(GRML2USB_BASE + "/grub/splash.xpm.gz"):
-        logging.critical("Error: %s/grub/splash.xpm.gz can not be read.", GRML2USB_BASE)
-        logging.critical("Please make sure you've installed the grml2usb (Debian) package!")
-        raise
-    else:
-        exec_rsync(GRML2USB_BASE + '/grub/splash.xpm.gz', grub_target + 'splash.xpm.gz')
-
-    # grml splash in grub
-    copy_if_exist(GRML2USB_BASE + "/grub/grml.png", grub_target + 'grml.png')
-
-    # font file for graphical bootsplash in grub
-    copy_if_exist('/usr/share/grub/ascii.pf2', grub_target + 'ascii.pf2')
-
-    # always copy grub content as it might be useful
-
+    # copy all grub files from ISO
     glob_and_copy(iso_mount + '/boot/grub/*.mod', grub_target)
+    glob_and_copy(iso_mount + '/boot/grub/*.lst', grub_target)
     glob_and_copy(iso_mount + '/boot/grub/*.img', grub_target)
+    glob_and_copy(iso_mount + '/boot/grub/*.pf2', grub_target) # fonts for splash
+    glob_and_copy(iso_mount + '/boot/grub/*.png', grub_target) # splash image
     glob_and_copy(iso_mount + '/boot/grub/stage*', grub_target)
 
 def install_iso_files(grml_flavour, iso_mount, device, target):
@@ -1308,7 +1286,7 @@ def modify_grub_config(filename):
         for regex in options.removeoption:
             regexe.append(re.compile(r'%s' % regex))
 
-        option_re = re.compile(r'(.*/boot/release/.*linux26.*)')
+        option_re = re.compile(r'(.*/boot/.*(linux26|vmlinuz).*)')
 
         for line in fileinput.input(filename, inplace=1):
             if regexe and option_re.search(line):
@@ -1333,20 +1311,15 @@ def handle_grub2_config(grml_flavour, grub_target, bootopt):
     global GRML_DEFAULT
 
     # install main configuration only *once*, no matter how many ISOs we have:
-    grub_flavour_is_default = False
+    install_main_config = True
     if os.path.isfile(grub2_cfg):
         string = open(grub2_cfg).readline()
         main_identifier = re.compile(".*main config generated at: %s.*" % re.escape(str(DATESTAMP)))
-        if not re.match(main_identifier, string):
-            grub2_config_file = open(grub2_cfg, 'w')
-            GRML_DEFAULT = grml_flavour
-            grub_flavour_is_default = True
-            grub2_config_file.write(generate_main_grub2_config(grml_flavour, bootopt))
-            grub2_config_file.close()
-    else:
+        if re.match(main_identifier, string):
+            install_main_config = False
+    if install_main_config:
         grub2_config_file = open(grub2_cfg, 'w')
         GRML_DEFAULT = grml_flavour
-        grub_flavour_is_default = True
         grub2_config_file.write(generate_main_grub2_config(grml_flavour, bootopt))
         grub2_config_file.close()
 
@@ -1362,7 +1335,7 @@ def handle_grub2_config(grml_flavour, grub_target, bootopt):
     if grub_flavour_config:
         grub2_config_file = open(grub2_cfg, 'a')
         # display only if the grml flavour isn't the default
-        if not grub_flavour_is_default:
+        if GRML_DEFAULT != grml_flavour:
             GRML_FLAVOURS.add(grml_flavour)
         grub2_config_file.write(generate_flavour_specific_grub2_config(grml_flavour, bootopt))
         grub2_config_file.close()
@@ -1449,8 +1422,7 @@ def adjust_syslinux_bootoptions(src, flavour):
     @flavour: grml flavour
     """
 
-    append_re = re.compile("^(\s*append.*/boot/release.*)$", re.I)
-    boot_re = re.compile("/boot/([a-zA-Z0-9_]+/)+([a-zA-Z0-9._]+)")
+    append_re = re.compile("^(\s*append.*/boot/.*)$", re.I)
     # flavour_re = re.compile("(label.*)(grml\w+)")
     default_re = re.compile("(default.cfg)")
     bootid_re = re.compile("bootid=[\w_-]+")
@@ -1461,13 +1433,12 @@ def adjust_syslinux_bootoptions(src, flavour):
     regexe = []
     option_re = None
     if options.removeoption:
-        option_re = re.compile(r'/boot/release/.*/initrd.gz')
+        option_re = re.compile(r'/boot/.*/(initrd.gz|initrd.img)')
 
         for regex in options.removeoption:
             regexe.append(re.compile(r'%s' % regex))
 
     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)
@@ -1510,7 +1481,7 @@ def add_syslinux_entry(filename, grml_flavour):
     data.close()
 
 def modify_filenames(grml_flavour, target, filenames):
-    """Replace the standarf filenames with the new ones
+    """Replace the standard filenames with the new ones
 
     @grml_flavour: grml-flavour strin
     @target: directory where the files are located
@@ -1587,7 +1558,7 @@ def handle_syslinux_config(grml_flavour, target):
     entry = 'include %s\n' % new_default
     defaults_file = '%s/defaults.cfg' % syslinux_target
     new_default_with_path = "%s/%s" % (syslinux_target, new_default)
-    new_grml_cfg = "%s/%s_grml.cfg" % ( syslinux_target, flavour_filename)
+    new_grml_cfg = "%s/%s_grml.cfg" % (syslinux_target, flavour_filename)
 
     if os.path.isfile(defaults_file):