summaryrefslogtreecommitdiffstats
path: root/modules-available/serversetup-bwlp/inc
diff options
context:
space:
mode:
authorSimon Rettberg2018-09-19 11:27:22 +0200
committerSimon Rettberg2018-09-19 11:27:22 +0200
commit6da78493a0bb010a0fff50ac3cc23e018b15e979 (patch)
tree6baaa31e9d985e503e09cd669f11bce65355cd3d /modules-available/serversetup-bwlp/inc
parent[serversetup-bwlp] Pass initrd= on KCL for EFI mode (diff)
downloadslx-admin-6da78493a0bb010a0fff50ac3cc23e018b15e979.tar.gz
slx-admin-6da78493a0bb010a0fff50ac3cc23e018b15e979.tar.xz
slx-admin-6da78493a0bb010a0fff50ac3cc23e018b15e979.zip
[serversetup-bwlp] Differentiate between EFI/BIOS
Different executable/initrd etc. can be given for a simple boot entry of type "exec", or it can be specified that only one of them is supported. For bootentry type "script" there can still be only one entry, since you can just check the ${platform} variable within the script.
Diffstat (limited to 'modules-available/serversetup-bwlp/inc')
-rw-r--r--modules-available/serversetup-bwlp/inc/bootentry.inc.php113
-rw-r--r--modules-available/serversetup-bwlp/inc/ipxemenu.inc.php8
-rw-r--r--modules-available/serversetup-bwlp/inc/menuentry.inc.php10
3 files changed, 97 insertions, 34 deletions
diff --git a/modules-available/serversetup-bwlp/inc/bootentry.inc.php b/modules-available/serversetup-bwlp/inc/bootentry.inc.php
index 930f4413..010b660c 100644
--- a/modules-available/serversetup-bwlp/inc/bootentry.inc.php
+++ b/modules-available/serversetup-bwlp/inc/bootentry.inc.php
@@ -14,7 +14,9 @@ abstract class BootEntry
}
}
- public abstract function toScript($failLabel);
+ public abstract function supportsMode($mode);
+
+ public abstract function toScript($failLabel, $mode);
public abstract function toArray();
@@ -46,9 +48,19 @@ abstract class BootEntry
public static function newStandardBootEntry($initData)
{
- if (empty($initData['executable']))
- return null;
- return new StandardBootEntry($initData);
+ $ret = new StandardBootEntry($initData);
+ $list = [];
+ if ($ret->arch() !== StandardBootEntry::EFI) {
+ $list[] = StandardBootEntry::BIOS;
+ }
+ if ($ret->arch() === StandardBootEntry::EFI || $ret->arch() === StandardBootEntry::BOTH) {
+ $list[] = StandardBootEntry::EFI;
+ }
+ foreach ($list as $mode) {
+ if (empty($initData['executable'][$mode]))
+ return null;
+ }
+ return $ret;
}
public static function newCustomBootEntry($initData)
@@ -83,6 +95,12 @@ class StandardBootEntry extends BootEntry
protected $replace;
protected $autoUnload;
protected $resetConsole;
+ protected $arch; // true == available, false == not available
+
+ 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)
public function __construct($data = false)
{
@@ -109,38 +127,70 @@ class StandardBootEntry extends BootEntry
} else {
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' => '' ];
+ }
+ }
+ if ($this->arch === null) {
+ $this->arch = self::AGNOSTIC;
+ }
+ }
+
+ public function arch()
+ {
+ return $this->arch;
+ }
+
+ public function supportsMode($mode)
+ {
+ if ($mode === $this->arch || $this->arch === self::AGNOSTIC)
+ return true;
+ if ($mode === self::BIOS || $mode === self::EFI) {
+ return $this->arch === self::BOTH;
+ }
+ error_log('Unknown iPXE platform: ' . $mode);
+ return false;
}
- public function toScript($failLabel)
+ public function toScript($failLabel, $mode)
{
+ if (!$this->supportsMode($mode)) {
+ return "prompt Entry doesn't have an executable for mode $mode\n";
+ }
+ if ($this->arch === self::AGNOSTIC) {
+ $mode = self::BIOS;
+ }
+
$script = '';
- if ($this->resetConsole) {
+ if ($this->resetConsole[$mode]) {
$script .= "console ||\n";
}
- if (!empty($this->initRd)) {
+ if (!empty($this->initRd[$mode])) {
$script .= "imgfree ||\n";
- if (!is_array($this->initRd)) {
- $script .= "initrd {$this->initRd} || goto $failLabel\n";
+ if (!is_array($this->initRd[$mode])) {
+ $script .= "initrd {$this->initRd[$mode]} || goto $failLabel\n";
} else {
- foreach ($this->initRd as $initrd) {
+ foreach ($this->initRd[$mode] as $initrd) {
$script .= "initrd $initrd || goto $failLabel\n";
}
}
}
$script .= "boot ";
- if ($this->autoUnload) {
+ if ($this->autoUnload[$mode]) {
$script .= "-a ";
}
- if ($this->replace) {
+ if ($this->replace[$mode]) {
$script .= "-r ";
}
- $script .= "{$this->executable}";
- $rdBase = basename($this->initRd);
- if (!empty($this->commandLine)) {
- $script .= " initrd=$rdBase {$this->commandLine}";
+ $script .= $this->executable[$mode];
+ $rdBase = basename($this->initRd[$mode]);
+ if (!empty($this->commandLine[$mode])) {
+ $script .= " initrd=$rdBase {$this->commandLine[$mode]}";
}
$script .= " || goto $failLabel\n";
- if ($this->resetConsole) {
+ if ($this->resetConsole[$mode]) {
$script .= "goto start ||\n";
}
return $script;
@@ -148,14 +198,19 @@ class StandardBootEntry extends BootEntry
public function addFormFields(&$array)
{
- $array['entry'] = [
- 'executable' => $this->executable,
- 'initRd' => $this->initRd,
- 'commandLine' => $this->commandLine,
- 'replace_checked' => $this->replace ? 'checked' : '',
- 'autoUnload_checked' => $this->autoUnload ? 'checked' : '',
- 'resetConsole_checked' => $this->resetConsole ? 'checked' : '',
- ];
+ $array[$this->arch . '_selected'] = 'selected';
+ foreach ([self::BIOS, self::EFI] as $mode) {
+ $array['entries'][] = [
+ 'is' . $mode => true,
+ 'mode' => $mode,
+ 'executable' => $this->executable[$mode],
+ 'initRd' => $this->initRd[$mode],
+ 'commandLine' => $this->commandLine[$mode],
+ 'replace_checked' => $this->replace[$mode] ? 'checked' : '',
+ 'autoUnload_checked' => $this->autoUnload[$mode] ? 'checked' : '',
+ 'resetConsole_checked' => $this->resetConsole[$mode] ? 'checked' : '',
+ ];
+ }
$array['exec_checked'] = 'checked';
}
@@ -168,6 +223,7 @@ class StandardBootEntry extends BootEntry
'replace' => $this->replace,
'autoUnload' => $this->autoUnload,
'resetConsole' => $this->resetConsole,
+ 'arch' => $this->arch,
];
}
}
@@ -176,7 +232,12 @@ class CustomBootEntry extends BootEntry
{
protected $script;
- public function toScript($failLabel)
+ public function supportsMode($mode)
+ {
+ return true;
+ }
+
+ public function toScript($failLabel, $mode)
{
return str_replace('%fail%', $failLabel, $this->script) . "\n";
}
diff --git a/modules-available/serversetup-bwlp/inc/ipxemenu.inc.php b/modules-available/serversetup-bwlp/inc/ipxemenu.inc.php
index ed9f0986..56041c20 100644
--- a/modules-available/serversetup-bwlp/inc/ipxemenu.inc.php
+++ b/modules-available/serversetup-bwlp/inc/ipxemenu.inc.php
@@ -36,11 +36,11 @@ class IPxeMenu
}
}
- public function getMenuDefinition($targetVar)
+ public function getMenuDefinition($targetVar, $mode)
{
$str = "menu {$this->title}\n";
foreach ($this->items as $item) {
- $str .= $item->getMenuItemScript("m_{$this->menuid}", $this->defaultEntryId);
+ $str .= $item->getMenuItemScript("m_{$this->menuid}", $this->defaultEntryId, $mode);
}
if ($this->defaultEntryId === null) {
$defaultLabel = "mx_{$this->menuid}_poweroff";
@@ -61,11 +61,11 @@ class IPxeMenu
return $str;
}
- public function getItemsCode()
+ public function getItemsCode($mode)
{
$str = '';
foreach ($this->items as $item) {
- $str .= $item->getBootEntryScript("m_{$this->menuid}", 'fail');
+ $str .= $item->getBootEntryScript("m_{$this->menuid}", 'fail', $mode);
$str .= "goto slx_menu\n";
}
return $str;
diff --git a/modules-available/serversetup-bwlp/inc/menuentry.inc.php b/modules-available/serversetup-bwlp/inc/menuentry.inc.php
index 9d9d4163..03b860e8 100644
--- a/modules-available/serversetup-bwlp/inc/menuentry.inc.php
+++ b/modules-available/serversetup-bwlp/inc/menuentry.inc.php
@@ -58,8 +58,10 @@ class MenuEntry
settype($this->menuentryid, 'int');
}
- public function getMenuItemScript($lblPrefix, $requestedDefaultId)
+ public function getMenuItemScript($lblPrefix, $requestedDefaultId, $mode)
{
+ if ($this->bootEntry !== null && !$this->bootEntry->supportsMode($mode))
+ return '';
$str = 'item ';
if ($this->gap) {
$str .= '--gap ';
@@ -81,9 +83,9 @@ class MenuEntry
return $str . " || prompt Could not create menu item for {$lblPrefix}_{$this->menuentryid}\n";
}
- public function getBootEntryScript($lblPrefix, $failLabel)
+ public function getBootEntryScript($lblPrefix, $failLabel, $mode)
{
- if ($this->bootEntry === null)
+ if ($this->bootEntry === null || !$this->bootEntry->supportsMode($mode))
return '';
$str = ":{$lblPrefix}_{$this->menuentryid}\n";
if (!empty($this->md5pass)) {
@@ -94,7 +96,7 @@ class MenuEntry
. "goto slx_pass_check || goto $failLabel\n"
. ":{$lblPrefix}_ok\n";
}
- return $str . $this->bootEntry->toScript($failLabel);
+ return $str . $this->bootEntry->toScript($failLabel, $mode);
}
/*