-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·179 lines (157 loc) · 7.55 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·179 lines (157 loc) · 7.55 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
# macOS CLI installer
# Usage: curl -sSL https://raw.githubusercontent.com/manuaudio/macos-cli/main/install.sh | bash
# Or: git clone https://github.com/manuaudio/macos-cli && cd macos-cli && ./install.sh
set -e
REPO_URL="https://github.com/manuaudio/macos-cli.git"
INSTALL_DIR="/usr/local/bin"
BINARY_NAME="macos"
CLONE_DIR="/tmp/macos-cli-install"
echo ""
echo "macOS CLI installer"
echo "==================="
echo ""
# ── Check for Swift ──────────────────────────────────────────────────────────
if ! command -v swift &>/dev/null; then
echo "❌ Swift not found."
echo " Install Xcode Command Line Tools first:"
echo " xcode-select --install"
echo " Then re-run this script."
exit 1
fi
echo "✅ Swift $(swift --version 2>&1 | head -1 | awk '{print $3}')"
# ── Check install dir ────────────────────────────────────────────────────────
if [ ! -d "$INSTALL_DIR" ]; then
echo "Creating $INSTALL_DIR..."
sudo mkdir -p "$INSTALL_DIR"
fi
# ── Clone or use existing repo ───────────────────────────────────────────────
if [ -f "Package.swift" ] && [ -d "Sources" ]; then
REPO_DIR="$(pwd)"
echo "✅ Using local repo: $REPO_DIR"
else
echo "📦 Cloning macos-cli..."
rm -rf "$CLONE_DIR"
git clone --depth 1 "$REPO_URL" "$CLONE_DIR" 2>&1 | tail -1
REPO_DIR="$CLONE_DIR"
fi
# ── Build ────────────────────────────────────────────────────────────────────
echo "🔨 Building (this takes ~30s)..."
cd "$REPO_DIR"
echo "Building macos binary..."
if ! swift build -c release 2>&1 | tee /tmp/macos-build.log | grep -q "Build complete"; then
echo "Build failed. Full output:"
cat /tmp/macos-build.log
exit 1
fi
BUILT_BINARY=$(find .build -path '*/release/macos-cli' -type f -not -path '*dSYM*' -not -path '*checkouts*' 2>/dev/null | head -1)
if [ -z "$BUILT_BINARY" ]; then
echo "❌ Build failed — binary not found"
exit 1
fi
# ── Install ──────────────────────────────────────────────────────────────────
echo "📋 Installing to $INSTALL_DIR/$BINARY_NAME..."
if cp "$BUILT_BINARY" "$INSTALL_DIR/$BINARY_NAME" 2>/dev/null; then
chmod +x "$INSTALL_DIR/$BINARY_NAME"
else
sudo cp "$BUILT_BINARY" "$INSTALL_DIR/$BINARY_NAME"
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME"
fi
echo "✅ Installed: $($INSTALL_DIR/$BINARY_NAME --version)"
echo ""
# ── Setup ────────────────────────────────────────────────────────────────────
echo ""
echo "✓ macos installed. Setting up permissions..."
echo ""
"$INSTALL_DIR/$BINARY_NAME" auth setup --all --yes 2>/dev/null || true
echo ""
echo "Run 'macos auth setup' to customize permissions interactively."
echo "Run 'macos setup' to verify everything works."
# ── Optional: install MCP + HTTP bridge ──────────────────────────────────────
# These let local LLM stacks (Claude Desktop / Code via MCP, Ollama / LM Studio
# / Open WebUI via HTTP) drive the same tools. Skipped if bun is not installed.
install_wrapper_layer() {
if ! command -v bun &>/dev/null; then
echo ""
echo "ℹ️ Skipping MCP + bridge install — bun not found."
echo " To enable later: brew install oven-sh/bun/bun, then re-run install.sh."
return 0
fi
BUN_MAJOR=$(bun --version 2>/dev/null | cut -d. -f1)
if [ -z "$BUN_MAJOR" ] || [ "$BUN_MAJOR" -lt 1 ]; then
echo "ℹ️ Bun 1.0+ required for MCP server build. Run: brew install oven-sh/bun/bun"
return 0
fi
echo ""
echo "🔌 Building MCP server + HTTP bridge..."
local ARCH
ARCH="$(uname -m)"
local BUILD_SCRIPT="build"
if [ "$ARCH" = "arm64" ]; then BUILD_SCRIPT="build:arm"; fi
# Always re-copy canonical tools.json into both wrappers
if [ -f "$REPO_DIR/tool-definitions/tools.json" ]; then
cp "$REPO_DIR/tool-definitions/tools.json" "$REPO_DIR/macos-mcp/tools.json"
cp "$REPO_DIR/tool-definitions/tools.json" "$REPO_DIR/macos-bridge/tools.json"
fi
# macos-mcp
if [ -d "$REPO_DIR/macos-mcp" ]; then
(cd "$REPO_DIR/macos-mcp" && bun install --silent >/dev/null && bun run "$BUILD_SCRIPT" 2>&1 | tail -3)
if [ -f "$REPO_DIR/macos-mcp/macos-mcp" ]; then
if cp "$REPO_DIR/macos-mcp/macos-mcp" "$INSTALL_DIR/macos-mcp" 2>/dev/null; then
chmod +x "$INSTALL_DIR/macos-mcp"
else
sudo cp "$REPO_DIR/macos-mcp/macos-mcp" "$INSTALL_DIR/macos-mcp"
sudo chmod +x "$INSTALL_DIR/macos-mcp"
fi
echo "✅ Installed: $INSTALL_DIR/macos-mcp"
else
echo "⚠️ macos-mcp build did not produce a binary — skipping install"
fi
fi
# macos-bridge
if [ -d "$REPO_DIR/macos-bridge" ]; then
(cd "$REPO_DIR/macos-bridge" && bun install --silent >/dev/null && bun run "$BUILD_SCRIPT" 2>&1 | tail -3)
if [ -f "$REPO_DIR/macos-bridge/macos-bridge" ]; then
if cp "$REPO_DIR/macos-bridge/macos-bridge" "$INSTALL_DIR/macos-bridge" 2>/dev/null; then
chmod +x "$INSTALL_DIR/macos-bridge"
else
sudo cp "$REPO_DIR/macos-bridge/macos-bridge" "$INSTALL_DIR/macos-bridge"
sudo chmod +x "$INSTALL_DIR/macos-bridge"
fi
echo "✅ Installed: $INSTALL_DIR/macos-bridge"
# Offer to enable the LaunchAgent (user-level, no sudo)
local PLIST_SRC="$REPO_DIR/macos-bridge/com.macos-cli.bridge.plist"
local PLIST_DST="$HOME/Library/LaunchAgents/com.macos-cli.bridge.plist"
if [ -f "$PLIST_SRC" ]; then
if [ -t 0 ]; then
read -r -p "Start macos-bridge automatically on login? [y/N] " ans
else
ans="n"
fi
if [[ "$ans" =~ ^[Yy] ]]; then
mkdir -p "$HOME/Library/LaunchAgents"
cp "$PLIST_SRC" "$PLIST_DST"
launchctl unload "$PLIST_DST" 2>/dev/null || true
launchctl load "$PLIST_DST"
echo "✅ LaunchAgent loaded: com.macos-cli.bridge (port 2772)"
else
echo "ℹ️ Skipped LaunchAgent. Enable later with:"
echo " cp \"$PLIST_SRC\" ~/Library/LaunchAgents/"
echo " launchctl load ~/Library/LaunchAgents/com.macos-cli.bridge.plist"
fi
fi
else
echo "⚠️ macos-bridge build did not produce a binary — skipping install"
fi
fi
echo ""
echo "🎉 Wrapper layer installed."
echo ""
echo " Claude Desktop config snippet:"
echo ' { "mcpServers": { "macos": { "command": "/usr/local/bin/macos-mcp" } } }'
echo ""
echo " Local LLM HTTP endpoint:"
echo " http://localhost:2772/v1/tools"
echo ""
}
install_wrapper_layer