#!/bin/sh
LPKGDIR="$1"
CONFIG_DIR="$LPKGDIR/app/config"

hw_copy_file() {
	echo "LNX_TARGET_DEV:$1"
	rsync -a --exclude='hw_cfg' ../config "$LPKGDIR/app"
    case "$1" in
    iMX6ULL)
        cp -r -v -f ../config/hw_cfg/imx6ull/* "$CONFIG_DIR"
        mv -v -f "$CONFIG_DIR/emsd_notaosd.service" "$LPKGDIR/platspec/emsd.service"
        ;;
    BAU-B30-003)
        cp -r -v -f ../config/hw_cfg/bau3.0/* "$CONFIG_DIR"
        ;;
    RK3568)
        ;;
    ECU1170)
        cp -r -v -f ../config/hw_cfg/ecu1170/* "$CONFIG_DIR"
        ;;
    *) ;;
    esac
}

mkdir -p "${LPKGDIR}/app/upstart" "${LPKGDIR}/app/eventinfo" "${LPKGDIR}/app/cert" "${LPKGDIR}/app/template" "${LPKGDIR}/app/config"
cp -v -P -f ../docs/event/*.json ../docs/abnormal_log/*.json "${LPKGDIR}/app/eventinfo" && \
	cp -f ../cert/* "${LPKGDIR}/app/cert" && \
	rsync -a --exclude='.git' --exclude='.gitlab-ci.yml' ../template "${LPKGDIR}/app" && \
	hw_copy_file $LNX_TARGET_DEV
[ $? -ne 0 ] && exit 1

cp -v -f ipkg-skeleton/CONTROL/postinst "${LPKGDIR}/app/upstart/$(printf "%03d" ${FTPIDX})-ems-ng.sh"
exit $?
