#!/bin/sh
# lan7800-programmer install — put the CLI + webapp launcher on PATH.
# The CLI (cli/lan7800prog) needs its cli/lan7800/ package dir alongside it and
# the webapp finds the CLI relatively, so we install wrappers that point back
# into this module dir rather than copying files out of it.
set -e
SRC="$(cd "$(dirname "$0")" && pwd)"

pick_bindir() {
  if [ -w /usr/local/bin ]; then
    echo /usr/local/bin
  else
    mkdir -p "$HOME/.local/bin"
    echo "$HOME/.local/bin"
  fi
}
BIN="$(pick_bindir)"

# lan7800prog — the CLI
cat > "$BIN/lan7800prog" <<EOF
#!/bin/sh
exec python3 "$SRC/cli/lan7800prog" "\$@"
EOF
chmod +x "$BIN/lan7800prog"
echo "installed lan7800prog -> $BIN/lan7800prog"

# lan7800-programmer — the Hydrogen webapp (default port 8747, override with PORT)
cat > "$BIN/lan7800-programmer" <<EOF
#!/bin/sh
exec python3 "$SRC/webapp/server.py" "\$@"
EOF
chmod +x "$BIN/lan7800-programmer"
echo "installed lan7800-programmer -> $BIN/lan7800-programmer"

case ":$PATH:" in
  *":$BIN:"*) : ;;
  *) echo "note: add $BIN to your PATH" ;;
esac

# place the user skill where Claude Code discovers it
if [ -f "$SRC/SKILL.md" ]; then
  mkdir -p "$HOME/.claude/skills/lan7800-programmer"
  cp "$SRC/SKILL.md" "$HOME/.claude/skills/lan7800-programmer/SKILL.md"
  echo "installed skill -> $HOME/.claude/skills/lan7800-programmer/SKILL.md"
fi

echo "run: lan7800prog scan   (or)   lan7800-programmer   for the webapp"
