#!/bin/sh -efu
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2007-2023  Alexey Gladkov <gladkov.alexey@gmail.com>

# shellcheck source=tools/mki-sh-functions
. "${0%/*}"/mki-sh-functions

pkgs="${PACKAGES_REQUIRED_COPY_PXELINUX:-}"

verbose "has started executing."

[ -d "$chroot" ] ||
	fatal "$dir: not look like a work directory of hasher."

mki-install $pkgs ||
	fatal "failed to install packages: $pkgs."

[ -d "$chroot/.image/syslinux/pxelinux.cfg" ] ||
	message 'Warning: /.image/tftpboot/pxelinux.cfg: not found.'

run_chrooted "$chroot" <<EOF
#!/bin/sh -efu

. /.host/mki-chroot-sh-functions

mkdir $verbose -p -- /.image/syslinux/alt0

kimage=
find_vmlinuz kimage

[ -n "\$kimage" ] ||
	fatal 'Kernel vmlinuz image could not be located in /boot directory!'

cp $verbose -aLf "\$kimage" /.image/syslinux/alt0/vmlinuz

[ ! -f /boot/full.cz ] ||
	cp $verbose -aLf /boot/full.cz /.image/syslinux/alt0/full.cz

cp $verbose -f /usr/lib/syslinux/pxelinux.0 /.image/syslinux/
EOF
