<%page args="kernels, runtime_img, runtime_base, basearch, outroot, arch"/>
<%
configdir="tmp/config_files/uboot"
PXEBOOTDIR="images/pxeboot"
BOOTDIR="boot"
KERNELDIR=PXEBOOTDIR
LIVEDIR="LiveOS"
LORAXDIR="usr/share/lorax/"

from os.path import basename
%>

mkdir ${LIVEDIR}
install ${runtime_img} ${LIVEDIR}/squashfs.img
treeinfo stage2 mainimage ${LIVEDIR}/squashfs.img

## install kernels
mkdir ${KERNELDIR}
%for kernel in kernels:
    %if kernel.flavor:
        installkernel images-${kernel.flavor}-${basearch} ${kernel.path} ${KERNELDIR}/vmlinuz-${kernel.flavor}
        installinitrd images-${kernel.flavor}-${basearch} ${kernel.initrd.path} ${KERNELDIR}/initrd-${kernel.flavor}.img

        treeinfo images-${kernel.flavor}-${basearch} uimage ${KERNELDIR}/uImage-${kernel.flavor}
        treeinfo images-${kernel.flavor}-${basearch} uinitrd ${KERNELDIR}/uInitrd-${kernel.flavor}

    %else:
        installkernel images-${basearch} ${kernel.path} ${KERNELDIR}/vmlinuz
        installinitrd images-${basearch} ${kernel.initrd.path} ${KERNELDIR}/initrd.img

        treeinfo images-${basearch} uimage ${KERNELDIR}/uImage
        treeinfo images-${basearch} uinitrd ${KERNELDIR}/uInitrd

    %endif
%endfor

# Create optional product.img and updates.img
<% images=["product", "updates"] %>
%for img in images:
    %if exists("%s/%s/" % (LORAXDIR, img)):
        installimg --xz -9 --memlimit-compress=3700MiB ${LORAXDIR}/${img}/ images/${img}.img
        treeinfo images-${basearch} ${img}.img images/${img}.img
    %endif
%endfor

# Add the license files
%for f in glob("/usr/share/licenses/*-release/*"):
    install ${f} ${f|basename}
%endfor

## FIXME: ARM may need some extra boot config

