-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure.sh
More file actions
executable file
·470 lines (411 loc) · 15.3 KB
/
configure.sh
File metadata and controls
executable file
·470 lines (411 loc) · 15.3 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
#!/bin/bash
# IBEX Connector Configuration
# Add or update credentials for IBEX MCP servers
#
# Usage:
# ./configure.sh # Interactive configuration
# ./configure.sh --status # Show current status only
set -e
ENV_FILE="$HOME/.ibex-mcp.env"
# ── Colors ──────────────────────────────────────────────────
if [ -t 1 ]; then
GREEN='\033[0;32m'
RED='\033[0;31m'
BOLD='\033[1m'
NC='\033[0m'
else
GREEN='' RED='' BOLD='' NC=''
fi
# ── Load existing configuration ─────────────────────────────
load_config() {
if [ -f "$ENV_FILE" ]; then
set -a
source "$ENV_FILE"
set +a
fi
}
# ── Prompt helpers ──────────────────────────────────────────
prompt_value() {
local prompt="$1"
local default="$2"
if [ -n "$default" ]; then
printf " %s [%s]: " "$prompt" "$default" >&2
else
printf " %s: " "$prompt" >&2
fi
read REPLY
if [ -n "$REPLY" ]; then
echo "$REPLY"
else
echo "$default"
fi
}
prompt_secret() {
local prompt="$1"
local default="$2"
if [ -n "$default" ]; then
if [ ${#default} -gt 4 ]; then
local masked="****${default: -4}"
else
local masked="****"
fi
printf " %s [%s]: " "$prompt" "$masked" >&2
else
printf " %s: " "$prompt" >&2
fi
read -s REPLY
echo "" >&2
if [ -n "$REPLY" ]; then
echo "$REPLY"
else
echo "$default"
fi
}
ask_yn() {
local prompt="$1"
local default="${2:-n}"
if [ "$default" = "y" ]; then
printf "%s (Y/n): " "$prompt" >&2
else
printf "%s (y/N): " "$prompt" >&2
fi
read REPLY
REPLY="${REPLY:-$default}"
case "$REPLY" in
[Yy]*) return 0 ;;
*) return 1 ;;
esac
}
# ── Connector status checks ────────────────────────────────
is_slack_configured() { [ -n "${SLACK_TOKEN:-}" ]; }
is_notion_configured() { [ -n "${NOTION_TOKEN:-}" ]; }
is_jira_configured() { [ -n "${JIRA_DOMAIN:-}" ] && [ -n "${JIRA_EMAIL:-}" ] && [ -n "${JIRA_API_TOKEN:-}" ]; }
is_memory_configured() { [ -n "${GITHUB_TOKEN:-}" ] && [ -n "${GITHUB_OWNER:-}" ] && [ -n "${GITHUB_REPO:-}" ]; }
is_servicenow_configured() { [ -n "${SERVICENOW_INSTANCE:-}" ] && [ -n "${SERVICENOW_USERNAME:-}" ] && [ -n "${SERVICENOW_PASSWORD:-}" ]; }
is_salesforce_configured() { [ -n "${SALESFORCE_INSTANCE_URL:-}" ] && [ -n "${SALESFORCE_ACCESS_TOKEN:-}" ]; }
# ── Show status ─────────────────────────────────────────────
show_status() {
echo ""
echo "Connector status:"
if is_slack_configured; then
printf " ${GREEN}✓${NC} Slack\n"
else
printf " ${RED}✗${NC} Slack\n"
fi
if is_notion_configured; then
printf " ${GREEN}✓${NC} Notion\n"
else
printf " ${RED}✗${NC} Notion\n"
fi
if is_jira_configured; then
printf " ${GREEN}✓${NC} Jira\n"
else
printf " ${RED}✗${NC} Jira\n"
fi
if is_memory_configured; then
printf " ${GREEN}✓${NC} Memory (GitHub)\n"
else
printf " ${RED}✗${NC} Memory (GitHub)\n"
fi
if is_servicenow_configured; then
printf " ${GREEN}✓${NC} ServiceNow\n"
else
printf " ${RED}✗${NC} ServiceNow\n"
fi
if is_salesforce_configured; then
printf " ${GREEN}✓${NC} Salesforce\n"
else
printf " ${RED}✗${NC} Salesforce\n"
fi
}
# ── Configure each connector ───────────────────────────────
configure_slack() {
echo ""
echo " ${BOLD}Slack Setup${NC}"
echo " → Create app: https://api.slack.com/apps"
echo " → OAuth & Permissions → User Token Scopes:"
echo " search:read, channels:history, channels:read, users:read"
echo " → Install to Workspace → Copy User OAuth Token"
echo ""
SLACK_TOKEN=$(prompt_secret "Slack user token (xoxp-...)" "${SLACK_TOKEN:-}")
}
configure_notion() {
echo ""
echo " ${BOLD}Notion Setup${NC}"
echo " → https://www.notion.so/profile/integrations"
echo " → New integration → Copy Internal Integration Secret"
echo " → Add integration to pages via ··· menu → Connections"
echo ""
NOTION_TOKEN=$(prompt_secret "Notion integration token (ntn_...)" "${NOTION_TOKEN:-}")
}
configure_jira() {
echo ""
echo " ${BOLD}Jira Setup${NC}"
echo " → https://id.atlassian.com/manage-profile/security/api-tokens"
echo ""
JIRA_DOMAIN="perconadev.atlassian.net"
JIRA_EMAIL=$(prompt_value "Jira email (you@percona.com)" "${JIRA_EMAIL:-}")
JIRA_API_TOKEN=$(prompt_secret "Jira API token" "${JIRA_API_TOKEN:-}")
}
configure_memory() {
echo ""
echo " ${BOLD}Memory (GitHub) Setup${NC}"
echo " If you already use PACK, skip this — same credentials work."
echo " → Create a private repo for memory storage"
echo " → https://github.com/settings/tokens?type=beta"
echo " → Fine-grained PAT → Scope to your org → select repo"
echo " → Permissions: Contents → Read and write"
echo ""
GITHUB_TOKEN=$(prompt_secret "GitHub fine-grained PAT (ghp_...)" "${GITHUB_TOKEN:-}")
GITHUB_OWNER=$(prompt_value "GitHub org or username" "${GITHUB_OWNER:-Percona-Lab}")
local default_repo="ai-memory-$(whoami)"
GITHUB_REPO=$(prompt_value "GitHub repo name" "${GITHUB_REPO:-$default_repo}")
GITHUB_MEMORY_PATH="${GITHUB_MEMORY_PATH:-MEMORY.md}"
}
configure_servicenow() {
echo ""
echo " ${BOLD}ServiceNow Setup${NC}"
echo " → Instance format: yourcompany.service-now.com"
echo ""
SERVICENOW_INSTANCE=$(prompt_value "ServiceNow instance" "${SERVICENOW_INSTANCE:-}")
SERVICENOW_USERNAME=$(prompt_value "ServiceNow username" "${SERVICENOW_USERNAME:-}")
SERVICENOW_PASSWORD=$(prompt_secret "ServiceNow password" "${SERVICENOW_PASSWORD:-}")
}
configure_salesforce() {
echo ""
echo " ${BOLD}Salesforce Setup${NC}"
echo " → Instance format: https://yourcompany.my.salesforce.com"
echo ""
SALESFORCE_INSTANCE_URL=$(prompt_value "Salesforce instance URL" "${SALESFORCE_INSTANCE_URL:-}")
SALESFORCE_ACCESS_TOKEN=$(prompt_secret "Salesforce access token" "${SALESFORCE_ACCESS_TOKEN:-}")
}
# ── Write env file ──────────────────────────────────────────
write_env_file() {
# Preserve any unknown lines from existing file
local extra_lines=""
if [ -f "$ENV_FILE" ]; then
while IFS= read -r line || [ -n "$line" ]; do
case "$line" in
SLACK_TOKEN=*|NOTION_TOKEN=*) ;;
JIRA_DOMAIN=*|JIRA_EMAIL=*|JIRA_API_TOKEN=*) ;;
GITHUB_TOKEN=*|GITHUB_OWNER=*|GITHUB_REPO=*|GITHUB_MEMORY_PATH=*) ;;
SERVICENOW_INSTANCE=*|SERVICENOW_USERNAME=*|SERVICENOW_PASSWORD=*) ;;
SALESFORCE_INSTANCE_URL=*|SALESFORCE_ACCESS_TOKEN=*) ;;
NOTION_SYNC_PAGE_ID=*|GOOGLE_DOC_ID=*|GOOGLE_CLIENT_ID=*) ;;
GOOGLE_CLIENT_SECRET=*|GOOGLE_REFRESH_TOKEN=*) ;;
\#*|"") ;;
*=*) extra_lines="${extra_lines}${line}"$'\n' ;;
esac
done < "$ENV_FILE"
fi
{
echo "# IBEX MCP Server Configuration"
echo "# Last updated: $(date '+%Y-%m-%d %H:%M:%S')"
if [ -n "${SLACK_TOKEN:-}" ]; then
echo ""
echo "# Slack (user token required for search)"
echo "SLACK_TOKEN=$SLACK_TOKEN"
fi
if [ -n "${NOTION_TOKEN:-}" ]; then
echo ""
echo "# Notion"
echo "NOTION_TOKEN=$NOTION_TOKEN"
fi
if [ -n "${JIRA_DOMAIN:-}" ] || [ -n "${JIRA_EMAIL:-}" ] || [ -n "${JIRA_API_TOKEN:-}" ]; then
echo ""
echo "# Jira"
[ -n "${JIRA_DOMAIN:-}" ] && echo "JIRA_DOMAIN=$JIRA_DOMAIN"
[ -n "${JIRA_EMAIL:-}" ] && echo "JIRA_EMAIL=$JIRA_EMAIL"
[ -n "${JIRA_API_TOKEN:-}" ] && echo "JIRA_API_TOKEN=$JIRA_API_TOKEN"
fi
if [ -n "${GITHUB_TOKEN:-}" ] || [ -n "${GITHUB_OWNER:-}" ] || [ -n "${GITHUB_REPO:-}" ]; then
echo ""
echo "# Memory (GitHub-backed)"
[ -n "${GITHUB_TOKEN:-}" ] && echo "GITHUB_TOKEN=$GITHUB_TOKEN"
[ -n "${GITHUB_OWNER:-}" ] && echo "GITHUB_OWNER=$GITHUB_OWNER"
[ -n "${GITHUB_REPO:-}" ] && echo "GITHUB_REPO=$GITHUB_REPO"
echo "GITHUB_MEMORY_PATH=${GITHUB_MEMORY_PATH:-MEMORY.md}"
fi
if [ -n "${SERVICENOW_INSTANCE:-}" ] || [ -n "${SERVICENOW_USERNAME:-}" ] || [ -n "${SERVICENOW_PASSWORD:-}" ]; then
echo ""
echo "# ServiceNow"
[ -n "${SERVICENOW_INSTANCE:-}" ] && echo "SERVICENOW_INSTANCE=$SERVICENOW_INSTANCE"
[ -n "${SERVICENOW_USERNAME:-}" ] && echo "SERVICENOW_USERNAME=$SERVICENOW_USERNAME"
[ -n "${SERVICENOW_PASSWORD:-}" ] && echo "SERVICENOW_PASSWORD=$SERVICENOW_PASSWORD"
fi
if [ -n "${SALESFORCE_INSTANCE_URL:-}" ] || [ -n "${SALESFORCE_ACCESS_TOKEN:-}" ]; then
echo ""
echo "# Salesforce"
[ -n "${SALESFORCE_INSTANCE_URL:-}" ] && echo "SALESFORCE_INSTANCE_URL=$SALESFORCE_INSTANCE_URL"
[ -n "${SALESFORCE_ACCESS_TOKEN:-}" ] && echo "SALESFORCE_ACCESS_TOKEN=$SALESFORCE_ACCESS_TOKEN"
fi
# Preserve memory sync settings
if [ -n "${NOTION_SYNC_PAGE_ID:-}" ] || [ -n "${GOOGLE_DOC_ID:-}" ]; then
echo ""
echo "# Memory sync (optional)"
[ -n "${NOTION_SYNC_PAGE_ID:-}" ] && echo "NOTION_SYNC_PAGE_ID=$NOTION_SYNC_PAGE_ID"
[ -n "${GOOGLE_DOC_ID:-}" ] && echo "GOOGLE_DOC_ID=$GOOGLE_DOC_ID"
[ -n "${GOOGLE_CLIENT_ID:-}" ] && echo "GOOGLE_CLIENT_ID=$GOOGLE_CLIENT_ID"
[ -n "${GOOGLE_CLIENT_SECRET:-}" ] && echo "GOOGLE_CLIENT_SECRET=$GOOGLE_CLIENT_SECRET"
[ -n "${GOOGLE_REFRESH_TOKEN:-}" ] && echo "GOOGLE_REFRESH_TOKEN=$GOOGLE_REFRESH_TOKEN"
fi
# Preserve any unknown settings
if [ -n "$extra_lines" ]; then
echo ""
echo "# Additional settings"
printf "%s" "$extra_lines"
fi
echo ""
} > "$ENV_FILE"
chmod 600 "$ENV_FILE"
}
# ── Main ────────────────────────────────────────────────────
load_config
# Install mode: skip Open WebUI update (install.sh handles it later after Docker setup)
INSTALL_MODE=false
if [ "${1:-}" = "--install-mode" ]; then
INSTALL_MODE=true
fi
# Status-only mode
if [ "${1:-}" = "--status" ]; then
echo "============================================================"
echo " IBEX Connector Status"
echo "============================================================"
show_status
echo ""
echo "Credentials: $ENV_FILE"
exit 0
fi
echo "============================================================"
echo " IBEX Connector Configuration"
echo "============================================================"
show_status
echo ""
changed=false
# Check if any connectors are already configured
configured_list=""
is_slack_configured && configured_list="${configured_list} Slack,"
is_notion_configured && configured_list="${configured_list} Notion,"
is_jira_configured && configured_list="${configured_list} Jira,"
is_servicenow_configured && configured_list="${configured_list} ServiceNow,"
is_salesforce_configured && configured_list="${configured_list} Salesforce,"
is_memory_configured && configured_list="${configured_list} Memory,"
if [ -n "$configured_list" ]; then
# Trim trailing comma
configured_list="${configured_list%,}"
echo " Settings found for:${configured_list}"
echo ""
if ! ask_yn " Need to change anything?"; then
echo ""
echo " No changes made."
echo ""
if $INSTALL_MODE; then exit 0; else exit 0; fi
fi
echo ""
fi
# Iterate through each connector
for connector in slack notion jira servicenow salesforce memory; do
configured=false
label=""
case $connector in
slack) is_slack_configured && configured=true || true; label="Slack" ;;
notion) is_notion_configured && configured=true || true; label="Notion" ;;
jira) is_jira_configured && configured=true || true; label="Jira" ;;
memory) is_memory_configured && configured=true || true; label="Memory (GitHub)" ;;
servicenow) is_servicenow_configured && configured=true || true; label="ServiceNow" ;;
salesforce) is_salesforce_configured && configured=true || true; label="Salesforce" ;;
esac
if $configured; then
if ask_yn "$label is configured. Reconfigure?"; then
"configure_$connector"
changed=true
fi
else
if ask_yn "Configure $label?"; then
"configure_$connector"
changed=true
fi
fi
done
if $changed; then
write_env_file
echo ""
echo "============================================================"
echo " Configuration saved to $ENV_FILE"
echo "============================================================"
show_status
# Rebuild system prompt based on new configuration
IBEX_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$IBEX_DIR/scripts/build-prompt.sh"
sys_prompt=$(build_system_prompt)
PROMPT_FILE="$HOME/.ibex-system-prompt.txt"
echo -e "$sys_prompt" > "$PROMPT_FILE"
echo ""
echo "Updated system prompt saved to $PROMPT_FILE"
echo ""
echo "────────────────────────────────────────"
echo -e "$sys_prompt"
echo "────────────────────────────────────────"
echo ""
if $INSTALL_MODE; then
echo " Open WebUI prompt will be configured after Docker setup."
elif ask_yn " Update Open WebUI system prompt automatically?"; then
echo ""
read -rp " Open WebUI email: " email
read -rsp " Open WebUI password: " password
echo ""
auth_response=$(curl -sf -X POST http://localhost:8080/api/v1/auths/signin \
-H "Content-Type: application/json" \
-d "{\"email\":\"${email}\",\"password\":\"${password}\"}" 2>/dev/null)
token=$(echo "$auth_response" | python3 -c "import sys,json; print(json.load(sys.stdin).get('token',''))" 2>/dev/null)
if [ -n "$token" ]; then
python3 -c "
import sys, json, urllib.request
token = sys.argv[1]
prompt_file = sys.argv[2]
with open(prompt_file) as f:
sys_prompt = f.read().strip()
try:
req = urllib.request.Request(
'http://localhost:8080/api/v1/users/user/settings',
headers={'Authorization': f'Bearer {token}'},
)
resp = urllib.request.urlopen(req)
settings = json.loads(resp.read())
except Exception:
settings = {}
settings['system'] = sys_prompt
payload = json.dumps(settings).encode()
req = urllib.request.Request(
'http://localhost:8080/api/v1/users/user/settings/update',
data=payload,
headers={
'Authorization': f'Bearer {token}',
'Content-Type': 'application/json',
},
method='POST',
)
urllib.request.urlopen(req)
print('ok')
" "$token" "$PROMPT_FILE" 2>/dev/null | grep -q "ok" && \
printf " ${GREEN}✓${NC} System prompt updated in Open WebUI\n" || \
printf " ${RED}✗${NC} Failed to update system prompt\n"
else
printf " ${RED}✗${NC} Could not sign in — check your credentials\n"
echo " You can paste the prompt manually from $PROMPT_FILE"
fi
else
echo " You can paste it manually in Open WebUI:"
echo " Settings → General → System Prompt"
fi
if ! $INSTALL_MODE; then
echo ""
echo "Restart IBEX servers to apply changes:"
echo " ~/IBEX/start.sh"
fi
echo ""
else
echo ""
echo "No changes made."
echo ""
fi