-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·1205 lines (1053 loc) · 43.4 KB
/
setup.sh
File metadata and controls
executable file
·1205 lines (1053 loc) · 43.4 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
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -euo pipefail
# =============================================================
# Opencode Personal Assistant — Interactive Setup Wizard
# =============================================================
BOLD='\033[1m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ENV_FILE="$SCRIPT_DIR/.env"
MEMORY_DIR="$SCRIPT_DIR/memory"
SOUL_FILE="$MEMORY_DIR/soul.md"
CRON_FILE="$MEMORY_DIR/cron.yml"
SETUP_LOG="${TMPDIR:-/tmp}/opencode-setup.log"
# Reset log on every run so users can share a fresh one when reporting issues
: > "$SETUP_LOG"
print_header() {
echo ""
echo -e "${CYAN}${BOLD}╔══════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}${BOLD}║ Opencode Personal Assistant — Setup ║${NC}"
echo -e "${CYAN}${BOLD}╚══════════════════════════════════════════════╝${NC}"
echo ""
}
print_step() {
echo ""
echo -e "${CYAN}${BOLD}── $1 ──────────────────────────────────${NC}"
}
print_ok() {
echo -e "${GREEN}✓${NC} $1"
}
print_warn() {
echo -e "${YELLOW}⚠${NC} $1"
}
print_err() {
echo -e "${RED}✗${NC} $1"
}
ask() {
local prompt="$1"
local default="${2:-}"
local answer
if [[ -n "$default" ]]; then
echo -ne "${BOLD}→${NC} $prompt (default: $default): " >&2
read -r answer < /dev/tty
echo "${answer:-$default}"
else
echo -ne "${BOLD}→${NC} $prompt: " >&2
read -r answer < /dev/tty
echo "$answer"
fi
}
ask_yn() {
local prompt="$1"
local default="${2:-S}"
local answer
echo -ne "${BOLD}→${NC} $prompt [S/n]: " >&2
read -r answer < /dev/tty
answer="${answer:-$default}"
[[ "${answer,,}" =~ ^(s|y|si|yes)$ ]]
}
ask_choice() {
local prompt="$1"
shift
local options=("$@")
local choice
# Print options to stderr so they are visible even when called inside $(...)
for i in "${!options[@]}"; do
echo " $((i+1))) ${options[$i]}" >&2
done
while true; do
# Read from /dev/tty so it works inside $(...) subshells
# Prompt goes to stderr so it is always visible
echo -ne "${BOLD}→${NC} $prompt [1-${#options[@]}]: " >&2
read -r choice < /dev/tty
if [[ "$choice" =~ ^[0-9]+$ ]] && (( choice >= 1 && choice <= ${#options[@]} )); then
echo "$choice"
return
fi
echo " Please enter a number between 1 and ${#options[@]}" >&2
done
}
# ── Detect timezone ─────────────────────────────────────────
detect_timezone() {
if command -v timedatectl &>/dev/null; then
timedatectl show --property=Timezone --value 2>/dev/null || echo "UTC"
elif [[ -f /etc/timezone ]]; then
cat /etc/timezone
elif [[ -L /etc/localtime ]]; then
readlink /etc/localtime | sed 's|.*/zoneinfo/||'
else
echo "UTC"
fi
}
# ── Validate Telegram token via getMe ───────────────────────
validate_telegram_token() {
local token="$1"
local result
result=$(curl -s "https://api.telegram.org/bot${token}/getMe" 2>/dev/null || echo '{}')
if echo "$result" | grep -q '"ok":true'; then
echo "$result" | grep -o '"username":"[^"]*"' | cut -d'"' -f4
return 0
fi
return 1
}
# ── Privilege helpers ───────────────────────────────────────
is_root() {
[[ $EUID -eq 0 ]]
}
# Returns 0 if we can run privileged commands (root or sudo available).
# Note: this does NOT prove sudo will succeed — it just checks the binary
# exists. The actual sudo call may still prompt for a password.
has_sudo() {
is_root && return 0
command -v sudo &>/dev/null
}
# Run a command with root privileges (direct if root, else via sudo).
run_root() {
if is_root; then
"$@"
else
sudo "$@"
fi
}
# Detect operating system
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "macos" ;;
*) echo "unknown" ;;
esac
}
# Refresh PATH with all common install locations OpenCode/npm/bun may use
reload_install_paths() {
local node_version
node_version="$(node -v 2>/dev/null || echo "")"
for dir in \
"$HOME/.opencode/bin" \
"$HOME/.local/bin" \
"$HOME/bin" \
"$HOME/.bun/bin" \
"/usr/local/bin" \
"$HOME/.npm-global/bin" \
"$HOME/.nvm/versions/node/${node_version}/bin"; do
if [[ -d "$dir" && ":$PATH:" != *":$dir:"* ]]; then
export PATH="$dir:$PATH"
fi
done
# Best-effort source of common shell rc files (PATH exports may live there)
# shellcheck disable=SC1090,SC1091
[[ -f "$HOME/.profile" ]] && source "$HOME/.profile" 2>/dev/null || true
# shellcheck disable=SC1090,SC1091
[[ -f "$HOME/.bashrc" ]] && source "$HOME/.bashrc" 2>/dev/null || true
}
# ── Generate soul.md from wizard answers ────────────────────
generate_soul() {
local name="$1"
local lang="$2"
local tone="$3"
local extra="$4"
local tone_desc
case "$tone" in
1) tone_desc="Direct and concise — get to the point, avoid unnecessary words" ;;
2) tone_desc="Friendly and conversational — warm, approachable, use informal language" ;;
3) tone_desc="Technical and detailed — thorough explanations, include relevant details" ;;
*) tone_desc="Direct and concise" ;;
esac
cat > "$SOUL_FILE" << EOF
# Soul — ${name}
You are ${name}, an intelligent and proactive personal assistant powered by OpenCode.
## Language
Respond in: ${lang}
Adapt to the user's language if they write in a different one.
## Personality & Tone
${tone_desc}
## Behavior
- When the user asks you to remember something, update \`memory/memory.md\`
- Use \`memory/context.md\` to understand the current project or focus area
- Follow \`memory/agents.md\` to choose the right agent for each task
- Default model: big-pickle (Claude Sonnet — completely free)
## Skills
You have access to the following skills in \`memory/skills/\`:
- **web-search** — search for information on the internet
- **code-review** — review code and suggest improvements
- **daily-summary** — generate a daily summary of activity
When a task requires a skill, read its instructions from \`memory/skills/<name>.md\`
and apply them to complete the task.
## Memory Rules
- Add facts, preferences, and important notes to \`memory/memory.md\`
- Keep \`memory/context.md\` updated with the active project
- Never modify \`memory/soul.md\` — it is read-only
$(if [[ -n "$extra" ]]; then echo -e "\n## Special Instructions\n${extra}"; fi)
EOF
}
# ── Generate cron.yml with correct timezone ─────────────────
generate_cron_yml() {
local tz="$1"
cat > "$CRON_FILE" << EOF
# Cron Jobs — Opencode Personal Assistant
# Changes here are automatically synced with the bot.
#
# Types:
# task — creates an OpenCode session and runs the prompt (default)
# reminder — sends a direct Telegram message (no tokens used)
# backup — copies memory files to memory/backups/YYYY-MM-DD/
#
# Schedule: standard cron expression (min hour dom month dow)
crons: []
# Examples (uncomment to enable):
#
# - id: daily-summary
# schedule: "0 8 * * *"
# type: task
# prompt: "Generate a daily summary using the daily-summary skill"
# timezone: "${tz}"
#
# - id: morning-reminder
# schedule: "30 7 * * 1-5"
# type: reminder
# message: "Good morning! Check your pending tasks."
# timezone: "${tz}"
#
# - id: weekly-backup
# schedule: "0 0 * * 0"
# type: backup
# timezone: "${tz}"
EOF
}
# ── Detect Linux package manager ────────────────────────────
detect_pkg_manager() {
if command -v apt-get &>/dev/null; then echo "apt"
elif command -v dnf &>/dev/null; then echo "dnf"
elif command -v yum &>/dev/null; then echo "yum"
elif command -v pacman &>/dev/null; then echo "pacman"
elif command -v zypper &>/dev/null; then echo "zypper"
else echo "unknown"
fi
}
# ── Install Docker on Linux via the official convenience script ────
install_docker_linux() {
echo ""
echo " Docker not found. The official installer will be used:"
echo " https://get.docker.com"
echo ""
if ! has_sudo; then
print_err "Cannot install Docker without sudo or root privileges."
echo " Please install Docker manually: https://docs.docker.com/engine/install/"
return 1
fi
echo " This will request sudo to install the Docker Engine + Compose v2 plugin."
if ! ask_yn "Install Docker now?"; then
return 1
fi
if ! curl -fsSL https://get.docker.com -o "$SETUP_LOG.docker.sh" 2>>"$SETUP_LOG"; then
print_err "Failed to download Docker installer."
return 1
fi
if ! run_root sh "$SETUP_LOG.docker.sh" >>"$SETUP_LOG" 2>&1; then
print_err "Docker installer failed (see $SETUP_LOG)."
rm -f "$SETUP_LOG.docker.sh"
return 1
fi
rm -f "$SETUP_LOG.docker.sh"
# Add the current user to the docker group so we can run without sudo.
if ! is_root; then
if ! id -nG "$USER" | tr ' ' '\n' | grep -qx docker; then
run_root usermod -aG docker "$USER" 2>>"$SETUP_LOG" || true
print_warn "Added $USER to the 'docker' group."
print_warn "Group membership only takes effect in NEW shells."
print_warn "Once setup finishes, log out and back in (or run 'newgrp docker')"
print_warn "to use 'docker' without sudo."
fi
fi
return 0
}
# ── Install the docker compose v2 plugin if missing ────────
install_compose_plugin_linux() {
local pm
pm="$(detect_pkg_manager)"
if ! has_sudo; then
print_err "Cannot install docker-compose-plugin without sudo or root."
return 1
fi
case "$pm" in
apt)
run_root apt-get update >>"$SETUP_LOG" 2>&1 || true
run_root apt-get install -y docker-compose-plugin >>"$SETUP_LOG" 2>&1
;;
dnf|yum)
run_root "$pm" install -y docker-compose-plugin >>"$SETUP_LOG" 2>&1
;;
pacman)
run_root pacman -Sy --noconfirm docker-compose >>"$SETUP_LOG" 2>&1
;;
zypper)
run_root zypper install -y docker-compose >>"$SETUP_LOG" 2>&1
;;
*)
print_err "Unknown package manager. Install docker-compose-plugin manually."
return 1
;;
esac
}
# ── Ensure docker daemon is reachable ───────────────────────
docker_can_connect() {
docker info &>/dev/null
}
# ── Ensure all required dependencies are installed ─────────
ensure_dependencies() {
local os
os="$(detect_os)"
# curl is required to download installers / call Telegram API
if ! command -v curl &>/dev/null; then
print_err "Required dependency not found: curl"
echo " curl is required to download installers and validate the bot token."
case "$os" in
linux)
local pm
pm="$(detect_pkg_manager)"
if [[ "$pm" != "unknown" ]] && has_sudo; then
if ask_yn "Install curl now (via $pm)?"; then
case "$pm" in
apt) run_root apt-get update >>"$SETUP_LOG" 2>&1 && run_root apt-get install -y curl ;;
dnf|yum) run_root "$pm" install -y curl ;;
pacman) run_root pacman -Sy --noconfirm curl ;;
zypper) run_root zypper install -y curl ;;
esac
fi
fi
;;
*)
echo " Install curl and run setup.sh again."
;;
esac
if ! command -v curl &>/dev/null; then
exit 1
fi
fi
# Docker engine
if ! command -v docker &>/dev/null; then
case "$os" in
linux)
if ! install_docker_linux; then
print_err "Docker installation failed or skipped."
echo " Install Docker manually and re-run setup.sh:"
echo " https://docs.docker.com/engine/install/"
exit 1
fi
;;
macos)
print_err "Docker not found."
echo " On macOS, install Docker Desktop (or OrbStack):"
echo " https://www.docker.com/products/docker-desktop/"
echo " or: brew install --cask docker"
exit 1
;;
*)
print_err "Docker not found and automatic install is not supported on this OS."
echo " Install Docker manually: https://docs.docker.com/engine/install/"
exit 1
;;
esac
fi
# Compose v2 plugin
if ! docker compose version &>/dev/null 2>&1; then
print_warn "docker compose v2 plugin not found."
if [[ "$os" == "linux" ]]; then
if ask_yn "Install the docker-compose-plugin now?"; then
if ! install_compose_plugin_linux; then
print_err "Failed to install docker-compose-plugin (see $SETUP_LOG)."
echo " Install manually: https://docs.docker.com/compose/install/linux/"
exit 1
fi
else
echo " Install docker compose v2 manually and re-run setup.sh."
exit 1
fi
else
print_err "docker compose v2 is required."
echo " See: https://docs.docker.com/compose/install/"
exit 1
fi
if ! docker compose version &>/dev/null 2>&1; then
print_err "docker compose v2 still not available after installation."
exit 1
fi
fi
# Daemon reachability — covers fresh installs where the user is not yet in
# the 'docker' group, or the daemon is stopped.
if ! docker_can_connect; then
if has_sudo && run_root docker info &>/dev/null; then
print_warn "Docker daemon is running but the current user cannot reach it."
print_warn "You were added to the 'docker' group, but group changes only"
print_warn "apply to NEW shells. Log out and back in (or run 'newgrp docker')"
print_warn "and then re-run ./setup.sh."
exit 1
fi
# Try to start the daemon (systemd-managed installs)
if has_sudo && command -v systemctl &>/dev/null; then
run_root systemctl start docker >>"$SETUP_LOG" 2>&1 || true
run_root systemctl enable docker >>"$SETUP_LOG" 2>&1 || true
fi
if ! docker_can_connect; then
print_err "Cannot reach the Docker daemon."
echo " Make sure Docker is running and you have permission to use it."
echo " Logs: $SETUP_LOG"
exit 1
fi
fi
print_ok "Dependencies OK: curl, docker $(docker --version 2>/dev/null | awk '{print $3}' | tr -d ','), compose v2"
}
# ────────────────────────────────────────────────────────────
# MAIN WIZARD
# ────────────────────────────────────────────────────────────
main() {
print_header
echo "Welcome to the Opencode Personal Assistant setup wizard."
echo "Answer the following questions to configure your assistant."
# ── Check dependencies ───────────────────────────────────
ensure_dependencies
# ── Handle existing .env ─────────────────────────────────
if [[ -f "$ENV_FILE" ]]; then
echo ""
print_warn ".env file already exists."
if ! ask_yn "Overwrite it with new configuration?"; then
echo "Setup cancelled. Your existing .env was not modified."
exit 0
fi
fi
# The assistant always runs as Full Docker: bot + OpenCode in compose.
local opencode_api_url="http://opencode:4096"
# ──────────────────────────────────────────────────────────
# STEP 1 — Bot language
# ──────────────────────────────────────────────────────────
print_step "STEP 1/12 — Bot Language"
echo ""
local lang_choice
lang_choice=$(ask_choice "Bot interface language" \
"Español (es)" \
"English (en)" \
"Deutsch (de)" \
"Français (fr)" \
"Русский (ru)" \
"简体中文 (zh)")
local bot_locale
case "$lang_choice" in
1) bot_locale="es" ;;
2) bot_locale="en" ;;
3) bot_locale="de" ;;
4) bot_locale="fr" ;;
5) bot_locale="ru" ;;
6) bot_locale="zh" ;;
*) bot_locale="en" ;;
esac
print_ok "Language: $bot_locale"
# ──────────────────────────────────────────────────────────
# STEP 2 — Channels (Telegram, WhatsApp, or both)
# ──────────────────────────────────────────────────────────
print_step "STEP 2/12 — Messaging Channels"
echo ""
echo " The assistant talks to you over a chat app. Telegram has the richest"
echo " UI (inline buttons, pinned status, /skills picker, etc.). WhatsApp"
echo " is supported as a second channel via Baileys (unofficial Web client),"
echo " with a more limited UI but ubiquitous reach."
echo ""
local channels_choice
channels_choice=$(ask_choice "Which channel(s) do you want?" \
"Telegram only (full features, recommended)" \
"Telegram + WhatsApp (both channels, richest setup)" \
"WhatsApp only (no Telegram — limited UI; permissions/skills/task pickers unavailable)")
local use_telegram=false
local use_whatsapp=false
case "$channels_choice" in
1) use_telegram=true; use_whatsapp=false ;;
2) use_telegram=true; use_whatsapp=true ;;
3) use_telegram=false; use_whatsapp=true ;;
esac
# ──────────────────────────────────────────────────────────
# STEP 3 — Telegram Bot Token (skipped when only WhatsApp)
# ──────────────────────────────────────────────────────────
print_step "STEP 3/12 — Telegram Bot Token"
local bot_token=""
local bot_username=""
if $use_telegram; then
echo ""
echo " Create your bot with @BotFather:"
echo " 1. Open https://t.me/BotFather in Telegram"
echo " 2. Send /newbot and follow the prompts"
echo " 3. Copy the bot token you receive"
echo ""
while true; do
bot_token=$(ask "Paste your TELEGRAM_BOT_TOKEN")
if [[ -z "$bot_token" ]]; then
print_err "Token cannot be empty."
continue
fi
echo " Validating token..."
if bot_username=$(validate_telegram_token "$bot_token"); then
print_ok "Token valid! Bot: @${bot_username}"
break
else
print_err "Invalid token or network error. Please check and try again."
fi
done
else
echo ""
echo " (skipped — Telegram disabled in step 2)"
fi
# ──────────────────────────────────────────────────────────
# STEP 4 — Telegram User ID (skipped when only WhatsApp)
# ──────────────────────────────────────────────────────────
print_step "STEP 4/12 — Your Telegram User ID"
local user_id=""
if $use_telegram; then
echo ""
echo " Get your numeric user ID:"
echo " 1. Open https://t.me/userinfobot in Telegram"
echo " 2. Send any message"
echo " 3. Copy your numeric ID (e.g. 123456789)"
echo ""
echo " ⚠ Only this ID will be able to interact with your bot."
echo ""
while true; do
user_id=$(ask "Paste your TELEGRAM_ALLOWED_USER_ID")
if [[ "$user_id" =~ ^[0-9]+$ ]]; then
print_ok "User ID: $user_id"
break
else
print_err "User ID must be a number."
fi
done
else
echo ""
echo " (skipped — Telegram disabled in step 2)"
fi
# ──────────────────────────────────────────────────────────
# STEP 4 — AI Model
# ──────────────────────────────────────────────────────────
print_step "STEP 5/12 — AI Model"
echo ""
local model_choice
model_choice=$(ask_choice "Which AI model?" \
"big-pickle — Claude Sonnet (FREE, recommended)" \
"Anthropic Claude (API key required)" \
"OpenAI GPT (API key required)" \
"OpenRouter (free models available)" \
"Other OpenCode-compatible provider")
local model_provider="opencode"
local model_id="big-pickle"
local extra_model_env=""
case "$model_choice" in
1)
model_provider="opencode"
model_id="big-pickle"
print_ok "Model: big-pickle (free)"
;;
2)
model_provider="anthropic"
model_id=$(ask "Model ID" "claude-sonnet-4-5")
local anthropic_key
anthropic_key=$(ask "Anthropic API key")
extra_model_env="ANTHROPIC_API_KEY=${anthropic_key}"
print_ok "Model: $model_provider/$model_id"
;;
3)
model_provider="openai"
model_id=$(ask "Model ID" "gpt-4o")
local openai_key
openai_key=$(ask "OpenAI API key")
extra_model_env="OPENAI_API_KEY=${openai_key}"
print_ok "Model: $model_provider/$model_id"
;;
4)
model_provider="openrouter"
model_id=$(ask "Model ID (e.g. meta-llama/llama-3.1-8b-instruct:free)" "meta-llama/llama-3.1-8b-instruct:free")
local openrouter_key
openrouter_key=$(ask "OpenRouter API key")
extra_model_env="OPENROUTER_API_KEY=${openrouter_key}"
print_ok "Model: $model_provider/$model_id"
;;
5)
model_provider=$(ask "Provider ID")
model_id=$(ask "Model ID")
print_ok "Model: $model_provider/$model_id"
;;
esac
# ──────────────────────────────────────────────────────────
# STEP 5 — TTS
# ──────────────────────────────────────────────────────────
print_step "STEP 6/12 — Text to Speech (optional)"
echo ""
local tts_choice
tts_choice=$(ask_choice "TTS provider" \
"No TTS — text only" \
"Speechify (FREE — 50,000 chars/month, recommended)" \
"Edge TTS — Microsoft (FREE, no API key)" \
"OpenAI TTS (API key required)" \
"Google Cloud TTS (credentials required)")
local tts_provider=""
local tts_api_url=""
local tts_api_key=""
local tts_model=""
local tts_voice=""
local speechify_api_key=""
local tts_wait_for_idle="true"
local google_credentials=""
case "$tts_choice" in
1)
tts_provider=""
print_ok "TTS: disabled"
;;
2)
tts_provider="speechify"
echo ""
echo " Get your free Speechify API key at https://api.speechify.ai"
echo " Free tier: 50,000 characters/month"
echo ""
speechify_api_key=$(ask "Paste your SPEECHIFY_API_KEY")
echo ""
echo " Spanish voices: es-ES-elena, es-MX-camila, es-ES-diego"
echo " English voices: henry, aria, cliff, bella"
tts_voice=$(ask "Voice ID" "henry")
print_ok "TTS: Speechify ($tts_voice)"
;;
3)
# Edge TTS uses the openai-compatible provider with edge-tts service
tts_provider="openai"
tts_api_url="http://localhost:5050/v1"
tts_voice=$(ask "Edge TTS voice" "es-ES-ElviraNeural")
tts_model="tts-1"
print_ok "TTS: Edge TTS ($tts_voice)"
print_warn "Note: Edge TTS requires a local edge-tts proxy running on port 5050"
;;
4)
tts_provider="openai"
tts_api_url=$(ask "TTS API URL" "https://api.openai.com/v1")
tts_api_key=$(ask "TTS API key")
tts_model=$(ask "TTS model" "tts-1")
tts_voice=$(ask "Voice" "alloy")
print_ok "TTS: OpenAI ($tts_voice)"
;;
5)
tts_provider="google"
google_credentials=$(ask "Path to Google service account JSON" "/app/gcloud-key.json")
tts_voice=$(ask "Voice" "en-US-Studio-O")
print_ok "TTS: Google Cloud ($tts_voice)"
;;
esac
# ──────────────────────────────────────────────────────────
# STEP 6 — STT
# ──────────────────────────────────────────────────────────
print_step "STEP 7/12 — Voice Messages / Speech to Text (optional)"
echo ""
local stt_choice
stt_choice=$(ask_choice "STT provider" \
"No STT — no voice messages" \
"Groq Whisper (FREE, generous limit, recommended)" \
"OpenAI Whisper (API key required)" \
"Other Whisper-compatible API")
local stt_api_url=""
local stt_api_key=""
local stt_model=""
local stt_hide_recognized="true"
case "$stt_choice" in
1)
print_ok "STT: disabled"
;;
2)
echo ""
echo " Get your free Groq API key at https://console.groq.com"
echo ""
stt_api_url="https://api.groq.com/openai/v1"
stt_api_key=$(ask "Paste your Groq API key")
stt_model="whisper-large-v3-turbo"
print_ok "STT: Groq Whisper"
;;
3)
stt_api_url="https://api.openai.com/v1"
stt_api_key=$(ask "OpenAI API key")
stt_model="whisper-1"
print_ok "STT: OpenAI Whisper"
;;
4)
stt_api_url=$(ask "STT API URL")
stt_api_key=$(ask "STT API key")
stt_model=$(ask "STT model" "whisper-large-v3-turbo")
print_ok "STT: custom ($stt_api_url)"
;;
esac
# Ask about hiding recognized text only if STT is enabled
if [[ "$stt_choice" != "1" ]]; then
echo ""
echo " When you send a voice message, the transcribed text can be"
echo " shown in the chat or hidden (only sent silently to the assistant)."
echo ""
if ask_yn "Hide the transcribed text in the chat? (recommended)"; then
stt_hide_recognized="true"
print_ok "Transcribed text will be hidden"
else
stt_hide_recognized="false"
print_ok "Transcribed text will be shown in chat"
fi
fi
# ──────────────────────────────────────────────────────────
# STEP 7 — WhatsApp (optional second channel)
# ──────────────────────────────────────────────────────────
print_step "STEP 8/12 — WhatsApp number"
local whatsapp_enabled="false"
local whatsapp_number=""
if $use_whatsapp; then
echo ""
echo " ⚠ Uses Baileys, an unofficial WhatsApp Web client. Meta may ban"
echo " numbers that talk to unofficial clients — use a DEDICATED number,"
echo " not your main personal account."
echo ""
echo " Limitations:"
echo " • Permission/question dialogs not yet mirrored to WhatsApp"
if ! $use_telegram; then
echo " • Scheduled tasks (/task) require Telegram, unavailable in WhatsApp-only mode"
echo " • No model/agent/variant pickers, /skills, /commands, /projects from WhatsApp"
else
echo " • Pickers (model/agent/skills/projects) live in Telegram"
fi
echo ""
echo " Enter the dedicated phone number with country code (no '+', no spaces)."
echo " Example: 34666999999 for Spain, 5215511223344 for Mexico."
echo ""
whatsapp_enabled="true"
while true; do
whatsapp_number=$(ask "WhatsApp phone number")
whatsapp_number="${whatsapp_number//[^0-9]/}"
if [[ -n "$whatsapp_number" ]] && [[ ${#whatsapp_number} -ge 8 ]]; then
print_ok "WhatsApp number: $whatsapp_number (you'll scan a QR on first start)"
break
else
print_err "Please enter a valid phone number (digits only, 8+ chars)."
fi
done
else
echo ""
echo " (skipped — WhatsApp disabled in step 2)"
fi
# ──────────────────────────────────────────────────────────
# STEP 8 — Timezone
# ──────────────────────────────────────────────────────────
print_step "STEP 9/12 — Timezone (for cron jobs)"
echo ""
local detected_tz
detected_tz=$(detect_timezone)
echo " Detected timezone: $detected_tz"
echo ""
local timezone
if ask_yn "Use this timezone?" "S"; then
timezone="$detected_tz"
else
timezone=$(ask "Enter your timezone (e.g. America/Bogota, Europe/Madrid)")
fi
print_ok "Timezone: $timezone"
# ──────────────────────────────────────────────────────────
# STEP 9 — Personality
# ──────────────────────────────────────────────────────────
print_step "STEP 10/12 — Assistant Personality"
echo ""
echo " Customize your assistant's personality."
echo " (You can edit memory/soul.md at any time.)"
echo ""
local assistant_name
assistant_name=$(ask "Assistant name" "Assistant")
local assistant_lang
assistant_lang=$(ask "Default response language" "Same as the user")
echo ""
local tone_choice
tone_choice=$(ask_choice "Tone" \
"Professional and concise (recommended)" \
"Friendly and conversational" \
"Technical and detailed")
echo ""
echo " Optional: add special instructions for your assistant"
echo " Example: 'Always respond in bullet points'"
echo " 'You are an expert in Python and DevOps'"
echo ""
local extra_instructions
extra_instructions=$(ask "Special instructions (Enter to skip)" "")
print_ok "Personality configured for: $assistant_name"
# ──────────────────────────────────────────────────────────
# STEP 10 — Interface options
# ──────────────────────────────────────────────────────────
print_step "STEP 11/12 — Interface Options"
echo ""
echo " These options control what messages appear in the chat."
echo " Defaults are optimized for a clean, distraction-free experience."
echo ""
local hide_thinking="true"
local hide_footer="true"
if ask_yn "Show '💭 Thinking...' messages when the assistant is reasoning?" "N"; then
hide_thinking="false"
print_ok "Thinking messages: shown"
else
hide_thinking="true"
print_ok "Thinking messages: hidden (default)"
fi
echo ""
if ask_yn "Show run footer (model + elapsed time) after each response?" "N"; then
hide_footer="false"
print_ok "Footer: shown (e.g. 🛠️ Build · 🤖 opencode/big-pickle · 🕒 4.2s)"
else
hide_footer="true"
print_ok "Footer: hidden (default)"
fi
# ──────────────────────────────────────────────────────────
# STEP 11 — Skills from OpenClaw ecosystem (optional)
# ──────────────────────────────────────────────────────────
print_step "STEP 12/12 — OpenClaw Skills (optional)"
echo ""
echo " Your assistant already includes 3 built-in skills:"
echo " • web-search, code-review, daily-summary"
echo ""
echo " You can install additional skills from the OpenClaw ecosystem."
echo " Skills are compatible with any SKILL.md format (ClawHub, GitHub, etc.)"
echo ""
echo " Example sources:"
echo " github.com/alirezarezvani/claude-skills (235+ skills)"
echo " github.com/topics/openclaw-skills (700+ repos)"
echo ""
local extra_skill_urls=()
if ask_yn "Install additional skills from GitHub URLs?" "N"; then
echo ""
echo " Paste a raw SKILL.md URL (or GitHub blob URL). Enter to finish."
echo " Example: https://raw.githubusercontent.com/alirezarezvani/claude-skills/main/engineering/git-worktree-manager/SKILL.md"
echo ""
while true; do
local skill_url
skill_url=$(ask "Skill URL (Enter to finish)" "")
if [[ -z "$skill_url" ]]; then
break
fi
extra_skill_urls+=("$skill_url")
print_ok "Added: $skill_url"
done
fi
# ──────────────────────────────────────────────────────────
# SUMMARY and launch
# ──────────────────────────────────────────────────────────
print_step "SUMMARY — Review Configuration"
echo ""
echo -e "${BOLD} Configuration Summary${NC}"
echo " ─────────────────────────────────────────"
echo " Bot language: $bot_locale"
if $use_telegram; then
echo " Telegram: enabled (@${bot_username}, user ${user_id})"
else
echo " Telegram: disabled"
fi
if $use_whatsapp; then
echo " WhatsApp: enabled (number: $whatsapp_number)"
else
echo " WhatsApp: disabled"
fi
echo " AI model: $model_provider/$model_id"
echo " TTS: ${tts_provider:-disabled}"
echo " STT: ${stt_api_url:-disabled}"
echo " STT hide text: $stt_hide_recognized"
echo " Timezone: $timezone"
echo " Assistant name: $assistant_name"
echo " Thinking msgs: $([ "$hide_thinking" = "true" ] && echo "hidden" || echo "shown")"
echo " Run footer: $([ "$hide_footer" = "true" ] && echo "hidden" || echo "shown")"
echo " Extra skills: ${#extra_skill_urls[@]}"
echo " ─────────────────────────────────────────"
echo ""
if ! ask_yn "Everything looks correct? Proceed?"; then
echo "Setup cancelled. Run ./setup.sh again to restart."
exit 0
fi
# ──────────────────────────────────────────────────────────
# GENERATE FILES
# ──────────────────────────────────────────────────────────
echo ""
echo "Generating configuration files..."
# Generate .env