-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·397 lines (346 loc) · 10.9 KB
/
setup.sh
File metadata and controls
executable file
·397 lines (346 loc) · 10.9 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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
#!/bin/bash
#
# Sift Setup Script
# Interactive setup for notification forwarder
#
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo ""
echo -e "${BLUE}【 SIFT 】${NC}"
echo -e "The Dumbphone Companion - Setup"
echo ""
# Helper function to prompt with default
prompt() {
local var_name=$1
local prompt_text=$2
local default=$3
local value
if [ -n "$default" ]; then
read -p "$prompt_text [$default]: " value
value="${value:-$default}"
else
read -p "$prompt_text: " value
fi
eval "$var_name=\"$value\""
}
# Helper for yes/no
prompt_yn() {
local var_name=$1
local prompt_text=$2
local default=$3
local value
while true; do
read -p "$prompt_text (y/n) [$default]: " value
value="${value:-$default}"
case "$value" in
[Yy]* ) eval "$var_name=true"; break;;
[Nn]* ) eval "$var_name=false"; break;;
* ) echo "Please answer y or n.";;
esac
done
}
echo -e "${YELLOW}Step 1: Basic Configuration${NC}"
echo ""
prompt DUMBPHONE_NUMBER "Your dumbphone number (e.g., +441234567890)" ""
prompt PI_HOST "Raspberry Pi SSH address (e.g., pi@192.168.1.100)" "pi@192.168.1.100"
echo ""
echo -e "${YELLOW}Step 2: Location Settings${NC}"
echo ""
prompt DEFAULT_LOCATION "Default location for weather (e.g., London,UK)" "London,UK"
prompt DEFAULT_LAT "Latitude" "51.5074"
prompt DEFAULT_LON "Longitude" "-0.1278"
prompt HOME_ADDRESS "Home address for NAV (leave blank to skip)" ""
echo ""
echo -e "${YELLOW}Step 3: AI Features${NC}"
echo ""
prompt_yn ENABLE_AI "Enable AI features (requires Ollama)?" "y"
if [ "$ENABLE_AI" = true ]; then
prompt OLLAMA_URL "Ollama URL" "http://localhost:11434"
prompt OLLAMA_MODEL "Ollama model" "qwen2.5:3b"
else
OLLAMA_URL="http://localhost:11434"
OLLAMA_MODEL="qwen2.5:3b"
fi
echo ""
echo -e "${YELLOW}Step 4: Notification Sinks${NC}"
echo ""
prompt_yn ENABLE_IMESSAGE "Enable iMessage/SMS forwarding?" "y"
if [ "$ENABLE_IMESSAGE" = true ]; then
IMESSAGE_RECIPIENT="$DUMBPHONE_NUMBER"
fi
prompt_yn ENABLE_BARK "Enable Bark (iOS push)?" "n"
if [ "$ENABLE_BARK" = true ]; then
prompt BARK_URL "Bark server URL" "http://192.168.1.100:8089"
prompt BARK_DEVICE_KEY "Bark device key" ""
fi
prompt_yn ENABLE_NTFY "Enable ntfy?" "n"
if [ "$ENABLE_NTFY" = true ]; then
prompt NTFY_URL "ntfy URL (e.g., https://ntfy.sh/your-topic)" ""
fi
echo ""
echo -e "${YELLOW}Step 5: Paths${NC}"
echo ""
prompt OBSIDIAN_TODO "Obsidian TODO file path" "$HOME/obsidian/_todo.md"
prompt CONTACTS_FILE "Contacts JSON file path" "$SCRIPT_DIR/contacts.json"
# Expand ~ in paths for plist (launchd doesn't expand ~)
OBSIDIAN_TODO_EXPANDED="${OBSIDIAN_TODO/#\~/$HOME}"
CONTACTS_FILE_EXPANDED="${CONTACTS_FILE/#\~/$HOME}"
echo ""
echo -e "${YELLOW}Generating configuration...${NC}"
echo ""
# Backup function - creates timestamped backups
backup_if_exists() {
local file="$1"
if [ -f "$file" ]; then
local backup_dir="$SCRIPT_DIR/backups"
mkdir -p "$backup_dir"
local timestamp=$(date +%Y%m%d_%H%M%S)
local filename=$(basename "$file")
local backup_path="$backup_dir/${filename}.${timestamp}"
cp "$file" "$backup_path"
echo -e "${BLUE}↳ Backed up ${filename} to backups/${filename}.${timestamp}${NC}"
fi
}
# Backup existing config files
backup_if_exists "$SCRIPT_DIR/processor/.env"
backup_if_exists "$SCRIPT_DIR/sms-assistant/.env"
backup_if_exists "$SCRIPT_DIR/imessage-gateway/.env"
# Create processor .env
cat > "$SCRIPT_DIR/processor/.env" << EOF
# Processor Configuration (generated by setup.sh)
PI_HEALTH_URL=http://${PI_HOST#*@}:8080/health
OLLAMA_URL=$OLLAMA_URL
EOF
# Create SMS Assistant .env
cat > "$SCRIPT_DIR/sms-assistant/.env" << EOF
# SMS Assistant Configuration (generated by setup.sh)
# Required: Your dumbphone number
DUMBPHONE_NUMBER=$DUMBPHONE_NUMBER
# Ollama LLM settings
OLLAMA_URL=$OLLAMA_URL
OLLAMA_MODEL=$OLLAMA_MODEL
# Pi SSH connection
PI_HOST=$PI_HOST
# Paths
OBSIDIAN_TODO=$OBSIDIAN_TODO
MESSAGES_DB=$HOME/Library/Messages/chat.db
STATE_FILE=$HOME/.sms-assistant/state.json
CONTACTS_FILE=$CONTACTS_FILE
DATA_FILE=$HOME/.sms-assistant/data.json
# Location settings
DEFAULT_LOCATION=$DEFAULT_LOCATION
DEFAULT_LAT=$DEFAULT_LAT
DEFAULT_LON=$DEFAULT_LON
HOME_ADDRESS=$HOME_ADDRESS
# Bark settings
BARK_URL=${BARK_URL:-http://192.168.1.100:8089}
BARK_DEVICE_KEY=${BARK_DEVICE_KEY:-}
# Polling interval
POLL_INTERVAL=10
EOF
# Create iMessage Gateway .env
cat > "$SCRIPT_DIR/imessage-gateway/.env" << EOF
# iMessage Gateway Configuration (generated by setup.sh)
DEFAULT_RECIPIENT=$DUMBPHONE_NUMBER
EOF
# Handle config.yaml specially - ask before overwriting
WRITE_CONFIG=true
if [ -f "$SCRIPT_DIR/config.yaml" ]; then
echo ""
echo -e "${YELLOW}config.yaml already exists with your notification rules.${NC}"
prompt_yn OVERWRITE_CONFIG "Overwrite it? (This will reset all your rules!)" "n"
if [ "$OVERWRITE_CONFIG" = false ]; then
WRITE_CONFIG=false
echo -e "${GREEN}✓${NC} Keeping existing config.yaml"
else
backup_if_exists "$SCRIPT_DIR/config.yaml"
fi
fi
if [ "$WRITE_CONFIG" = true ]; then
cat > "$SCRIPT_DIR/config.yaml" << EOF
# Sift Configuration (generated by setup.sh)
port: 8090
apps:
phone:
default: send
messages:
default: drop
signal:
default: send
whatsapp:
default: drop
global:
unknown_apps: drop
rate_limit:
max_per_hour: 50
cooldown_seconds: 30
sentiment_detection:
enabled: $ENABLE_AI
batch_window_seconds: 60
max_batch_size: 30
apps:
- whatsapp
- messages
- signal
rules:
- body_regex: "(verification|security) code"
action: send
- body_contains: "one-time"
action: send
sinks:
console:
enabled: true
imessage:
enabled: $ENABLE_IMESSAGE
gateway_url: "http://host.docker.internal:8095"
recipient: "${IMESSAGE_RECIPIENT:-}"
bark:
enabled: $ENABLE_BARK
url: "${BARK_URL:-}"
device_key: "${BARK_DEVICE_KEY:-}"
ntfy:
enabled: $ENABLE_NTFY
url: "${NTFY_URL:-}"
twilio:
enabled: false
EOF
echo -e "${GREEN}✓${NC} Created config.yaml"
fi
echo -e "${GREEN}✓${NC} Created processor/.env"
echo -e "${GREEN}✓${NC} Created sms-assistant/.env"
echo -e "${GREEN}✓${NC} Created imessage-gateway/.env"
# Create SMS Assistant plist
mkdir -p "$HOME/.sms-assistant"
cat > "$HOME/Library/LaunchAgents/com.notif-fwd.sms-assistant.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.notif-fwd.sms-assistant</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>$SCRIPT_DIR/sms-assistant/assistant.py</string>
</array>
<key>WorkingDirectory</key>
<string>$SCRIPT_DIR/sms-assistant</string>
<key>EnvironmentVariables</key>
<dict>
<key>DUMBPHONE_NUMBER</key>
<string>$DUMBPHONE_NUMBER</string>
<key>OLLAMA_URL</key>
<string>$OLLAMA_URL</string>
<key>OLLAMA_MODEL</key>
<string>$OLLAMA_MODEL</string>
<key>PI_HOST</key>
<string>$PI_HOST</string>
<key>OBSIDIAN_TODO</key>
<string>$OBSIDIAN_TODO_EXPANDED</string>
<key>MESSAGES_DB</key>
<string>$HOME/Library/Messages/chat.db</string>
<key>STATE_FILE</key>
<string>$HOME/.sms-assistant/state.json</string>
<key>CONTACTS_FILE</key>
<string>$CONTACTS_FILE_EXPANDED</string>
<key>DATA_FILE</key>
<string>$HOME/.sms-assistant/data.json</string>
<key>DEFAULT_LOCATION</key>
<string>$DEFAULT_LOCATION</string>
<key>DEFAULT_LAT</key>
<string>$DEFAULT_LAT</string>
<key>DEFAULT_LON</key>
<string>$DEFAULT_LON</string>
<key>HOME_ADDRESS</key>
<string>$HOME_ADDRESS</string>
<key>BARK_URL</key>
<string>${BARK_URL:-}</string>
<key>BARK_DEVICE_KEY</key>
<string>${BARK_DEVICE_KEY:-}</string>
<key>POLL_INTERVAL</key>
<string>10</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/sms-assistant.log</string>
<key>StandardErrorPath</key>
<string>/tmp/sms-assistant.log</string>
</dict>
</plist>
EOF
echo -e "${GREEN}✓${NC} Created SMS Assistant launchd plist"
# Create iMessage Gateway plist
cat > "$HOME/Library/LaunchAgents/com.notif-fwd.imessage-gateway.plist" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.notif-fwd.imessage-gateway</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>$SCRIPT_DIR/imessage-gateway/server.py</string>
</array>
<key>WorkingDirectory</key>
<string>$SCRIPT_DIR/imessage-gateway</string>
<key>EnvironmentVariables</key>
<dict>
<key>DEFAULT_RECIPIENT</key>
<string>$DUMBPHONE_NUMBER</string>
</dict>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/imessage-gateway.log</string>
<key>StandardErrorPath</key>
<string>/tmp/imessage-gateway.log</string>
</dict>
</plist>
EOF
echo -e "${GREEN}✓${NC} Created iMessage Gateway launchd plist"
# Install git hooks
cp "$SCRIPT_DIR/hooks/pre-commit" "$SCRIPT_DIR/.git/hooks/pre-commit" 2>/dev/null || true
chmod +x "$SCRIPT_DIR/.git/hooks/pre-commit" 2>/dev/null || true
echo -e "${GREEN}✓${NC} Installed git hooks"
# Create docker-compose.yaml if it doesn't exist
if [ ! -f "$SCRIPT_DIR/docker-compose.yaml" ] && [ -f "$SCRIPT_DIR/docker-compose.example.yaml" ]; then
cp "$SCRIPT_DIR/docker-compose.example.yaml" "$SCRIPT_DIR/docker-compose.yaml"
echo -e "${GREEN}✓${NC} Created docker-compose.yaml"
fi
echo ""
echo -e "${YELLOW}Setup complete!${NC}"
echo ""
echo "Next steps:"
echo ""
echo " 1. Start the processor:"
echo -e " ${BLUE}make up${NC}"
echo ""
echo " 2. Start macOS services:"
echo -e " ${BLUE}launchctl load ~/Library/LaunchAgents/com.notif-fwd.sms-assistant.plist${NC}"
echo -e " ${BLUE}launchctl load ~/Library/LaunchAgents/com.notif-fwd.imessage-gateway.plist${NC}"
echo ""
echo " 3. Install Python dependencies:"
echo -e " ${BLUE}pip install -r sms-assistant/requirements.txt${NC}"
echo -e " ${BLUE}pip install -r imessage-gateway/requirements.txt${NC}"
echo ""
if [ "$ENABLE_AI" = true ]; then
echo " 4. Pull Ollama model:"
echo -e " ${BLUE}ollama pull $OLLAMA_MODEL${NC}"
echo ""
fi
echo " 5. Set up Raspberry Pi:"
echo -e " ${BLUE}See docs/ancs-bridge-setup.md${NC}"
echo ""
echo " 6. Test:"
echo -e " ${BLUE}make test${NC}"
echo ""