#!/usr/bin/env bash set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" cd "$ROOT" case "$(uname -s)" in Linux) ;; *) echo "wrong platform: $(uname -s) — use cargo xtask install" >&2; exit 1;; esac bash "$ROOT/scripts/linux/build.sh" STAGE="$ROOT/build/bin/com.jesshunter.layers" PLUGIN_ID="com.jesshunter.layers" # Drop into every existing KiCad >=10 install we can find — native and flatpak, # every version dir KiCad has already created. We never mkdir kicad//plugins; # KiCad creates it on first launch and we only fill in our own subdir. install_to_kicad_root() { local kicad_root="$1" [ -d "$kicad_root" ] || return 1 local installed=0 for ver_dir in "$kicad_root"/*/; do local ver ver="$(basename "$ver_dir")" [[ "$ver" =~ ^([0-9]+)\.0$ ]] || continue (( ${BASH_REMATCH[1]} >= 10 )) || continue local plugins_dir="${ver_dir}plugins" [ -d "$plugins_dir" ] || continue local target="$plugins_dir/$PLUGIN_ID" rm -rf "$target/bin" "$target/resources" "$target/plugin.json" "$target/LICENCE" mkdir -p "$target/bin" "$target/resources" cp -R "$STAGE/bin/." "$target/bin/" [ -f "$STAGE/plugin.json" ] && cp "$STAGE/plugin.json" "$target/plugin.json" [ -f "$STAGE/LICENCE" ] && cp "$STAGE/LICENCE" "$target/LICENCE" cp -R "$STAGE/resources/." "$target/resources/" echo "installed: $target" installed=1 done return $((1 - installed)) } NATIVE_ROOT="${XDG_DATA_HOME:-$HOME/.local/share}/kicad" FLATPAK_ROOT="$HOME/.var/app/org.kicad.KiCad/data/kicad" ok=0 install_to_kicad_root "$NATIVE_ROOT" && ok=1 || true install_to_kicad_root "$FLATPAK_ROOT" && ok=1 || true if [ "$ok" -eq 0 ]; then echo "no KiCad 10+ install detected. checked:" >&2 echo " $NATIVE_ROOT//plugins/" >&2 echo " $FLATPAK_ROOT//plugins/" >&2 echo "launch KiCad once first so it creates its data dirs, then re-run." >&2 exit 1 fi