#!/bin/sh
# Remove the wireBender layout and the installed node firmware. A locally
# modified layout is left in place.
set -e

LAYOUT_DIR="$HOME/project/project-content/layouts"
FIRMWARE_DIR="$HOME/project/project-content/firmware"
TARGET="$LAYOUT_DIR/wireBender.json"

if [ -f "$TARGET" ]; then
  if cmp -s "$PWD/wireBender.json" "$TARGET"; then
    rm "$TARGET"
    echo "removed: $TARGET"
  else
    echo "kept: $TARGET (locally modified)"
  fi
fi

for fw in "$PWD"/firmware/*.uf2; do
  [ -f "$fw" ] || continue
  name="$(basename "$fw")"
  [ -f "$FIRMWARE_DIR/$name" ] && rm "$FIRMWARE_DIR/$name" && echo "removed: $FIRMWARE_DIR/$name"
done
