Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New PXE loader "Grub2 UEFI SecureBoot (target OS)" #857

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions modules/tftp/server.rb
Expand Up @@ -108,6 +108,27 @@ def pxeconfig_file(mac)
end
end

class Pxegrub2targetos < Server
def setup_bootloader(mac, os)
FileUtils.mkdir_p(pxeconfig_dir(mac))
FileUtils.cp "/usr/local/share/bootloader-universe/#{os}/shimx64.efi", pxeconfig_dir(mac) + "shimx64.efi"
FileUtils.cp "/usr/local/share/bootloader-universe/#{os}/grubx64.efi", pxeconfig_dir(mac) + "grubx64.efi"
File.open(pxeconfig_dir(mac) + "/targetos", 'w') { |f| f.write(os) }
end

def pxeconfig_dir(mac)
"#{path}/grub2/" + mac.tr(':', '-').downcase + "/"
end

def pxe_default(mac)
["#{pxeconfig_dir}/grub.cfg", "#{pxeconfig_dir(mac)}/grub.cfg"]
end

def pxeconfig_file(mac)
["#{pxeconfig_dir(mac)}/grub.cfg", "#{pxeconfig_dir(mac)}/grub.cfg-01-" + mac.tr(':', '-').downcase, "#{pxeconfig_dir(mac)}/grub.cfg-#{mac.downcase}"]
end
end

class Ztp < Server
def pxeconfig_dir
"#{path}/ztp.cfg"
Expand Down
14 changes: 12 additions & 2 deletions modules/tftp/tftp_api.rb
Expand Up @@ -8,7 +8,7 @@ class Api < ::Sinatra::Base
helpers ::Proxy::Helpers
authorize_with_trusted_hosts
authorize_with_ssl_client
VARIANTS = ["Syslinux", "Pxelinux", "Pxegrub", "Pxegrub2", "Ztp", "Poap", "Ipxe"].freeze
VARIANTS = ["Syslinux", "Pxelinux", "Pxegrub", "Pxegrub2", "Pxegrub2targetos", "Ztp", "Poap", "Ipxe"].freeze

helpers do
def instantiate(variant, mac = nil)
Expand All @@ -23,6 +23,12 @@ def create(variant, mac)
log_halt(400, "TFTP: Failed to create pxe config file: ") { tftp.set(mac, (params[:pxeconfig] || params[:syslinux_config])) }
end

def create_targetos(variant, mac, os)
tftp = instantiate variant, mac
log_halt(400, "TFTP: Failed to setup target OS bootloader directory: ") { tftp.setup_bootloader(mac, os)}
log_halt(400, "TFTP: Failed to create pxe config file: ") { tftp.set(mac, (params[:pxeconfig] || params[:syslinux_config])) }
end

def delete(variant, mac)
tftp = instantiate variant, mac
log_halt(400, "TFTP: Failed to delete pxe config file: ") { tftp.del(mac) }
Expand All @@ -48,7 +54,11 @@ def create_default(variant)
end

post "/:variant/:mac" do |variant, mac|
create variant, mac
unless params[:targetos].nil?
create_targetos variant, mac, params[:targetos]
else
create variant, mac
end
end

delete "/:variant/:mac" do |variant, mac|
Expand Down