summaryrefslogtreecommitdiffstats
path: root/modules-available/minilinux/inc/linuxbootentryhook.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/minilinux/inc/linuxbootentryhook.inc.php')
-rw-r--r--modules-available/minilinux/inc/linuxbootentryhook.inc.php81
1 files changed, 56 insertions, 25 deletions
diff --git a/modules-available/minilinux/inc/linuxbootentryhook.inc.php b/modules-available/minilinux/inc/linuxbootentryhook.inc.php
index 324ffc7e..1424b6b9 100644
--- a/modules-available/minilinux/inc/linuxbootentryhook.inc.php
+++ b/modules-available/minilinux/inc/linuxbootentryhook.inc.php
@@ -10,38 +10,41 @@
class LinuxBootEntryHook extends BootEntryHook
{
- public function name()
+ public function name(): string
{
- return Dictionary::translateFileModule('minilinux', 'module', 'module_name', true);
+ return Dictionary::translateFileModule('minilinux', 'module', 'module_name');
}
- public function extraFields()
+ public function extraFields(): array
{
/* For translate module:
* Dictionary::translate('ipxe-kcl-extra');
* Dictionary::translate('ipxe-debug');
* Dictionary::translate('ipxe-insecure-cpu');
+ * Dictionary::translate('ipxe-force-init-dhcp');
*/
return [
new HookExtraField('kcl-extra', 'string', ''),
new HookExtraField('debug', 'bool', false),
new HookExtraField('insecure-cpu', 'bool', false),
+ new HookExtraField('force-init-dhcp', 'bool', false),
];
}
/**
* @return HookEntryGroup[]
*/
- protected function groupsInternal()
+ protected function groupsInternal(): array
{
/*
* Dictionary::translate('default_boot_entry');
* Dictionary::translate('not_installed_hint');
+ * Dictionary::translate('latest_of_branch');
*/
$array = [];
$array[] = new HookEntryGroup($this->name(), [
new HookEntry('default',
- Dictionary::translateFileModule('minilinux', 'module', 'default_boot_entry', true),
+ Dictionary::translateFileModule('minilinux', 'module', 'default_boot_entry'),
MiniLinux::updateCurrentBootSetting())
]);
$branches = Database::queryAll('SELECT sourceid, branchid, title FROM minilinux_branch ORDER BY title');
@@ -49,26 +52,32 @@ class LinuxBootEntryHook extends BootEntryHook
// Group by branch for detailed listing
foreach ($branches as $branch) {
if (isset($versions[$branch['branchid']])) {
- $group = [];
+ $group = [
+ new HookEntry($branch['branchid'],
+ $branch['branchid'] . ' '
+ . Dictionary::translateFileModule('minilinux', 'module',
+ 'latest_of_branch'),
+ true),
+ ];
foreach ($versions[$branch['branchid']] as $version) {
- $valid = $version['installed'] != 0;
+ $valid = $version['installed'] != MiniLinux::INSTALL_MISSING;
$title = $version['versionid'] . ' ' . $version['title'];
if (!$valid) {
- $title .= ' ' . Dictionary::translateFileModule('minilinux', 'module', 'not_installed_hint');
+ $title .= ' ' . Dictionary::translateFileModule('minilinux', 'module',
+ 'not_installed_hint');
}
$group[] = new HookEntry($version['versionid'], $title, $valid);
}
- $array[] = new HookEntryGroup($branch['title'] ? $branch['title'] : $branch['branchid'], $group);
+ $array[] = new HookEntryGroup($branch['title'] ?: $branch['branchid'], $group);
}
}
return $array;
}
/**
- * @param $id
- * @return BootEntry the actual boot entry instance for given entry, false if invalid id
+ * @return ?BootEntry the actual boot entry instance for given entry, false if invalid id
*/
- public function getBootEntryInternal($localData)
+ public function getBootEntryInternal(array $localData): ?BootEntry
{
$id = $localData['id'];
if ($id === 'default') { // Special case
@@ -76,13 +85,19 @@ class LinuxBootEntryHook extends BootEntryHook
} else {
$effectiveId = $id;
}
- $res = Database::queryFirst('SELECT installed, data FROM minilinux_version WHERE versionid = :id', ['id' => $effectiveId]);
+ $res = Database::queryFirst('SELECT versionid, installed, data FROM minilinux_version WHERE versionid = :id',
+ ['id' => $effectiveId]);
if ($res === false) {
- return BootEntry::newCustomBootEntry(['script' => 'prompt Invalid minilinux boot entry id: ' . $id]);
+ // Maybe this is a branchid, which means latest from according branch (installed only)
+ $res = Database::queryFirst('SELECT versionid, installed, data FROM minilinux_version
+ WHERE branchid = :id AND installed = :ok
+ ORDER BY dateline DESC LIMIT 1',
+ ['id' => $effectiveId, 'ok' => MiniLinux::INSTALL_OK]);
}
- if ($res['installed'] == 0) {
+ if ($res === false) {
return BootEntry::newCustomBootEntry(['script' => 'prompt Selected version not currently installed on server: ' . $effectiveId]);
}
+ $effectiveId = $res['versionid']; // In case we selected from a branchid, so above message doesn't show versionid
$remoteData = json_decode($res['data'], true);
$bios = $efi = false;
if (!@is_array($remoteData['agnostic']) && !@is_array($remoteData['efi']) && !@is_array($remoteData['bios'])) {
@@ -106,10 +121,10 @@ class LinuxBootEntryHook extends BootEntryHook
$arch = BootEntry::EFI;
}
}
- return BootEntry::newStandardBootEntry($bios, $efi, $arch);
+ return BootEntry::newStandardBootEntry($bios, $efi, $arch, 'ml-' . $id);
}
- private function generateExecData($effectiveId, $remoteData, $localData)
+ private function generateExecData($effectiveId, $remoteData, $localData): ExecData
{
$exec = new ExecData();
// Defaults
@@ -117,7 +132,9 @@ class LinuxBootEntryHook extends BootEntryHook
$exec->executable = 'kernel';
$exec->initRd = ['initramfs-stage31'];
$exec->imageFree = true;
- $exec->commandLine = 'slxbase=boot/%ID% slxsrv=${serverip} quiet splash ${ipappend1} ${ipappend2}';
+ $exec->commandLine = 'slxbase=boot/%ID% slxsrv=${serverip} quiet splash ${ipappend1} ${ipappend2}'
+ . ' ipv4.ip=${ip} ipv4.router=${gateway} ipv4.dns=${dns} ipv4.hostname=${hostname} ipv4.domain=${domain} ipv4.search=${dnssl}'
+ . ' ipv4.if=${mac} ipv4.ntpsrv=${ntpsrv} ipv4.subnet=${netmask}';
// Overrides
foreach (['executable', 'commandLine', 'initRd', 'imageFree'] as $key) {
if (isset($remoteData[$key])) {
@@ -128,23 +145,34 @@ class LinuxBootEntryHook extends BootEntryHook
if (!empty($localData['debug'])) {
// Debug boot enabled
$exec->commandLine = IPxe::modifyCommandLine($exec->commandLine,
- isset($remoteData['debugCommandLineModifier'])
- ? $remoteData['debugCommandLineModifier']
- : '-vga -quiet -splash -loglevel loglevel=7'
+ $remoteData['debugCommandLineModifier'] ?? '-vga -quiet -splash -loglevel loglevel=7'
);
}
// disable all CPU sidechannel attack mitigations etc.
if (!empty($localData['insecure-cpu'])) {
$exec->commandLine = IPxe::modifyCommandLine($exec->commandLine,
- 'noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off mitigations=off');
+ 'noibrs noibpb nopti nospectre_v2 nospectre_v1 l1tf=off nospec_store_bypass_disable no_stf_barrier mds=off mitigations=off i915.mitigations=off');
+ }
+ // force that we
+ if (!empty($localData['force-init-dhcp'])) {
+ $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine,
+ '-ipv4.router -ipv4.dns -ipv4.subnet');
+ }
+ // GVT, PCI Pass-thru etc.
+ if (Module::isAvailable('statistics')) {
+ $hwextra = HardwareInfo::getKclModifications();
+ if (!empty($hwextra)) {
+ $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, $hwextra);
+ }
}
+ // User-supplied modifications
if (!empty($localData['kcl-extra'])) {
$exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, $localData['kcl-extra']);
}
$exec->commandLine = str_replace('%ID%', $effectiveId, $exec->commandLine);
$exec->executable = $root . $exec->executable;
foreach ($exec->initRd as &$rd) {
- if ($rd{0} !== '/') {
+ if ($rd[0] !== '/') {
$rd = $root . $rd;
}
}
@@ -152,11 +180,14 @@ class LinuxBootEntryHook extends BootEntryHook
return $exec;
}
- public function isValidId($id)
+ public function isValidId(string $id): bool
{
if ($id === 'default')
return true; // Meta-version that links to whatever the default is set to
$res = Database::queryFirst('SELECT installed FROM minilinux_version WHERE versionid = :id', ['id' => $id]);
- return $res !== false && $res['installed'];
+ if ($res !== false && $res['installed'] != MiniLinux::INSTALL_MISSING)
+ return true;
+ $res = Database::queryFirst('SELECT branchid FROM minilinux_branch WHERE branchid = :id', ['id' => $id]);
+ return $res !== false;
}
}