#!/bin/bash
set -x
DIR=`pwd`
# Go to the directory that you have downloaded all of the above files into... then:
mkdir ./archive
mv RTK* ./archive
mv nodejs_patches*gz ./archive
mv meta-ei.zip ./archive
cd ./archive
tar xzpf ./nodejs_patches_for_EdgeImpulse_20240805.tar.gz
cd $DIR
unzip ./archive/RTK0EF0180F05000SJ_linux-src.zip
unzip ./archive/meta-ei.zip
tar xzpf ./rzv2h_ai-sdk_yocto_recipe_v4.00.tar.gz
mv ./meta-rz-features $DIR
cd $DIR
repo init -u https://github.com/imd-tec/imdt-renesas-manifest.git -b imdt-linux-dunfell -m imdt-v2h-bsp-v2.0.0.xml
repo sync
export TEMPLATECONF=${DIR}/sources/meta-imdt-renesas/docs/template/conf/
export MACHINE='imdt-v2h-sbc'
cd $DIR
source sources/poky/oe-init-build-env
bitbake-layers add-layer ../sources/meta-openembedded/meta-filesystems
bitbake-layers add-layer ../sources/meta-openembedded/meta-networking
bitbake-layers add-layer ../sources/meta-virtualization
bitbake-layers add-layer ../meta-rz-features/meta-rz-graphics
bitbake-layers add-layer ../meta-rz-features/meta-rz-codecs
bitbake-layers add-layer ../meta-ei
cd $DIR
cp archive/0002_add_TRUE_FALSE_to_libical-3.0.7_icalrecur.h.patch $DIR/sources/poky/meta/recipes-support/libical/libical
cp archive/libical*bb $DIR/sources/poky/meta/recipes-support/libical/
cd $DIR/sources/poky/meta/recipes-support
rm -rf icu 2>&1 1> /dev/null
cp -r $DIR/archive/icu_70.1 icu
cd $DIR/sources/meta-openembedded/meta-oe/recipes-devtools
rm -rf nodejs 2>&1 1> /dev/null
cp -r $DIR/archive/nodejs_18.17.1 nodejs
cp $DIR/archive/packagegroup-qt5.bb ./meta-renesas/meta-rz-common/dynamic-layers/qt5-layer/packagegroups/
cd $DIR/build
echo "" >> ./conf/local.conf
echo "IMAGE_INSTALL_append = \" \\" >> ./conf/local.conf
echo " nodejs \\" >> ./conf/local.conf
echo " nodejs-npm \\" >> ./conf/local.conf
echo " e2fsprogs-resize2fs \\" >> ./conf/local.conf
echo " \"" >> ./conf/local.conf
echo "" >> ./conf/local.conf
echo "" >> ./conf/local.conf
echo "IMAGE_INSTALL_append = \" \\" >> ./conf/local.conf
echo " nvme-cli \\" >> ./conf/local.conf
echo " sudo \\" >> ./conf/local.conf
echo " curl \\" >> ./conf/local.conf
echo " zlib \\" >> ./conf/local.conf
echo " drpaitvm \\" >> ./conf/local.conf
echo " binutils \\" >> ./conf/local.conf
echo " \"" >> ./conf/local.conf
echo "" >> ./conf/local.conf
echo "WHITELIST_GPL-3.0 += \" cpp gcc gcc-dev mpfr g++ cpp make make-dev binutils libbfd \"" >> ./conf/local.conf
echo "IMAGE_INSTALL_append = \" zlib gcc g++ make cpp packagegroup-core-buildessential e2fsprogs-mke2fs \"" >> ./conf/local.conf
echo "IMAGE_INSTALL_append = \" python3 python3-pip python3-core python3-modules \"" >> ./conf/local.conf
echo "IMAGE_INSTALL_append = \" gstreamer1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good \"" >> ./conf/local.conf
echo "IMAGE_INSTALL_append = \" gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly \"" >> ./conf/local.conf
echo "EXTRA_IMAGE_FEATURES ?= \" debug-tweaks dev-pkgs tools-debug tools-sdk \"" >> ./conf/local.conf
echo "DISTRO_FEATURES ?= \" virtualization usbgadget usbhost wifi opengl systemd \"" >> ./conf/local.conf
echo "IMAGE_ROOTFS_EXTRA_SPACE_append_qemuall = \" + 6000000\"" >> ./conf/local.conf
#-# glibc2.31 instead of glibc2.28
sed -i 's/^CIP_MODE = "Buster"/CIP_MODE = "Bullseye"/g' ./conf/local.conf