From 413f49b4d5d11ebca429f342cf08e3d07e970f94 Mon Sep 17 00:00:00 2001 From: Antony Messerli Date: Fri, 29 Nov 2019 16:02:15 -0600 Subject: [PATCH] Add ability for self hosted custom menus (#23) * Adds ability for self hosted custom menus Templates can be added to /etc/netbootxyz/custom and are generated and placed in the custom directory of the root web directory by setting custom_generate_menus to true. This provides an option on the main netboot.xyz menu to chain into a custom environment so that seperate local menus can be added and maintained seperately from the netboot.xyz source code tree. * Remove todo --- README.md | 3 ++ TODO.md | 12 ------- etc/netbootxyz/custom/README.md | 24 +++++++++++++ etc/netbootxyz/custom/custom.ipxe.j2 | 36 +++++++++++++++++++ roles/netbootxyz/defaults/main.yml | 11 ++++++ .../tasks/generate_menus_custom.yml | 18 ++++++++++ roles/netbootxyz/tasks/main.yml | 4 +++ roles/netbootxyz/templates/menu/menu.ipxe.j2 | 18 ++++++++-- 8 files changed, 111 insertions(+), 15 deletions(-) delete mode 100644 TODO.md create mode 100644 etc/netbootxyz/custom/README.md create mode 100644 etc/netbootxyz/custom/custom.ipxe.j2 create mode 100644 roles/netbootxyz/tasks/generate_menus_custom.yml diff --git a/README.md b/README.md index aa93db07..469a4aa7 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,6 @@ If you want to override the defaults, you can put overrides in user_overrides.ym Also note many user customizations are located in the boot.cfg file for the IPXE menus. A high level of customization can be achieved using our stock build output and hosting this along with the menus locally. +## Self Hosted Custom Options + +In addition to being able to host netboot.xyz locally, you can also create your own custom templates for custom menus within netboot.xyz. Please see [Custom User Menus](etc/netbootxyz/custom/README.md) for more information. \ No newline at end of file diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 036513b4..00000000 --- a/TODO.md +++ /dev/null @@ -1,12 +0,0 @@ -## TODO - -* Finish the templates -* Convert utilties to dictionary -* Signature generation -* Custom iPXE Certificate generation -* Logic to mirror repos locally for airgapped environments or those with plenty of space. -* Webserver optimization, make configurable (nginx, apache, etc) -* More host OS support -* Docker images -* package cacher -* port netboot.xyz to this in staging env to validate and test diff --git a/etc/netbootxyz/custom/README.md b/etc/netbootxyz/custom/README.md new file mode 100644 index 00000000..2a6c0c3f --- /dev/null +++ b/etc/netbootxyz/custom/README.md @@ -0,0 +1,24 @@ +# Custom Menus for Self Hosted netboot.xyz + +This directory contains custom iPXE files that are rendered +during menu generation and available from the main menu via +the custom menu option. + +When these options are set: + +``` +custom_generate_menus: true +custom_templates_dir: "{{ netbootxyz_conf_dir }}/custom" +``` + +the menu will add an option for custom menus and attempt to load into +custom/custom.ipxe. From there custom options can be built and +maintained seperately from the netboot.xyz source tree so that both +menus can be updated independently. + +A sample menu is provided to demonstrate how to configure and set up +a menu. You can copy the custom directory from the repo: + +``` +cp etc/netbootxyz/custom /etc/netbootxyz/custom +``` \ No newline at end of file diff --git a/etc/netbootxyz/custom/custom.ipxe.j2 b/etc/netbootxyz/custom/custom.ipxe.j2 new file mode 100644 index 00000000..42f1f41b --- /dev/null +++ b/etc/netbootxyz/custom/custom.ipxe.j2 @@ -0,0 +1,36 @@ +#!ipxe +### +### {{ site_name }} custom menu example +### + +:custom +clear custom_choice +menu This is a Test Menu +item --gap This is the first sub menu +item option_one ${space} Loading a kernel and initrd +item option_two ${space} Loading an ISO +item --gap This is a second sub menu +item option_three ${space} Loads another custom sub menu +item option_four ${space} This is option four +choose custom_choice || goto custom_exit +echo ${cls} +goto ${custom_choice} +goto custom_exit + +:option_one +kernel http://path.to/vmlinuz +initrd http://path.to/initrd +imgargs vmlinuz put_kernel_img_args_here +boot || goto custom_exit + +:option_two +kernel {{ memdisk_location }} raw iso +initrd http://path.to/iso +boot || goto custom_exit + +:option_three +echo Chains into another menu... +chain custom1.ipxe || goto custom + +:custom_exit +exit diff --git a/roles/netbootxyz/defaults/main.yml b/roles/netbootxyz/defaults/main.yml index 83665ca8..b5820e0c 100644 --- a/roles/netbootxyz/defaults/main.yml +++ b/roles/netbootxyz/defaults/main.yml @@ -6,6 +6,9 @@ boot_domain: boot.netboot.xyz boot_version: 1.04 boot_timeout: 300000 time_server: "0.pool.ntp.org" + +# signature checking +sigs_menu: false sigs_enabled: false img_sigs_enabled: false @@ -19,6 +22,7 @@ ipxe_branch: master ipxe_source_dir: /usr/src/ipxe netbootxyz_root: /var/www/html +netbootxyz_conf_dir: /etc/netbootxyz # live os settings live_endpoint: "https://github.com/netbootxyz" @@ -36,6 +40,13 @@ bootloader_http_enabled: true bootloader_disks: - "netboot.xyz" +# custom menus +# custom_github_menus allows for github custom menus +# custom_generate_menus allows for self hosted custom menus to be added +custom_github_menus: true +custom_generate_menus: false +custom_templates_dir: "{{ netbootxyz_conf_dir }}/custom" + # signature generation generate_signatures: false sigs_dir: "{{ netbootxyz_root }}/sigs" diff --git a/roles/netbootxyz/tasks/generate_menus_custom.yml b/roles/netbootxyz/tasks/generate_menus_custom.yml new file mode 100644 index 00000000..ed36090f --- /dev/null +++ b/roles/netbootxyz/tasks/generate_menus_custom.yml @@ -0,0 +1,18 @@ +--- + + - name: Generate directories + file: + path: "{{ item }}" + state: directory + with_items: + - "{{ custom_templates_dir }}" + - "{{ netbootxyz_root }}/custom" + + - name: Generate custom user menu templates + template: + src: "{{ item.src }}" + dest: "{{ netbootxyz_root }}/custom/{{ item.path | regex_replace('.j2','') }}" + with_filetree: "{{ custom_templates_dir }}" + when: item.state == "file" + tags: + - skip_ansible_lint \ No newline at end of file diff --git a/roles/netbootxyz/tasks/main.yml b/roles/netbootxyz/tasks/main.yml index 301d8a88..b614f034 100644 --- a/roles/netbootxyz/tasks/main.yml +++ b/roles/netbootxyz/tasks/main.yml @@ -3,6 +3,10 @@ when: - generate_menus | default(true) | bool + - include: generate_menus_custom.yml + when: + - custom_generate_menus | default(false) | bool + - include: generate_signatures.yml when: - generate_signatures | default(false) | bool diff --git a/roles/netbootxyz/templates/menu/menu.ipxe.j2 b/roles/netbootxyz/templates/menu/menu.ipxe.j2 index 51dda817..0dde2e1c 100644 --- a/roles/netbootxyz/templates/menu/menu.ipxe.j2 +++ b/roles/netbootxyz/templates/menu/menu.ipxe.j2 @@ -53,11 +53,19 @@ iseq ${arch} x86_64 && set bits 64 || set bits 32 item changebits ${space} Architecture: ${arch} (${bits}bit) item shell ${space} iPXE shell item netinfo ${space} Network card info +{% if sigs_menu | bool %} item --gap Signature Checks: item sig_check ${space} netboot.xyz [ enabled: ${sigs_enabled} ] item img_sigs_check ${space} Images [ enabled: ${img_sigs_enabled} ] -isset ${github_user} && item --gap Custom Menu: || -isset ${github_user} && item nbxyz-custom ${space} ${github_user}'s Custom Menu || +{% endif %} +{% if custom_github_menus | bool %} +isset ${github_user} && item --gap Custom Github Menu: || +isset ${github_user} && item custom-github ${space} ${github_user}'s Custom Menu || +{% endif %} +{% if custom_generate_menus | bool %} +item --gap Custom User Menus: || +item custom-user ${space} Custom User Menus +{% endif %} isset ${menu} && set timeout 0 || set timeout {{ boot_timeout }} choose --timeout ${timeout} --default ${menu} menu || goto local echo ${cls} @@ -99,6 +107,10 @@ goto main_menu iseq ${img_sigs_enabled} true && set img_sigs_enabled false || set img_sigs_enabled true goto main_menu -:nbxyz-custom +:custom-github chain https://raw.githubusercontent.com/${github_user}/netboot.xyz-custom/master/custom.ipxe || goto error goto main_menu + +:custom-user +chain custom/custom.ipxe +goto main_menu \ No newline at end of file