summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2024-11-21 14:36:20 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-11-25 12:18:34 +0100
commit113472d5c0115d53d2fb99288759502d196a8e93 (patch)
tree7e3d77cedb5afb1f505d3df51848f79dda37db0a /src/rest.c
parent232e6eb30830eb74aac63e22e766f0f0848fb878 (diff)
src: add built-in ogrelive grub2 boot mode templatev1.2.5-26
Add built-in ogrelive grub2 boot mode template and use it to generate the grub2 boot file for each computer for the new live system. Use grub2 http to download vmlinuz, initrd.img. Use live support to download filesystem.squashfs through http. check for vmlinuz in cache, as usual, otherwise fallback to network boot.
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c59
1 files changed, 47 insertions, 12 deletions
diff --git a/src/rest.c b/src/rest.c
index 336c65d..db6f829 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -16,6 +16,7 @@
#include "wol.h"
#include "cfg.h"
#include "repo.h"
+#include "boot.h"
#include <ev.h>
#include <syslog.h>
#include <sys/ioctl.h>
@@ -1168,6 +1169,16 @@ static int og_get_boot_modes(struct list_head *boot_mode_list)
}
closedir(d);
+ /* ogrelive built-in grub2 template. */
+ mode = calloc(1, sizeof(struct og_boot_mode));
+ if (!mode) {
+ og_boot_mode_free(boot_mode_list);
+ return -1;
+ }
+
+ snprintf(mode->name, FILENAME_MAX, "ogrelive");
+ list_add_tail(&mode->list, boot_mode_list);
+
return 0;
}
@@ -1657,20 +1668,44 @@ static int og_set_client_mode(struct og_dbi *dbi, const char *client_ip,
return -1;
}
- if (og_get_client_mode_params(dbi, mac, params, sizeof(params)) < 0) {
- syslog(LOG_ERR, "failed to get boot parameters (%s:%d)\n", __FILE__, __LINE__);
- return -1;
- }
+ if (!strcmp(mode, "ogrelive")) {
+ struct og_boot_mode_params boot_params = {};
+ struct og_boot_cfg boot_cfg = {};
- if (og_create_boot_file(OG_TFTP_BOOT_BIOS, mac, mode, params) < 0) {
- syslog(LOG_ERR, "failed to create BIOS boot file (%s:%d)\n", __FILE__, __LINE__);
- return -1;
- }
+ if (og_boot_params_find(dbi, &boot_params, mac) < 0) {
+ syslog(LOG_ERR, "failed to get boot parameters (%s:%d)\n", __FILE__, __LINE__);
+ return -1;
+ }
- if (og_create_boot_file(OG_TFTP_BOOT_UEFI, mac, mode, params) < 0) {
- og_remove_tftpboot_file(OG_TFTP_BOOT_BIOS, mac);
- syslog(LOG_ERR, "failed to create UEFI boot file (%s:%d)\n", __FILE__, __LINE__);
- return -1;
+ boot_cfg.ogserver = boot_params.server_ip;
+ boot_cfg.ogrepo = boot_params.repo_ip;
+ boot_cfg.ogrelivedir = boot_params.oglivedir;
+ boot_cfg.username = "opengnsys";
+ boot_cfg.passwd = ogconfig.db.pass;
+
+ if (ogrelive_generate_grub2_file(&boot_cfg, mac) < 0) {
+ syslog(LOG_ERR, "failed to create HTTP boot file (%s:%d)\n", __FILE__, __LINE__);
+ og_boot_params_free(&boot_params);
+ return -1;
+ }
+
+ og_boot_params_free(&boot_params);
+ } else {
+ if (og_get_client_mode_params(dbi, mac, params, sizeof(params)) < 0) {
+ syslog(LOG_ERR, "failed to get boot parameters (%s:%d)\n", __FILE__, __LINE__);
+ return -1;
+ }
+
+ if (og_create_boot_file(OG_TFTP_BOOT_BIOS, mac, mode, params) < 0) {
+ syslog(LOG_ERR, "failed to create BIOS boot file (%s:%d)\n", __FILE__, __LINE__);
+ return -1;
+ }
+
+ if (og_create_boot_file(OG_TFTP_BOOT_UEFI, mac, mode, params) < 0) {
+ og_remove_tftpboot_file(OG_TFTP_BOOT_BIOS, mac);
+ syslog(LOG_ERR, "failed to create UEFI boot file (%s:%d)\n", __FILE__, __LINE__);
+ return -1;
+ }
}
if (og_change_db_mode(dbi, mac, mode) < 0) {