#!/system/bin/sh
set -xe

# Add logo
echo "logo $1/logo.bin" >> "$BOOTSET/db/entries/$1.conf"
cp "$3" "$BOOTSET/$1/logo.bin"

# Create working dir
TEMP="$(mktemp -d)"
mkdir -p "$TEMP/boot"

# Copy boot
cp "$2" "$TEMP/boot/boot.img"

# Unpack boot
unpackbootimg -i "$TEMP/boot/boot.img" -o "$TEMP/boot/"

# Format partition
DATAPART=$6
dataformat() {
true | mkfs.ext4 "$DATAPART"
}
$FORMATDATA && dataformat

# Copy kernel
cp "$TEMP/boot/boot.img-kernel" "$BOOTSET/$1/zImage"

# Copy rd
cp "$4" "$BOOTSET/$1/initrd.cpio.gz"

# Copy maps
cp $BOOTSET/$1/0.map $BOOTSET/ut_system.map
cp $BOOTSET/$1/1.map $BOOTSET/ut_data.map
