#!/bin/sh
# ============================================================================
# KiBot Template Bootstrapping Script
# ============================================================================

# Create the Development Branch
git checkout -b dev
echo "Created Development Branch"

# Add the Asymworks KiCad Library
git remote add -f asymworks-kicad-lib https://git.asymworks.com/asymworks/kicad-library
git subtree add --prefix lib/asymworks asymworks-kicad-lib main --squash -m "[bootstrap] Add subtree 'Asymworks/KiCad-Library' at 'lib/asymworks'"
echo "Added Asymworks KiCad Library"

# Rename the KiCad Project based on the directory name
PROJ_NAME=$(basename "$PWD")
git mv Asymworks_Template.kicad_pro "${PROJ_NAME}.kicad_pro"
git mv Asymworks_Template.kicad_sch "${PROJ_NAME}.kicad_sch"
git mv Asymworks_Template.kicad_pcb "${PROJ_NAME}.kicad_pcb"
git commit -a -m 'Rename Project'
echo "Renamed project to \"${PROJ_NAME}.kicad_pro\""

# Push the Develpment Branch to Gitea
git push -u origin dev

# Bootstrap Complete
echo "Bootstrap complete. Please run 'git pull' after the CI action finishes.'"
