-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
Β·282 lines (232 loc) Β· 7.26 KB
/
install.sh
File metadata and controls
executable file
Β·282 lines (232 loc) Β· 7.26 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/bash
set -euo pipefail
# Whasapo installer β macOS and Linux
# Usage:
# curl -sSL https://raw.githubusercontent.com/toloco/whasapo/main/install.sh | bash
# ./install.sh (local install)
# ./install.sh --uninstall (remove whasapo)
REPO="toloco/whasapo"
INSTALL_DIR="$HOME/.whasapo"
BINARY="$INSTALL_DIR/whasapo"
# Detect OS and architecture
OS="$(uname -s)"
ARCH="$(uname -m)"
case "$OS" in
Darwin) PLATFORM="macos" ;;
Linux) PLATFORM="linux" ;;
*) echo "Error: Unsupported OS: $OS. Use install.ps1 for Windows." >&2; exit 1 ;;
esac
case "$ARCH" in
x86_64|amd64) ARCH="amd64" ;;
arm64|aarch64) ARCH="arm64" ;;
*) echo "Error: Unsupported architecture: $ARCH" >&2; exit 1 ;;
esac
# Claude Desktop config path
case "$OS" in
Darwin) CONFIG_FILE="$HOME/Library/Application Support/Claude/claude_desktop_config.json" ;;
Linux)
CONFIG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}"
CONFIG_FILE="$CONFIG_DIR/Claude/claude_desktop_config.json"
;;
esac
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BOLD='\033[1m'
NC='\033[0m'
info() { echo -e "${BOLD}$*${NC}"; }
ok() { echo -e "${GREEN}$*${NC}"; }
warn() { echo -e "${YELLOW}$*${NC}"; }
error() { echo -e "${RED}Error: $*${NC}" >&2; }
# --- Uninstall ---
if [ "${1:-}" = "--uninstall" ]; then
info "=== Uninstalling Whasapo ==="
echo ""
# Remove symlinks
for dir in /usr/local/bin "$HOME/.local/bin"; do
if [ -L "$dir/whasapo" ]; then
rm -f "$dir/whasapo"
echo "Removed $dir/whasapo"
fi
done
if [ -d "$INSTALL_DIR" ]; then
if [ -f "$INSTALL_DIR/session.db" ]; then
warn "Backing up session to $HOME/.whasapo.session.db.bak"
cp "$INSTALL_DIR/session.db" "$HOME/.whasapo.session.db.bak"
fi
rm -rf "$INSTALL_DIR"
ok "Removed $INSTALL_DIR"
fi
if [ -f "$CONFIG_FILE" ]; then
python3 -c "
import json, sys
try:
with open('$CONFIG_FILE', 'r') as f:
config = json.load(f)
if 'mcpServers' in config and 'whatsapp' in config['mcpServers']:
del config['mcpServers']['whatsapp']
with open('$CONFIG_FILE', 'w') as f:
json.dump(config, f, indent=2)
print('Removed WhatsApp from Claude config.')
else:
print('WhatsApp not found in Claude config (already clean).')
except Exception as e:
print(f'Warning: Could not update Claude config: {e}', file=sys.stderr)
"
fi
echo ""
ok "Uninstalled. Restart Claude desktop for changes to take effect."
exit 0
fi
# --- Install ---
echo ""
info "π± Whasapo Installer"
info " WhatsApp integration for Claude"
echo " Platform: $PLATFORM ($ARCH)"
echo ""
# Create install directory
mkdir -p "$INSTALL_DIR"
# Cleanup on failure
cleanup() {
if [ "${INSTALL_COMPLETE:-}" != "1" ]; then
error "Installation failed. Cleaning up..."
rm -f "$BINARY"
fi
}
trap cleanup EXIT
# --- Download or copy binary ---
# When piped from curl, always download from GitHub.
IS_PIPED=0
if [ ! -t 0 ] && [ -z "${BASH_SOURCE[0]:-}" ]; then
IS_PIPED=1
fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd || echo "")"
LOCAL_BIN=""
if [ "$IS_PIPED" = "0" ]; then
for dir in "$SCRIPT_DIR" "$SCRIPT_DIR/bin" "$SCRIPT_DIR/dist"; do
if [ -f "$dir/whasapo" ] 2>/dev/null; then
LOCAL_BIN="$dir/whasapo"
break
fi
done
fi
if [ -n "$LOCAL_BIN" ]; then
info "π¦ Installing from local binary..."
cat "$LOCAL_BIN" > "$BINARY"
else
info "β¬οΈ Downloading latest release..."
# Determine asset pattern based on platform
if [ "$PLATFORM" = "macos" ]; then
ASSET_PATTERN="macos"
else
ASSET_PATTERN="linux-${ARCH}"
fi
DOWNLOAD_URL=$(curl -sSL "https://api.github.com/repos/$REPO/releases/latest" \
| grep '"browser_download_url"' \
| grep "$ASSET_PATTERN" \
| head -1 \
| cut -d '"' -f 4) || true
if [ -z "$DOWNLOAD_URL" ]; then
error "Could not find a $PLATFORM-$ARCH release."
error "Check https://github.com/$REPO/releases"
exit 1
fi
TEMP_DIR=$(mktemp -d)
echo " Downloading from: $DOWNLOAD_URL"
curl -sSL "$DOWNLOAD_URL" -o "$TEMP_DIR/whasapo-archive"
echo " Extracting..."
if echo "$DOWNLOAD_URL" | grep -q '\.zip$'; then
unzip -qo "$TEMP_DIR/whasapo-archive" -d "$TEMP_DIR"
else
tar xzf "$TEMP_DIR/whasapo-archive" -C "$TEMP_DIR"
fi
if [ -f "$TEMP_DIR/whasapo" ]; then
cat "$TEMP_DIR/whasapo" > "$BINARY"
else
error "Archive doesn't contain whasapo binary."
rm -rf "$TEMP_DIR"
exit 1
fi
rm -rf "$TEMP_DIR"
fi
chmod +x "$BINARY"
# macOS: sign binary and remove quarantine to prevent "killed" errors
if [ "$OS" = "Darwin" ]; then
codesign -s - -f "$BINARY" 2>/dev/null || true
xattr -d com.apple.quarantine "$BINARY" 2>/dev/null || true
fi
ok "β
Binary installed to $BINARY"
# Add to PATH via symlink
LINK_DIR="/usr/local/bin"
if [ -d "$LINK_DIR" ] && [ -w "$LINK_DIR" ]; then
ln -sf "$BINARY" "$LINK_DIR/whasapo"
echo " Linked to $LINK_DIR/whasapo"
else
LINK_DIR="$HOME/.local/bin"
mkdir -p "$LINK_DIR"
ln -sf "$BINARY" "$LINK_DIR/whasapo"
echo " Linked to $LINK_DIR/whasapo"
if ! echo "$PATH" | tr ':' '\n' | grep -q "$LINK_DIR"; then
warn " Add this to your shell profile: export PATH=\"$LINK_DIR:\$PATH\""
fi
fi
echo ""
# --- Configure Claude desktop ---
info "βοΈ Configuring Claude desktop app..."
CONFIG_DIR_PATH="$(dirname "$CONFIG_FILE")"
mkdir -p "$CONFIG_DIR_PATH"
if [ -f "$CONFIG_FILE" ]; then
cp "$CONFIG_FILE" "$CONFIG_FILE.backup"
echo " Backed up config to claude_desktop_config.json.backup"
fi
python3 -c "
import json, os, sys
config_file = '$CONFIG_FILE'
binary = '$BINARY'
if os.path.exists(config_file):
with open(config_file, 'r') as f:
try:
config = json.load(f)
except json.JSONDecodeError:
config = {}
else:
config = {}
if 'mcpServers' not in config:
config['mcpServers'] = {}
config['mcpServers']['whatsapp'] = {
'command': binary,
'args': ['serve']
}
with open(config_file, 'w') as f:
json.dump(config, f, indent=2)
print(' Added whatsapp MCP server to Claude config.')
" || {
error "Failed to update Claude config. You can add it manually:"
echo ""
echo " Edit: $CONFIG_FILE"
echo ' Add to mcpServers: "whatsapp": {"command": "'$BINARY'", "args": ["serve"]}'
echo ""
}
ok "β
Claude desktop configured"
echo ""
# --- Pair with WhatsApp ---
# Pair always runs β it tests the connection and re-pairs if needed
"$BINARY" pair
INSTALL_COMPLETE=1
echo ""
echo ""
ok "π ========================================="
ok " Whasapo installed successfully!"
ok " ========================================="
echo ""
echo " Restart the Claude desktop app, then try asking:"
echo ""
echo " π¬ \"Show me my recent WhatsApp messages\""
echo " π€ \"Send a WhatsApp message to Mom saying hi\""
echo ""
echo " Commands:"
echo " whasapo status Check connection"
echo " whasapo pair Re-link WhatsApp"
echo " whasapo update Update to latest version"
echo " whasapo --help All commands"
echo ""