# --- SDE-COPYRIGHT-NOTE-BEGIN ---
# This copyright note is auto-generated by ./scripts/Create-CopyPatch.
#
# Filename: package/.../mkinitramfs/find_template.in
# Copyright (C) 2008 The OpenSDE Project
#
# More information can be found in the files COPYING and README.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License. A copy of the
# GNU General Public License can be found in the file COPYING.
# --- SDE-COPYRIGHT-NOTE-END ---

# find the image
#
initrd_img="$base/config/$config/initrd.img"
if [ -s "$initrd_img" ]; then
	# explicit overwrite
	echo_status "mkinitramfs: Using given ${mkinitramfs_tpl#$base/}."
elif [ -z "$SDECFG_PKG_MKINITRAMFS_TPL" ]; then
	initrd_img=
else
	# wanted initramfs config
	x="$base/config/$SDECFG_PKG_MKINITRAMFS_TPL/config"
	if [ ! -s "$x" ]; then
		echo_error "mkinitramfs: '$SDECFG_PKG_MKINITRAMFS_TPL' config not found."
		initrd_img=
	else
		x=$(grep SDECFG_ID= "$x" | cut -d"'" -f2)
		if [ -d "$base/loop/build" ]; then
			initrd_img="$base/loop/build/$x/TOOLCHAIN/initrd.img"
		else
			initrd_img="$base/build/$x/TOOLCHAIN/initrd.img"
		fi

		if [ -s "$initrd_img" ]; then
			echo_status "mkinitramfs: Using $SDECFG_PKG_MKINITRAMFS_TPL's initrd.img"
		else
			echo_error "mkinitramfs: '$SDECFG_PKG_MKINITRAMFS_TPL' doesn't contain an initrd.img"
			initrd_img=
		fi
	fi
fi