#!/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 STAGE="$ROOT/build/bin/com.jesshunter.layers" PLUGIN_ID="com.jesshunter.layers" # Installs into every existing KiCad >=10 plugins dir — native and flatpak. # Does not mkdir kicad//plugins; KiCad creates it on first launch. 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 # Native install: build with the front-end matching the host's WM (build.sh # autodetects unless LAYERS_FEATURES is set). if [ -d "$NATIVE_ROOT" ]; then bash "$ROOT/scripts/linux/build.sh" install_to_kicad_root "$NATIVE_ROOT" && ok=1 || true fi # Flatpak install: force the X11 front-end. if [ -d "$FLATPAK_ROOT" ]; then LAYERS_FEATURES=x11 bash "$ROOT/scripts/linux/build.sh" install_to_kicad_root "$FLATPAK_ROOT" && ok=1 || true fi 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