main
Colby Knox Publish 1.1.0 7bc6a96 4d ago
#!/usr/bin/env bash
# Install hook for board-to-molecule. adom-wiki `pkg install` does not pull
# release assets, so this downloads the version-pinned Linux binary from the
# page's release, then installs the skill and the kicad-to-molecule shim.
set -euo pipefail
cd "$(dirname "$0")"

VER="$(grep -o '"version"[^,]*' package.json | grep -o '[0-9][0-9.]*' | head -1)"
BIN_DIR="${HOME}/.local/bin"
mkdir -p "$BIN_DIR"
URL="https://wiki.adom.inc/download/adom/board-to-molecule/${VER}/board-to-molecule"
TMP="$(mktemp)"
if curl -fsSL "$URL" -o "$TMP"; then
  install -m 0755 "$TMP" "$BIN_DIR/board-to-molecule"
  echo "OK: installed board-to-molecule ${VER} -> $BIN_DIR/board-to-molecule"
elif command -v cargo >/dev/null 2>&1; then
  echo "WARN: release download failed; building from source with cargo" >&2
  cargo build --release
  BUILT="target/release/board-to-molecule"
  [ -e "$BUILT" ] || { echo "ERROR: cargo build did not produce $BUILT" >&2; exit 1; }
  install -m 0755 "$BUILT" "$BIN_DIR/board-to-molecule"
else
  echo "ERROR: could not download the binary and cargo is not available" >&2
  exit 1
fi
rm -f "$TMP"
install -m 0755 bin/kicad-to-molecule "$BIN_DIR/kicad-to-molecule"
"$BIN_DIR/board-to-molecule" install
case ":$PATH:" in *":$BIN_DIR:"*) ;; *) echo "Hint: add $BIN_DIR to PATH" ;; esac