Sha256: bb79082d4499ea791e08246d2772b9ca53a2177420fdb98335c2dfb58441ce34

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

# Generates an iPXE ISO hybrid image
#
# requires syslinux, ipxe/ipxe-bootimgs, mkisofs, isohybrid
class Bootdisk::ISOGenerator
  attr_reader :script

  def initialize(script, opts = {})
    @script = script
  end

  def generate(&block)
    Dir.mktmpdir('bootdisk') do |wd|
      Dir.mkdir(File.join(wd, 'build'))
      File.open(File.join(wd, 'build', 'isolinux.cfg'),'w') do |file|
        file.write(<<EOF)
default ipxe
label ipxe
kernel /ipxe
initrd /script
EOF
      end

      FileUtils.cp(File.join(Setting[:bootdisk_syslinux_dir], 'isolinux.bin'), File.join(wd, 'build', 'isolinux.bin'))
      FileUtils.cp(File.join(Setting[:bootdisk_ipxe_dir], 'ipxe.lkrn'), File.join(wd, 'build', 'ipxe'))
      File.open(File.join(wd, 'build', 'script'),'w') { |file| file.write(script) }

      iso = File.join(wd, 'output.iso')
      unless system("mkisofs -o #{iso} -b isolinux.bin -c boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table #{File.join(wd, 'build')}")
        raise ::Foreman::Exception.new(N_("ISO build failed"))
      end

      # Make the ISO bootable as a HDD/USB disk too
      unless system("isohybrid", iso)
        raise ::Foreman::Exception.new(N_("ISO hybrid conversion failed"))
      end

      yield iso
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_bootdisk-1.2.1 app/services/bootdisk/iso_generator.rb
foreman_bootdisk-1.2.0 app/services/bootdisk/iso_generator.rb
foreman_bootdisk-1.1.0 app/services/bootdisk/iso_generator.rb