#!/usr/bin/env bash

set -e

response=y
test -f env-oe.sh && read -p "Overwrite env-oe.sh with defaults? (y/N) " response
if [[ $response =~ ^y$ || $response =~ ^yes$ ]]; then
	echo "Copying default environment script..."
	cp multitech/contrib/env-oe.sh .
else
	echo "Leaving existing env-oe.sh alone."
fi

echo ""
response=y
test -f conf/local.conf && read -p "Overwrite conf/local.conf with defaults? (y/N) " response
if [[ $response =~ ^y$ || $response =~ ^yes$ ]]; then
	echo "Creating default bitbake configuration..."
	cp multitech/contrib/local.conf conf/
else
	echo "Leaving existing conf/local.conf alone."
fi

echo ""
echo "Creating user-layer..."
mkdir -p user-layer/conf
mkdir -p user-layer/recipes

echo ""
response=y
test -f user-layer/conf/layer.conf && read -p "Overwrite user-layer/conf/layer.conf with defaults? (y/N) " response
if [[ $response =~ ^y$ || $response =~ ^yes$ ]]; then
	echo "Creating default user-layer configuration..."
	cp multitech/contrib/user-layer.conf user-layer/conf/layer.conf
else
	echo "Leaving existing user-layer/conf/layer.conf alone."
fi

echo ""
echo "Creating directory structure..."
mkdir -p sources
mkdir -p build

echo ""
echo "Updating git submodules..."
git submodule update --init

echo ""
echo "Setup Done."
echo ""
echo "To build corecdp-base-image:"
echo "   source env-oe.sh"
echo "   bitbake corecdp-base-image"