From 318d05c58d45d992b964af89302ee8d252bea49d Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 29 Oct 2019 16:56:09 +0100 Subject: [minilinux] Move LinuxBootEntryHook to own file Under certain conditions the ipxe-bootentry hook would be executed multiple times, resuting in a fatal error because the class would be declared multiple times. --- .../minilinux/hooks/ipxe-bootentry.inc.php | 142 ------------------- .../minilinux/inc/linuxbootentryhook.inc.php | 150 +++++++++++++++++++++ 2 files changed, 150 insertions(+), 142 deletions(-) create mode 100644 modules-available/minilinux/inc/linuxbootentryhook.inc.php diff --git a/modules-available/minilinux/hooks/ipxe-bootentry.inc.php b/modules-available/minilinux/hooks/ipxe-bootentry.inc.php index 944cdfa3..b044ce5d 100644 --- a/modules-available/minilinux/hooks/ipxe-bootentry.inc.php +++ b/modules-available/minilinux/hooks/ipxe-bootentry.inc.php @@ -1,145 +1,3 @@ name(), [ - new HookEntry('default', - Dictionary::translateFileModule('minilinux', 'module', 'default_boot_entry', true), - MiniLinux::updateCurrentBootSetting()) - ]); - $branches = Database::queryAll('SELECT sourceid, branchid, title FROM minilinux_branch ORDER BY title'); - $versions = MiniLinux::queryAllVersionsByBranch(); - // Group by branch for detailed listing - foreach ($branches as $branch) { - if (isset($versions[$branch['branchid']])) { - $group = []; - foreach ($versions[$branch['branchid']] as $version) { - $valid = $version['installed'] != 0; - $title = $version['versionid'] . ' ' . $version['title']; - if (!$valid) { - $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); - } - } - return $array; - } - - /** - * @param $id - * @return BootEntry the actual boot entry instance for given entry, false if invalid id - */ - public function getBootEntryInternal($localData) - { - $id = $localData['id']; - if ($id === 'default') { // Special case - $effectiveId = Property::get(MiniLinux::PROPERTY_DEFAULT_BOOT_EFFECTIVE); - } else { - $effectiveId = $id; - } - $res = Database::queryFirst('SELECT installed, data FROM minilinux_version WHERE versionid = :id', ['id' => $effectiveId]); - if ($res === false) { - return BootEntry::newCustomBootEntry(['script' => 'prompt Invalid minilinux boot entry id: ' . $id]); - } - if ($res['installed'] == 0) { - return BootEntry::newCustomBootEntry(['script' => 'prompt Selected version not currently installed on server: ' . $effectiveId]); - } - $remoteData = json_decode($res['data'], true); - $bios = $efi = false; - if (!@is_array($remoteData['agnostic']) && !@is_array($remoteData['efi']) && !@is_array($remoteData['bios'])) { - $remoteData['agnostic'] = []; // We got nothing at all so fake this entry, resulting in a generic default entry - } - if (@is_array($remoteData['agnostic'])) { - $bios = $this->generateExecData($effectiveId, $remoteData['agnostic'], $localData); - $arch = BootEntry::AGNOSTIC; - } else { - if (@is_array($remoteData['efi'])) { - $efi = $this->generateExecData($effectiveId, $remoteData['efi'], $localData); - } - if (@is_array($remoteData['bios'])) { - $bios = $this->generateExecData($effectiveId, $remoteData['bios'], $localData); - } - if ($bios && $efi) { - $arch = BootEntry::BOTH; - } elseif ($bios) { - $arch = BootEntry::BIOS; - } else { - $arch = BootEntry::EFI; - } - } - return BootEntry::newStandardBootEntry($bios, $efi, $arch); - } - - private function generateExecData($effectiveId, $remoteData, $localData) - { - $exec = new ExecData(); - // Defaults - $root = '/boot/' . $effectiveId . '/'; - $exec->executable = 'kernel'; - $exec->initRd = ['initramfs-stage31']; - $exec->imageFree = true; - $exec->commandLine = 'slxbase=boot/%ID% slxsrv=${serverip} quiet splash ${ipappend1} ${ipappend2}'; - // Overrides - foreach (['executable', 'commandLine', 'initRd', 'imageFree'] as $key) { - if (isset($remoteData[$key])) { - $exec->{$key} = $remoteData[$key]; - } - } - // KCL hacks - if (isset($localData['debug']) && $localData['debug']) { - $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, - isset($remoteData['debugCommandLineModifier']) - ? $remoteData['debugCommandLineModifier'] - : '-vga -quiet -splash -loglevel loglevel=7' - ); - } - if (isset($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) { - $rd = $root . $rd; - } - unset($rd); - return $exec; - } - - public function isValidId($id) - { - $res = Database::queryFirst('SELECT installed FROM minilinux_version WHERE versionid = :id', ['id' => $id]); - return $res !== false && $res['installed']; - } -} - return new LinuxBootEntryHook(); \ No newline at end of file diff --git a/modules-available/minilinux/inc/linuxbootentryhook.inc.php b/modules-available/minilinux/inc/linuxbootentryhook.inc.php new file mode 100644 index 00000000..339c471d --- /dev/null +++ b/modules-available/minilinux/inc/linuxbootentryhook.inc.php @@ -0,0 +1,150 @@ +name(), [ + new HookEntry('default', + Dictionary::translateFileModule('minilinux', 'module', 'default_boot_entry', true), + MiniLinux::updateCurrentBootSetting()) + ]); + $branches = Database::queryAll('SELECT sourceid, branchid, title FROM minilinux_branch ORDER BY title'); + $versions = MiniLinux::queryAllVersionsByBranch(); + // Group by branch for detailed listing + foreach ($branches as $branch) { + if (isset($versions[$branch['branchid']])) { + $group = []; + foreach ($versions[$branch['branchid']] as $version) { + $valid = $version['installed'] != 0; + $title = $version['versionid'] . ' ' . $version['title']; + if (!$valid) { + $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); + } + } + return $array; + } + + /** + * @param $id + * @return BootEntry the actual boot entry instance for given entry, false if invalid id + */ + public function getBootEntryInternal($localData) + { + $id = $localData['id']; + if ($id === 'default') { // Special case + $effectiveId = Property::get(MiniLinux::PROPERTY_DEFAULT_BOOT_EFFECTIVE); + } else { + $effectiveId = $id; + } + $res = Database::queryFirst('SELECT installed, data FROM minilinux_version WHERE versionid = :id', ['id' => $effectiveId]); + if ($res === false) { + return BootEntry::newCustomBootEntry(['script' => 'prompt Invalid minilinux boot entry id: ' . $id]); + } + if ($res['installed'] == 0) { + return BootEntry::newCustomBootEntry(['script' => 'prompt Selected version not currently installed on server: ' . $effectiveId]); + } + $remoteData = json_decode($res['data'], true); + $bios = $efi = false; + if (!@is_array($remoteData['agnostic']) && !@is_array($remoteData['efi']) && !@is_array($remoteData['bios'])) { + $remoteData['agnostic'] = []; // We got nothing at all so fake this entry, resulting in a generic default entry + } + if (@is_array($remoteData['agnostic'])) { + $bios = $this->generateExecData($effectiveId, $remoteData['agnostic'], $localData); + $arch = BootEntry::AGNOSTIC; + } else { + if (@is_array($remoteData['efi'])) { + $efi = $this->generateExecData($effectiveId, $remoteData['efi'], $localData); + } + if (@is_array($remoteData['bios'])) { + $bios = $this->generateExecData($effectiveId, $remoteData['bios'], $localData); + } + if ($bios && $efi) { + $arch = BootEntry::BOTH; + } elseif ($bios) { + $arch = BootEntry::BIOS; + } else { + $arch = BootEntry::EFI; + } + } + return BootEntry::newStandardBootEntry($bios, $efi, $arch); + } + + private function generateExecData($effectiveId, $remoteData, $localData) + { + $exec = new ExecData(); + // Defaults + $root = '/boot/' . $effectiveId . '/'; + $exec->executable = 'kernel'; + $exec->initRd = ['initramfs-stage31']; + $exec->imageFree = true; + $exec->commandLine = 'slxbase=boot/%ID% slxsrv=${serverip} quiet splash ${ipappend1} ${ipappend2}'; + // Overrides + foreach (['executable', 'commandLine', 'initRd', 'imageFree'] as $key) { + if (isset($remoteData[$key])) { + $exec->{$key} = $remoteData[$key]; + } + } + // KCL hacks + if (isset($localData['debug']) && $localData['debug']) { + $exec->commandLine = IPxe::modifyCommandLine($exec->commandLine, + isset($remoteData['debugCommandLineModifier']) + ? $remoteData['debugCommandLineModifier'] + : '-vga -quiet -splash -loglevel loglevel=7' + ); + } + if (isset($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) { + $rd = $root . $rd; + } + unset($rd); + return $exec; + } + + public function isValidId($id) + { + $res = Database::queryFirst('SELECT installed FROM minilinux_version WHERE versionid = :id', ['id' => $id]); + return $res !== false && $res['installed']; + } +} -- cgit v1.2.3-55-g7522