浏览代码

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
Antony Messerli 5 年之前
父节点
当前提交
413f49b4d5

+ 3 - 0
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.

+ 0 - 12
TODO.md

@@ -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

+ 24 - 0
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
+```

+ 36 - 0
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

+ 11 - 0
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"

+ 18 - 0
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

+ 4 - 0
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

+ 15 - 3
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