summaryrefslogtreecommitdiff
path: root/scripts/setup.sh
blob: 9c64c4ce02e8173e6c42fdbd4f71c9c83f3bf200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# Build Rust icloud-note, ensure Chromium, install to ~/.local/bin, link agent skill.
set -euo pipefail

REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
CONFIG_DIR="${ICLOUD_NOTES_CONFIG:-$HOME/.config/icloud-notes}"
BIN_DIR="$HOME/.local/bin"
BIN="$BIN_DIR/icloud-note"
AGENTS_SKILL="$HOME/.agents/skills/iphone-icloud-notes"
CURSOR_SKILL="$HOME/.cursor/skills/iphone-icloud-notes"

mkdir -p "$CONFIG_DIR" "$BIN_DIR" "$HOME/.agents/skills" "$HOME/.cursor/skills"
chmod 700 "$CONFIG_DIR"

# Prefer existing Playwright Chromium; otherwise install via npx playwright
if [[ -z "${ICLOUD_NOTES_CHROME:-}" ]]; then
  if compgen -G "$HOME/.cache/ms-playwright/chromium-*/chrome-linux64/chrome" > /dev/null; then
    CHROME="$(ls -1 "$HOME/.cache/ms-playwright"/chromium-*/chrome-linux64/chrome | head -1)"
    echo "ok: using Playwright Chromium at $CHROME"
  elif command -v npm >/dev/null 2>&1; then
    echo "Installing Playwright Chromium for automation…"
    mkdir -p "$CONFIG_DIR"
    cd "$CONFIG_DIR"
    if [[ ! -f package.json ]]; then
      npm init -y >/dev/null
    fi
    npm install playwright@latest
    npx playwright install chromium
  else
    echo "warn: no Chromium found and npm unavailable; install Chromium or set ICLOUD_NOTES_CHROME" >&2
  fi
fi

cd "$REPO_ROOT"
cargo build --release
install -m 755 "$REPO_ROOT/target/release/icloud-note" "$BIN"

ln -sfn "$REPO_ROOT" "$AGENTS_SKILL"
ln -sfn "$REPO_ROOT" "$CURSOR_SKILL"

echo "ok: installed $BIN"
echo "ok: skill linked -> $REPO_ROOT"
echo "Next: icloud-note login"