From d957c1b2fcb2caf1920fa200c9d17863e1326ad5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 7 Mar 2019 18:37:12 +0100 Subject: [serversetup-bwlp-ipxe] Improve legacy PXELinux import --- .../serversetup-bwlp-ipxe/inc/bootentry.inc.php | 40 +++++++++++++++------- .../serversetup-bwlp-ipxe/inc/ipxe.inc.php | 23 +++++++++---- 2 files changed, 44 insertions(+), 19 deletions(-) (limited to 'modules-available/serversetup-bwlp-ipxe') diff --git a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php index 69adffd3..a66736b6 100644 --- a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php @@ -57,7 +57,7 @@ abstract class BootEntry $list[] = StandardBootEntry::EFI; } foreach ($list as $mode) { - if (empty($initData['executable'][$mode])) + if (empty($ret->toArray()['executable'][$mode])) return null; } return $ret; @@ -107,7 +107,7 @@ class StandardBootEntry extends BootEntry if ($data instanceof PxeSection) { // Gets arrayfied below $this->executable = $data->kernel; - $this->initRd = $data->initrd; + $this->initRd = [self::BIOS => $data->initrd]; $this->commandLine = ' ' . str_replace('vga=current', '', $data->append) . ' '; $this->resetConsole = true; $this->replace = true; @@ -126,14 +126,28 @@ class StandardBootEntry extends BootEntry } $this->commandLine = trim(preg_replace('/\s+/', ' ', $this->commandLine)); } else { + if (isset($data['initRd']) && is_array($data['initRd'])) { + foreach ($data['initRd'] as &$initrd) { + if (is_string($initrd)) { + $initrd = preg_split('/\s*,\s*/', $initrd); + } + } + unset($initrd); + } parent::__construct($data); } // Convert legacy DB format foreach (['executable', 'initRd', 'commandLine', 'replace', 'autoUnload', 'resetConsole'] as $key) { if (!is_array($this->{$key})) { - $this->{$key} = [ 'PCBIOS' => $this->{$key}, 'EFI' => '' ]; + $this->{$key} = [ self::BIOS => $this->{$key}, self::EFI => '' ]; + } + } + foreach ($this->initRd as &$initrd) { + if (!is_array($initrd)) { + $initrd = [$initrd]; } } + unset($initrd); if ($this->arch === null) { $this->arch = self::AGNOSTIC; } @@ -168,14 +182,12 @@ class StandardBootEntry extends BootEntry if ($this->resetConsole[$mode]) { $script .= "console ||\n"; } + $initrds = []; if (!empty($this->initRd[$mode])) { $script .= "imgfree ||\n"; - if (!is_array($this->initRd[$mode])) { - $script .= "initrd {$this->initRd[$mode]} || goto $failLabel\n"; - } else { - foreach ($this->initRd[$mode] as $initrd) { - $script .= "initrd $initrd || goto $failLabel\n"; - } + foreach (array_values($this->initRd[$mode]) as $i => $initrd) { + $script .= "initrd --name initrd$i $initrd || goto $failLabel\n"; + $initrds[] = "initrd$i"; } } $script .= "boot "; @@ -186,9 +198,13 @@ class StandardBootEntry extends BootEntry $script .= "-r "; } $script .= $this->executable[$mode]; - $rdBase = basename($this->initRd[$mode]); + if (empty($initrds)) { + $rdBase = ''; + } else { + $rdBase = " initrd=" . implode(',', $initrds); + } if (!empty($this->commandLine[$mode])) { - $script .= " initrd=$rdBase {$this->commandLine[$mode]}"; + $script .= "$rdBase {$this->commandLine[$mode]}"; } $script .= " || goto $failLabel\n"; if ($this->resetConsole[$mode]) { @@ -205,7 +221,7 @@ class StandardBootEntry extends BootEntry 'is' . $mode => true, 'mode' => $mode, 'executable' => $this->executable[$mode], - 'initRd' => $this->initRd[$mode], + 'initRd' => implode(',', $this->initRd[$mode]), 'commandLine' => $this->commandLine[$mode], 'replace_checked' => $this->replace[$mode] ? 'checked' : '', 'autoUnload_checked' => $this->autoUnload[$mode] ? 'checked' : '', diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php index 4320bb82..4683c843 100644 --- a/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php @@ -207,7 +207,7 @@ class IPxe 'isdefault' => $isDefault, ]); $menuId = Database::lastInsertId(); - if (!array_key_exists($defaultLabel, $menuEntries) && $timeoutMs > 0) { + if (($defaultLabel === false || !array_key_exists($defaultLabel, $menuEntries)) && $timeoutMs > 0) { $defaultLabel = array_keys($menuEntries)[0]; } // Link boot entries to menu @@ -236,7 +236,10 @@ class IPxe if ($entry instanceof PxeSection) { $data['hidden'] = (int)$entry->isHidden; // Prefer explicit data from this imported menu over the defaults - $data['title'] = self::sanitizeIpxeString($entry->title); + $title = self::sanitizeIpxeString($entry->title); + if (!empty($title)) { + $data['title'] = $title; + } if (MenuEntry::getKeyCode($entry->hotkey) !== false) { $data['hotkey'] = $entry->hotkey; } @@ -266,22 +269,28 @@ class IPxe private static function createDefaultEntries() { - $query = 'INSERT IGNORE INTO serversetup_bootentry (entryid, hotkey, title, builtin, data) - VALUES (:entryid, :hotkey, :title, 1, :data)'; - Database::exec($query, + Database::exec( 'INSERT IGNORE INTO serversetup_bootentry (entryid, hotkey, title, builtin, data) + VALUES (:entryid, :hotkey, :title, 1, :data)', [ - 'script' => ' + 'entryid' => 'bwlp-default', + 'hotkey' => 'B', + 'title' => 'bwLehrpool-Umgebung starten', + 'data' => json_encode([ + 'script' => ' imgfree || set slxextra ,logo || initrd /boot/default/initramfs-stage31 || goto fail initrd --name logo /tftp/bwlp.ppm.gz /etc/splash.ppm.gz || clear slxextra boot -a -r /boot/default/kernel initrd=initramfs-stage31${slxextra} slxbase=boot/default quiet splash loglevel=5 rd.systemd.show_status=auto intel_iommu=igfx_off ${ipappend1} ${ipappend2} || goto fail ', + ]), ]); + $query = 'INSERT IGNORE INTO serversetup_bootentry (entryid, hotkey, title, builtin, data) + VALUES (:entryid, :hotkey, :title, 1, :data)'; Database::exec($query, [ 'entryid' => 'bwlp-default-dbg', - 'hotkey' => '', + 'hotkey' => 'D', 'title' => 'bwLehrpool-Umgebung starten (nosplash, debug)', 'data' => json_encode([ 'executable' => '/boot/default/kernel', -- cgit v1.2.3-55-g7522