#!/bin/sh -efu
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2008  Michael A. Kangin <mak@rsmu.ru>
# Copyright (C) 2008-2023  Alexey Gladkov <gladkov.alexey@gmail.com>

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

pkgs="${PACKAGES_REQUIRED_COPY_SYSLINUX:-}"

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."

[ -f "$chroot/.image/syslinux/syslinux.cfg" ] ||
	message 'Warning: /.image/syslinux/syslinux.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
EOF
