From 193b765f07543b4824950fe08d337211c2ef8a1c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 17 Oct 2019 14:41:03 +0200 Subject: [serversetup-bwlp-ipxe/minilinux] Further improvements * Distinction between BIOS and EFI for ipxe hook in minilinux * Debug KCL modifier customizable by update meta data * Bugfixes, minor refactoring... --- .../serversetup-bwlp-ipxe/inc/bootentry.inc.php | 63 ++++++++++++---------- .../inc/bootentryhook.inc.php | 2 +- .../serversetup-bwlp-ipxe/inc/ipxe.inc.php | 26 +++++++++ .../serversetup-bwlp-ipxe/page.inc.php | 6 +-- 4 files changed, 65 insertions(+), 32 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 174f4459..dec70528 100644 --- a/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentry.inc.php @@ -3,6 +3,15 @@ abstract class BootEntry { + /** Supports both via same entry (stored in PCBIOS entry) */ + const AGNOSTIC = 'agnostic'; + /** Only valid for legacy BIOS boot */ + const BIOS = 'PCBIOS'; + /** Only valid for EFI boot */ + const EFI = 'EFI'; + /** Supports both via distinct entry */ + const BOTH = 'PCBIOS-EFI'; + public abstract function supportsMode($mode); public abstract function toScript($failLabel, $mode); @@ -57,11 +66,11 @@ abstract class BootEntry { $ret = new StandardBootEntry($initData, $efi, $arch); $list = []; - if ($ret->arch() !== StandardBootEntry::EFI) { - $list[] = StandardBootEntry::BIOS; + if ($ret->arch() !== self::EFI) { + $list[] = self::BIOS; } - if ($ret->arch() === StandardBootEntry::EFI || $ret->arch() === StandardBootEntry::BOTH) { - $list[] = StandardBootEntry::EFI; + if ($ret->arch() === self::EFI || $ret->arch() === self::BOTH) { + $list[] = self::EFI; } $data = $ret->toArray(); foreach ($list as $mode) { @@ -129,11 +138,6 @@ class StandardBootEntry extends BootEntry protected $arch; // Constants below - const BIOS = 'PCBIOS'; // Only valid for legacy BIOS boot - const EFI = 'EFI'; // Only valid for EFI boot - const BOTH = 'PCBIOS-EFI'; // Supports both via distinct entry - const AGNOSTIC = 'agnostic'; // Supports both via same entry (PCBIOS entry) - const KEYS = ['executable', 'initRd', 'commandLine', 'replace', 'imageFree', 'autoUnload', 'resetConsole', 'dhcpOptions']; public function __construct($data, $efi = false, $arch = false) @@ -157,18 +161,21 @@ class StandardBootEntry extends BootEntry } else { $this->arch = $data['arch']; } - if (isset($data[self::BIOS]) || isset($data[self::EFI])) { + if (isset($data[BootEntry::BIOS]) || isset($data[BootEntry::EFI])) { // Current format $this->fromCurrentFormat($data); } else { // Convert legacy DB format $this->fromLegacyFormat($data); } + } elseif ($arch == BootEntry::EFI && $efi instanceof ExecData) { + $this->efi = $efi; + $this->arch = $arch; } else { error_log('Invalid StandardBootEntry constructor call'); } - if (!in_array($this->arch, [self::BIOS, self::EFI, self::BOTH, self::AGNOSTIC])) { - $this->arch = self::AGNOSTIC; + if (!in_array($this->arch, [BootEntry::BIOS, BootEntry::EFI, BootEntry::BOTH, BootEntry::AGNOSTIC])) { + $this->arch = BootEntry::AGNOSTIC; } } @@ -176,12 +183,12 @@ class StandardBootEntry extends BootEntry { $ok = false; foreach (self::KEYS as $key) { - if (isset($data[$key][self::BIOS])) { - $this->pcbios->{$key} = $data[$key][self::BIOS]; + if (isset($data[$key][BootEntry::BIOS])) { + $this->pcbios->{$key} = $data[$key][BootEntry::BIOS]; $ok = true; } - if (isset($data[$key][self::EFI])) { - $this->efi->{$key} = $data[$key][self::EFI]; + if (isset($data[$key][BootEntry::EFI])) { + $this->efi->{$key} = $data[$key][BootEntry::EFI]; $ok = true; } } @@ -198,11 +205,11 @@ class StandardBootEntry extends BootEntry private function fromCurrentFormat($data) { foreach (self::KEYS as $key) { - if (isset($data[self::BIOS][$key])) { - $this->pcbios->{$key} = $data[self::BIOS][$key]; + if (isset($data[BootEntry::BIOS][$key])) { + $this->pcbios->{$key} = $data[BootEntry::BIOS][$key]; } - if (isset($data[self::EFI][$key])) { - $this->efi->{$key} = $data[self::EFI][$key]; + if (isset($data[BootEntry::EFI][$key])) { + $this->efi->{$key} = $data[BootEntry::EFI][$key]; } } } @@ -241,10 +248,10 @@ class StandardBootEntry extends BootEntry public function supportsMode($mode) { - if ($mode === $this->arch || $this->arch === self::AGNOSTIC) + if ($mode === $this->arch || $this->arch === BootEntry::AGNOSTIC) return true; - if ($mode === self::BIOS || $mode === self::EFI) { - return $this->arch === self::BOTH; + if ($mode === BootEntry::BIOS || $mode === BootEntry::EFI) { + return $this->arch === BootEntry::BOTH; } error_log('Unknown iPXE platform: ' . $mode); return false; @@ -255,7 +262,7 @@ class StandardBootEntry extends BootEntry if (!$this->supportsMode($mode)) { return "prompt Entry doesn't have an executable for mode $mode\n"; } - if ($this->arch === self::AGNOSTIC || $mode == self::BIOS) { + if ($this->arch === BootEntry::AGNOSTIC || $mode == BootEntry::BIOS) { $entry = $this->pcbios; } else { $entry = $this->efi; @@ -319,16 +326,16 @@ class StandardBootEntry extends BootEntry public function addFormFields(&$array) { $array[$this->arch . '_selected'] = 'selected'; - $array['entries'][] = $this->pcbios->toFormFields(self::BIOS); - $array['entries'][] = $this->efi->toFormFields(self::EFI); + $array['entries'][] = $this->pcbios->toFormFields(BootEntry::BIOS); + $array['entries'][] = $this->efi->toFormFields(BootEntry::EFI); $array['exec_checked'] = 'checked'; } public function toArray() { return [ - self::BIOS => $this->pcbios->toArray(), - self::EFI => $this->efi->toArray(), + BootEntry::BIOS => $this->pcbios->toArray(), + BootEntry::EFI => $this->efi->toArray(), 'arch' => $this->arch, ]; } diff --git a/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php index f89031a3..cf180006 100644 --- a/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/inc/bootentryhook.inc.php @@ -53,7 +53,7 @@ abstract class BootEntryHook * @param $id * @return BootEntry|null the actual boot entry instance for given entry, null if invalid id */ - public abstract function getBootEntryInternal($data); + public abstract function getBootEntryInternal($localData); public final function getBootEntry($data) { diff --git a/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php b/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php index 6caecc65..4c2a7678 100644 --- a/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/inc/ipxe.inc.php @@ -527,4 +527,30 @@ boot -a -r /boot/default/kernel initrd=initramfs-stage31 ${slxextra} slxbase=boo return md5(md5($plainpass) . '-' . $salt); } + /** + * Modify a kernel command line. Add or remove items to a given command line. The $modifier + * string is a list of space separated arguments. If the argument starts with a '-', all + * according occurrences of the given option will be removed from the command line. It is assumed + * that options are either of format "option" or "option=value", so a modifier of "-option" will + * remove any occurrence of either "option" or "option=something". If the argument starts with a + * '+', it will be added to the command line after removing the '+'. If the argument starts with any + * other character, it will also be added to the command line. + * @param string $cmdLine command line to modify + * @param string $modifier modification string of space separated arguments + * @return string the modified command line + */ + public static function modifyCommandLine($cmdLine, $modifier) + { + $items = preg_split('/\s+/', $modifier, -1, PREG_SPLIT_NO_EMPTY); + foreach ($items as $item) { + if ($item{0} === '-') { + $item = preg_quote(substr($item, 1), '/'); + $cmdLine = preg_replace('/(^|\s)' . $item . '(=\S*)?($|\s)/', ' ', $cmdLine); + } else { + $cmdLine .= ' ' . $item; + } + } + return $cmdLine; + } + } diff --git a/modules-available/serversetup-bwlp-ipxe/page.inc.php b/modules-available/serversetup-bwlp-ipxe/page.inc.php index f14c1e57..81f15922 100644 --- a/modules-available/serversetup-bwlp-ipxe/page.inc.php +++ b/modules-available/serversetup-bwlp-ipxe/page.inc.php @@ -434,13 +434,13 @@ class Page_ServerSetup extends Page if (!array_key_exists('arch', $bootentry['data'])) continue; // Naming and agnostic - if ($bootentry['data']['arch'] === StandardBootEntry::BIOS) { + if ($bootentry['data']['arch'] === BootEntry::BIOS) { $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_biosOnly', true); unset($bootentry['data']['EFI']); - } elseif ($bootentry['data']['arch'] === StandardBootEntry::EFI) { + } elseif ($bootentry['data']['arch'] === BootEntry::EFI) { $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_efiOnly', true); unset($bootentry['data']['PCBIOS']); - } elseif ($bootentry['data']['arch'] === StandardBootEntry::AGNOSTIC) { + } elseif ($bootentry['data']['arch'] === BootEntry::AGNOSTIC) { $bootentry['data']['arch'] = Dictionary::translateFile('template-tags','lang_archAgnostic', true); unset($bootentry['data']['EFI']); } else { -- cgit v1.2.3-55-g7522