[source]
git = "https://gitlab.redox-os.org/redox-os/redox-initfs.git"

[build]
template = "custom"
dependencies = [
  "bootstrap",
  "drivers-initfs",
  "init",
  "logd",
  "ramfs",
  "randd",
  "redoxfs",
  "zerod",
]
script = """
INITFS_RM_BINS='redoxfs-ar redoxfs-mkfs'

mkdir -p "${COOKBOOK_BUILD}/initfs/etc"

cp -r "${COOKBOOK_SYSROOT}/"* "${COOKBOOK_BUILD}/initfs"

# TODO: Move init.rc to another recipe, perhaps initfs-misc? Then it can be installed as a regular dependency.
cp "${COOKBOOK_RECIPE}/init.rc" "${COOKBOOK_BUILD}/initfs/etc/init.rc"
if [ -e ${COOKBOOK_RECIPE}/${TARGET}/init.rc.${BOARD} ]; then
    cp "${COOKBOOK_RECIPE}/${TARGET}/init.rc.${BOARD}" "${COOKBOOK_BUILD}/initfs/etc/init.rc"
elif [ -e ${COOKBOOK_RECIPE}/${TARGET}/init.rc ]; then
    cp "${COOKBOOK_RECIPE}/${TARGET}/init.rc" "${COOKBOOK_BUILD}/initfs/etc/init.rc"
fi

# Move /usr/bin files to /bin
mkdir -p "${COOKBOOK_BUILD}/initfs/bin"
if [ -d "${COOKBOOK_BUILD}/initfs/usr/bin" ]
then
    mv "${COOKBOOK_BUILD}/initfs/usr/bin/"* "${COOKBOOK_BUILD}/initfs/bin"
    rmdir "${COOKBOOK_BUILD}/initfs/usr/bin"
fi

for bin in ${INITFS_RM_BINS}; do
  rm -f "${COOKBOOK_BUILD}/initfs/bin/$bin"
done

env -u CARGO cargo run --manifest-path "${COOKBOOK_SOURCE}/tools/Cargo.toml" --bin redox-initfs-ar -- "${COOKBOOK_BUILD}/initfs" "${COOKBOOK_SYSROOT}/boot/bootstrap" -o "${COOKBOOK_BUILD}/initfs.img"

mkdir -v "${COOKBOOK_STAGE}/boot"
cp "${COOKBOOK_BUILD}/initfs.img" "${COOKBOOK_STAGE}/boot/initfs"
"""
