#!/bin/ash -efu
#
# mki-copy-yaboot
#
# This file is part of mkimage
# Copyright (C) 2008  Sergey Bolshakov <sbolshakov@altlinux.org>
# Copyright (C) 2008-2009  Alexey Gladkov <gladkov.alexey@gmail.com>
#
# This file is covered by the GNU General Public License,
# which should be included with mkimage as the file COPYING.
#

. "${0%/*}"/mki-sh-functions

pkgs="${PACKAGES_REQUIRED_COPY_YABOOT:-}"
imgsubdir="${MKI_IMAGESUBDIR:-}"
imgsubdir="${imgsubdir#/}"

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/$imgsubdir/etc/yaboot.conf" ] ||
	message "Warning: /.image/$imgsubdir/etc/yaboot.conf: not found."

make_exec "$chroot/.host/packimage.sh" <<EOF
#!/bin/sh -efu

mkdir $verbose -p -- \
	/.image/$imgsubdir/etc \
	/.image/$imgsubdir/ppc/chrp \
	/.image/$imgsubdir/ps3/otheros

cd /.image/$imgsubdir/

initrd=
[ ! -f /boot/full.cz ] ||
	initrd=/boot/full.cz

cp $verbose -aLf \
	/boot/vmlinuz /usr/lib/yaboot/yaboot \$initrd \
	./ppc/chrp/

wrapper -p ps3 \
	\${initrd:+-i \$initrd} \
	-o ./ps3/otheros/otheros.bld \
	/boot/vmlinuz

rm -f -- ./ps3/otheros/otheros.bld.bin
EOF

mki_run_once "$chroot" "/.host/packimage.sh"
