#!/bin/bash
echo -e "\nFully Rebuildan~\n"

echo -e "\nRunning fullclean\n"

idf.py fullclean

echo -e "\nRunning manual delete tasks:"

if [ -f build ]; then
	echo -e "\tDeleting build dir"
	rm -rf build
else
	echo -e "\tNo build dir, skipping delete"
fi

if [ -f sdkconfig ]; then
	echo -e "\tDeleting sdkconfig"
	rm sdkconfig
else
	echo -e "\tNo sdkconfig, skipping delete"
fi

if [ -f sdkconfig.old ]; then
	echo -e "\tDeleting sdkconfig.old"
	rm sdkconfig.old
else
	echo -e "\tNo sdkconfig.old, skipping delete"
fi

echo -e "\nSetting up project for $ESPTARGET\n"
idf.py set-target $ESPTARGET

echo -e "\nErase flash? y/n"
read wipe
if [ "$wipe" == "y" ]; then
	echo -e "\nExecuting erase-flash\n"
	idf.py erase-flash
	echo -e "\nFlash wiped\n"
fi

echo -e "\nRun menuconfig?\n"
read menuconfig
if [ "$wipe" == "y" ]; then
	echo -e "\n\Executing menuconfig"
	idf.py menuconfig
fi

echo -e "\nBuild now? y/n"
read build
if [ "$build" == "y" ]; then
	echo -e "\nBuildan~\n"
	idf.py build
	echo -e "\nBuild complete\n"
fi

echo -e "\nAll done :3\n"