-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.sh
More file actions
executable file
·145 lines (113 loc) · 4.08 KB
/
Copy pathupdate.sh
File metadata and controls
executable file
·145 lines (113 loc) · 4.08 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
#!/bin/bash
set -euo pipefail
# Update credential-proxy: pull latest, rebuild MCP relay, replace binary.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
APP_NAME="Credential Proxy.app"
APP_PATH="/Applications/$APP_NAME"
MCP_RELAY_DIR="$APP_PATH/Contents/Resources/mcp-relay"
APP_PORT=11111
RED='\033[0;31m'
GREEN='\033[0;32m'
DIM='\033[2m'
RESET='\033[0m'
info() { echo -e "${DIM}$1${RESET}"; }
success() { echo -e "${GREEN}✓ $1${RESET}"; }
error() { echo -e "${RED}✗ $1${RESET}"; exit 1; }
# Register credential-proxy MCP server in a JSON config file.
# Usage: register_mcp <config_path> <relay_index_path> [extra_fields_json]
register_mcp() {
local config_path="$1"
local relay_index="$2"
local extra="${3:-"{}"}"
node - "$config_path" "$relay_index" "$APP_PORT" "$extra" <<'REGISTER_SCRIPT'
const fs = require('fs');
const path = require('path');
const [,, configPath, relayIndex, portStr, extraJson] = process.argv;
const port = parseInt(portStr, 10);
const extra = JSON.parse(extraJson);
fs.mkdirSync(path.dirname(configPath), { recursive: true });
let config = {};
try { config = JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch {}
const key = config['mcp-servers'] && !config.mcpServers ? 'mcp-servers' : 'mcpServers';
if (!config[key]) config[key] = {};
const entry = {
...config[key]['credential-proxy'],
command: 'node',
args: [relayIndex],
env: { CREDENTIAL_PROXY_APP_URL: 'http://127.0.0.1:' + port },
...extra,
};
config[key]['credential-proxy'] = entry;
fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n');
REGISTER_SCRIPT
}
# --- Preflight ---
if [ ! -d "$APP_PATH" ]; then
error "App not found at $APP_PATH. Run install.sh first."
fi
echo ""
echo "Updating Credential Proxy..."
echo ""
# --- Stop all instances ---
info "Stopping app..."
pkill -x CredentialProxy 2>/dev/null || true
sleep 1
# --- Pull latest ---
cd "$SCRIPT_DIR"
info "Pulling latest changes..."
git pull
success "Pulled latest"
# --- Build MCP relay ---
info "Building MCP relay..."
npm run build --silent 2>/dev/null
success "MCP relay built"
# --- Build Swift binary from source ---
info "Building Swift binary..."
cd "$SCRIPT_DIR/macos"
if swift build -c release 2>&1 | tail -1; then
BUILT_BIN="$SCRIPT_DIR/macos/.build/release/CredentialProxy"
/bin/cp -f "$BUILT_BIN" "$APP_PATH/Contents/MacOS/CredentialProxy"
codesign -s - -f "$APP_PATH/Contents/MacOS/CredentialProxy" 2>/dev/null
# Also update the pre-built binary for install.sh
/bin/cp -f "$BUILT_BIN" "$SCRIPT_DIR/macos/bin/CredentialProxy" 2>/dev/null || true
success "Binary built and updated"
else
# Fall back to pre-built binary if Swift build fails (e.g. no Xcode)
PREBUILT_BIN="$SCRIPT_DIR/macos/bin/CredentialProxy"
if [ -f "$PREBUILT_BIN" ]; then
/bin/cp -f "$PREBUILT_BIN" "$APP_PATH/Contents/MacOS/CredentialProxy"
codesign -s - -f "$APP_PATH/Contents/MacOS/CredentialProxy" 2>/dev/null
echo -e "${DIM}Swift build failed — used pre-built binary instead${RESET}"
success "Binary updated (pre-built fallback)"
else
error "Swift build failed and no pre-built binary found at $PREBUILT_BIN"
fi
fi
cd "$SCRIPT_DIR"
# --- Update MCP relay ---
rm -rf "$MCP_RELAY_DIR"
mkdir -p "$MCP_RELAY_DIR"
cp -R "$SCRIPT_DIR/dist/"* "$MCP_RELAY_DIR/"
cp "$SCRIPT_DIR/package.json" "$MCP_RELAY_DIR/"
if [ -f "$SCRIPT_DIR/package-lock.json" ]; then
cp "$SCRIPT_DIR/package-lock.json" "$MCP_RELAY_DIR/"
fi
cd "$MCP_RELAY_DIR"
npm ci --omit=dev --silent 2>/dev/null
cd "$SCRIPT_DIR"
success "MCP relay updated"
# --- Fix MCP configs ---
RELAY_INDEX="$MCP_RELAY_DIR/index.js"
register_mcp "$HOME/.claude.json" "$RELAY_INDEX"
PI_MCP="$HOME/.pi/agent/mcp.json"
if [ -d "$HOME/.pi/agent" ] || [ -f "$PI_MCP" ]; then
register_mcp "$PI_MCP" "$RELAY_INDEX" '{"lifecycle":"keep-alive","directTools":true}'
fi
success "MCP configs updated"
# --- Relaunch ---
info "Launching app..."
open "$APP_PATH"
success "App running"
echo ""
echo -e "${GREEN}Update complete!${RESET}"
echo -e "${DIM}Enter your PIN to unlock. Restart Claude Code to pick up changes.${RESET}"