Repository navigation
Expand file tree
/
Copy pathinit.sh
More file actions
executable file
·1603 lines (1463 loc) · 75.9 KB
/
Copy pathinit.sh
File metadata and controls
executable file
·1603 lines (1463 loc) · 75.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
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
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd) || exit 1
CLEANUP_FILES="" # .env heredoc tmp (registered when created); swept by the traps.
# Unquoted expansion in the traps is safe: the whitespace guard
# rejects checkouts with spaces in their path.
trap 'rm -f "$SCRIPT_DIR/.env.tmp.$$" ${CLEANUP_FILES:-} 2>/dev/null || true; chmod 700 "$SCRIPT_DIR/mintlayer-data/prefs" 2>/dev/null || true' EXIT
trap 'rm -f "$SCRIPT_DIR/.env.tmp.$$" ${CLEANUP_FILES:-} 2>/dev/null || true; chmod 700 "$SCRIPT_DIR/mintlayer-data/prefs" 2>/dev/null || true; exit 130' INT
trap 'rm -f "$SCRIPT_DIR/.env.tmp.$$" ${CLEANUP_FILES:-} 2>/dev/null || true; chmod 700 "$SCRIPT_DIR/mintlayer-data/prefs" 2>/dev/null || true; exit 143' TERM
trap 'rm -f "$SCRIPT_DIR/.env.tmp.$$" ${CLEANUP_FILES:-} 2>/dev/null || true; chmod 700 "$SCRIPT_DIR/mintlayer-data/prefs" 2>/dev/null || true; exit 129' HUP
# Sweep this run's .env temp copy (credentials mid-rewrite) on any exit.
# INT/TERM clean up and then exit - a bare cleanup trap would resume the
# script after Ctrl-C. $$ matches env_set's temp file name below.
# EXIT/INT/TERM also restore 0700 on the prefs dir: the credential-seeding
# step widens it to 0777 for a rootful container, and an interrupted run
# would otherwise leave a world-writable credentials directory behind.
# Log window for the Tailscale login-URL scrape: URLs printed before this
# run started may be consumed/expired from an earlier attempt.
SCRIPT_START_EPOCH=$(date +%s)
# Anchor to the checkout: every path below (.env, bind mounts, compose
# project dir) assumes repo-root CWD, so `bash /path/to/init.sh` from
# elsewhere would otherwise write .env into the wrong directory.
cd -- "$(dirname -- "${BASH_SOURCE[0]}")" || exit 1
# Best-effort sweep of residue from a SIGKILLed/aborted earlier run (the
# traps only cover this run's pid). Only files idle for over an hour are
# swept: a concurrent live run's temp is recent and must survive (its rename
# depends on it). Runs AFTER the anchor so it sweeps the checkout's
# directory, not the caller's.
find . -maxdepth 1 -name '.env.tmp.*' -mmin +60 -delete 2>/dev/null || true
# ─────────────────────────────────────────────────────────────────────────────
# Mintlayer Nexus - interactive setup
# Inspired by the Astro create CLI style
# ─────────────────────────────────────────────────────────────────────────────
# ── Colors & symbols ──────────────────────────────────────────────────────────
RESET=$'\033[0m'
BOLD=$'\033[1m'
DIM=$'\033[2m'
CYAN=$'\033[36m'
GREEN=$'\033[32m'
YELLOW=$'\033[33m'
RED=$'\033[31m'
GRAY=$'\033[90m'
step() { printf "\n${CYAN}◆${RESET} ${BOLD}%s${RESET}\n" "$*"; }
ask() { printf "${CYAN}◇${RESET} ${BOLD}%s${RESET}\n" "$*"; }
hint() { printf "${GRAY}│ %s${RESET}\n" "$*"; }
ok() { printf "${GREEN}◈${RESET} %s\n" "$*"; }
warn() { printf "${YELLOW}▲${RESET} %s\n" "$*"; }
err() { printf "${RED}✗${RESET} %s\n" "$*" >&2; }
divider() { printf "${GRAY}└─────────────────────────────────────────${RESET}\n"; }
prompt() {
# prompt <var_name> <question> [default]
local var="$1" question="$2" default="${3:-}"
if [[ -n "$default" ]]; then
printf "${CYAN}│${RESET} ${question} ${GRAY}(${default})${RESET} "
else
printf "${CYAN}│${RESET} ${question} "
fi
read -r input
if [[ -z "$input" && -n "$default" ]]; then
printf -v "$var" '%s' "$default"
else
printf -v "$var" '%s' "$input"
fi
}
prompt_secret() {
local var="$1" question="$2" input
printf "${CYAN}│${RESET} ${question} "
read -rs input
printf '\n'
printf -v "$var" '%s' "$input"
}
choose() {
# choose <var_name> <question> <option1> <option2> [...]
local var="$1"; shift
local question="$1"; shift
local options=("$@")
printf "${CYAN}│${RESET}\n"
printf "${CYAN}│${RESET} %s\n" "$question"
local i=1
for opt in "${options[@]}"; do
printf "${CYAN}│${RESET} ${GRAY}%d)${RESET} %s\n" "$i" "$opt"
(( i++ ))
done
while true; do
printf "${CYAN}│${RESET} ${GRAY}›${RESET} "
read -r choice
if [[ "$choice" =~ ^[0-9]+$ ]] && (( choice >= 1 && choice <= ${#options[@]} )); then
printf -v "$var" '%s' "${options[$((choice-1))]}"
break
fi
printf "${CYAN}│${RESET} ${RED}Please enter a number between 1 and %d${RESET}\n" "${#options[@]}"
done
}
confirm() {
# confirm <var_name> <question> <default Y|N>
local var="$1" question="$2" default="${3:-Y}"
local hint_str
if [[ "$default" == "Y" ]]; then hint_str="Y/n"; else hint_str="y/N"; fi
printf "${CYAN}│${RESET} %s ${GRAY}[%s]${RESET} " "$question" "$hint_str"
read -r input
input="${input:-$default}"
if [[ "$input" =~ ^[Yy] ]]; then
printf -v "$var" '%s' "yes"
else
printf -v "$var" '%s' "no"
fi
}
rand_pass() {
# Generate a 32-char alphanumeric password
if command -v openssl &>/dev/null; then
openssl rand -base64 48 | tr -dc 'a-zA-Z0-9' | head -c 32
else
# Bounded urandom read: an unbounded 'cat /dev/urandom | tr | head'
# SIGPIPEs under 'set -o pipefail' (head exits early, the producer
# dies mid-write, the script aborts). 512 bytes yield ~120 alnum
# chars, far more than needed, and small enough to fit a pipe buffer.
head -c 512 /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 32
fi
}
# Real shell assignment (the .env heredoc below only writes the TEXT
# 'PROJECT_DIR_HOST=...'), needed by the whitespace guard early in the
# script and by the feature-enabler .env consumers.
PROJECT_DIR_HOST=$(pwd)
case "$PROJECT_DIR_HOST" in
*[[:space:]]*)
err "The repository path contains whitespace: $PROJECT_DIR_HOST"
err "Settings-page feature toggles will not work."
err "Move this checkout to a path without spaces and re-run init.sh."
exit 1
;;
esac
# ── Detect OS ─────────────────────────────────────────────────────────────────
detect_os() {
case "$(uname -s)" in
Darwin) echo "macos" ;;
Linux)
if grep -qi microsoft /proc/version 2>/dev/null; then
echo "wsl"
else
echo "linux"
fi
;;
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
*) echo "unknown" ;;
esac
}
# ── Docker install instructions ───────────────────────────────────────────────
docker_install_hint() {
local os
os=$(detect_os)
printf "\n"
case "$os" in
macos)
printf "${BOLD} Install Docker Desktop for Mac:${RESET}\n"
printf " 1. Download from https://docs.docker.com/desktop/install/mac-install/\n"
printf " 2. Open the .dmg and drag Docker to Applications\n"
printf " 3. Launch Docker Desktop and wait for the whale icon to stop animating\n"
printf " 4. Re-run this script\n"
;;
wsl)
printf "${BOLD} Install Docker Desktop for Windows (with WSL 2 backend):${RESET}\n"
printf " 1. Download from https://docs.docker.com/desktop/install/windows-install/\n"
printf " 2. Enable 'Use the WSL 2 based engine' in Docker Desktop settings\n"
printf " 3. Ensure your WSL distro is enabled under Resources → WSL Integration\n"
printf " 4. Re-run this script inside WSL\n"
;;
windows)
printf "${BOLD} Install Docker Desktop for Windows:${RESET}\n"
printf " 1. Download from https://docs.docker.com/desktop/install/windows-install/\n"
printf " 2. Run the installer and follow the prompts\n"
printf " 3. Re-run this script\n"
;;
linux)
printf "${BOLD} Install Docker Engine on Linux:${RESET}\n"
printf " Ubuntu/Debian:\n"
printf " curl -fsSL https://get.docker.com | sh\n"
printf " sudo usermod -aG docker \$USER # then log out and back in\n"
printf "\n"
printf " Or follow the official guide for your distro:\n"
printf " https://docs.docker.com/engine/install/\n"
printf "\n"
printf " After installing, re-run this script.\n"
;;
*)
printf " Visit https://docs.docker.com/get-docker/ for installation instructions.\n"
;;
esac
printf "\n"
}
# ── Prerequisite checks ───────────────────────────────────────────────────────
check_prereqs() {
# Check Docker first - give OS-specific install instructions if missing
if ! command -v docker &>/dev/null; then
err "Docker is not installed or not in PATH."
docker_install_hint
exit 1
fi
# Docker found - make sure the daemon is actually running
if ! docker info &>/dev/null 2>&1; then
err "Docker is installed but the daemon is not running."
local os
os=$(detect_os)
case "$os" in
macos|windows) printf " ${YELLOW}▲${RESET} Start Docker Desktop and wait for it to finish loading, then re-run this script.\n\n" ;;
wsl) printf " ${YELLOW}▲${RESET} Start Docker Desktop on Windows (WSL backend), then re-run this script.\n\n" ;;
linux) printf " ${YELLOW}▲${RESET} Run: ${GRAY}sudo systemctl start docker${RESET}\n\n" ;;
esac
exit 1
fi
# Accept both "docker compose" (v2) and "docker-compose" (v1)
if ! docker compose version &>/dev/null 2>&1 && ! command -v docker-compose &>/dev/null; then
err "Docker Compose is not available."
printf " Docker Compose v2 ships with Docker Desktop.\n"
printf " On Linux, install it with: ${GRAY}sudo apt install docker-compose-plugin${RESET}\n"
printf " Or see: https://docs.docker.com/compose/install/\n\n"
exit 1
fi
command -v node &>/dev/null || {
err "Node.js is not installed (required for password hashing)."
printf " Install Node.js v18+ from https://nodejs.org or via your package manager.\n\n"
exit 1
}
# env_set() needs fs.rmSync (>= 14.14) and the Tailscale status parser uses
# optional chaining (>= 14): enforce the advertised floor, not just presence.
node -e 'process.exit(parseInt(process.versions.node, 10) < 18 ? 1 : 0)' || {
err "Node.js v18+ is required."
printf " Install Node.js v18+ from https://nodejs.org or via your package manager.\n\n"
exit 1
}
}
# ── Determine compose command ─────────────────────────────────────────────────
compose_cmd() {
if docker compose version &>/dev/null 2>&1; then
echo "docker compose"
else
echo "docker-compose"
fi
}
# ── Update a single KEY=VALUE line in .env ──────────────
env_set() {
# env_set KEY VALUE - rewrite "KEY=" in .env, appending when absent.
# Uses node (a checked prerequisite) instead of sed -i: BSD and GNU sed
# disagree on how -i takes its backup argument. The temp file name comes
# from bash's $$ so the EXIT trap sweeps crash residue. KEY/VALUE travel
# via the environment, not argv: `ps` shows argv world-readable, and a
# future call site passing a secret must not leak through the process
# table (/proc/<pid>/environ is owner-only).
OCR_ENV_SET_KEY="$1" OCR_ENV_SET_VALUE="$2" OCR_ENV_SET_TMP=".env.tmp.$$" \
node -e '
const fs = require("fs");
const key = process.env.OCR_ENV_SET_KEY;
const value = process.env.OCR_ENV_SET_VALUE;
const tmp = process.env.OCR_ENV_SET_TMP;
// Validate before touching .env: an embedded newline would corrupt every
// line after the rewritten key.
if (/[\r\n]/.test(key) || /[\r\n]/.test(value)) {
console.error("env_set: key and value must not contain newlines");
process.exit(1);
}
if (/\$/.test(key) || /\$/.test(value)) {
console.error("env_set: key and value must not contain $ (compose would expand it)");
process.exit(1);
}
let lines;
try {
lines = fs.readFileSync(".env", "utf8").replace(/\r\n/g, "\n").split("\n");
} catch (err) {
console.error("env_set: cannot read .env - run init.sh first: " + err.message);
process.exit(1);
}
let found = false;
const rewritten = lines.map((line) => {
// Match indented (compose trims keys) and `export KEY=` lines too, so a
// hand-edited .env is replaced in place instead of duplicated.
const stripped = line.trim().replace(/^export\s+/, "");
if (stripped.startsWith(key + "=")) {
found = true;
return key + "=" + value;
}
return line;
});
if (!found) rewritten.push(key + "=" + value);
if (rewritten[rewritten.length - 1] !== "") rewritten.push("");
// Atomic replace: an interrupted truncate-in-place write would destroy
// the SESSION_SECRET/RPC/DB credentials in .env. mode 0600 applies at
// creation (umask cannot widen it); rm clears pid-reuse staleness and
// the EXIT trap (same bash $$ via the tmp env var) sweeps residue.
// 'wx' = O_CREAT|O_EXCL: a racing local user could swap the predictable
// .env.tmp.<pid> path for a symlink in the rm->write window - O_EXCL
// refuses the path instead of following it, aborting the rewrite rather
// than leaking credentials to an attacker-chosen target.
fs.rmSync(tmp, { force: true });
const fd = fs.openSync(tmp, "wx", 0o600);
fs.writeFileSync(fd, rewritten.join("\n"));
// fsync before rename: without it a power loss can persist the rename
// while the temp file data blocks are still in page cache.
fs.fsyncSync(fd);
fs.closeSync(fd);
fs.renameSync(tmp, ".env");
'
}
# lower STRING - lowercase without bash-4 ${var,,} (macOS ships bash 3.2).
lower() { printf '%s' "$1" | tr '[:upper:]' '[:lower:]'; }
# password_reject_reason VALUE - print the rejection reason for a user-chosen
# password (empty = acceptable). Rejects $ because compose expands $VAR/
# ${VAR} in .env values, which would corrupt the credential on write.
password_reject_reason() {
if [[ ${#1} -lt 8 ]]; then
printf "Password must be at least 8 characters"
elif [[ "$1" == *'$'* ]]; then
printf 'Password must not contain $ - compose would expand it in .env'
elif [[ "$1" == *' #'* ]]; then
printf 'Password must not contain " #" - compose treats it as an inline comment'
elif [[ "$1" == '"'* || "$1" == "'"* ]]; then
printf 'Password must not start with a quote - compose strips it from .env'
elif [[ "$1" =~ ^[[:space:]] || "$1" =~ [[:space:]]$ ]]; then
printf "Password must not start or end with whitespace - compose trims it"
fi
}
# api_port_reject_reason VALUE - conflict/validity message for the indexer
# REST API port (empty = acceptable). Called after the access mode is chosen,
# so the TLS-gateway reservation only applies in that mode.
api_port_reject_reason() {
if ! [[ "$1" =~ ^[0-9]{1,5}$ ]] || (( 10#$1 < 1 || 10#$1 > 65535 )); then
printf "Enter a valid port number (1-65535)"
elif (( 10#$1 == 10#$WEB_GUI_PORT )); then
printf "Port %s is taken by the web GUI - pick another" "$1"
elif [[ "$WEB_GUI_TLS" == "true" && "$1" == "443" ]]; then
printf "Port 443 is reserved for the HTTPS gateway - pick another"
fi
}
# show_totp_qr - render the TOTP URI as a terminal QR, falling back to the
# plain URI: qrencode -t ANSIUTF8 needs qrencode >= 3.4, and an older build
# used to abort the whole script mid-setup instead of degrading.
show_totp_qr() {
if command -v qrencode &>/dev/null && \
echo "$TOTP_URI" | qrencode -t ANSIUTF8 2>/dev/null | sed "s/^/${CYAN}│${RESET} /"; then
return 0
fi
printf "${CYAN}│${RESET} ${GRAY}%s${RESET}\n" "$TOTP_URI"
printf "${CYAN}│${RESET} ${DIM}(Install qrencode >= 3.4 for a scannable QR code in the terminal)${RESET}\n"
return 0
}
# ─────────────────────────────────────────────────────────────────────────────
# Banner
# ─────────────────────────────────────────────────────────────────────────────
clear 2>/dev/null || true
printf "\n"
printf "${CYAN}${BOLD}"
printf " ███╗ ███╗██╗███╗ ██╗████████╗██╗ █████╗ ██╗ ██╗███████╗██████╗ \n"
printf " ████╗ ████║██║████╗ ██║╚══██╔══╝██║ ██╔══██╗╚██╗ ██╔╝██╔════╝██╔══██╗\n"
printf " ██╔████╔██║██║██╔██╗ ██║ ██║ ██║ ███████║ ╚████╔╝ █████╗ ██████╔╝\n"
printf " ██║╚██╔╝██║██║██║╚██╗██║ ██║ ██║ ██╔══██║ ╚██╔╝ ██╔══╝ ██╔══██╗\n"
printf " ██║ ╚═╝ ██║██║██║ ╚████║ ██║ ███████╗██║ ██║ ██║ ███████╗██║ ██║\n"
printf " ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ ╚═╝ ╚══════╝╚═╝ ╚═╝\n"
printf "${RESET}"
printf "\n"
printf " ${BOLD}Web GUI Setup${RESET} ${GRAY}- node + wallet-rpc-daemon + web interface${RESET}\n"
printf "\n"
printf "${GRAY} This script writes your .env and starts the Docker stack.${RESET}\n"
printf "\n"
check_prereqs
# ─────────────────────────────────────────────────────────────────────────────
# Step 1 - Network
# ─────────────────────────────────────────────────────────────────────────────
step "Network"
hint "mainnet uses real ML tokens; testnet is for experimentation"
hint ""
NETWORK_CHOICE=""
choose NETWORK_CHOICE "Which network?" \
"mainnet - real funds" \
"testnet - for testing, no real value"
case "$NETWORK_CHOICE" in
"mainnet - real funds") NETWORK="mainnet" ;;
*) NETWORK="testnet" ;;
esac
divider
# ─────────────────────────────────────────────────────────────────────────────
# Step 2 - Passwords
# ─────────────────────────────────────────────────────────────────────────────
step "Passwords"
hint "Two internal RPC services need authentication."
hint ""
USE_RANDOM_PASSWORDS="yes"
confirm USE_RANDOM_PASSWORDS "Generate secure random passwords automatically?" "Y"
if [[ "$USE_RANDOM_PASSWORDS" == "yes" ]]; then
NODE_RPC_PASSWORD=$(rand_pass)
WALLET_RPC_PASSWORD=$(rand_pass)
ok "Generated random passwords (saved to .env)"
else
ask "Node RPC password"
hint "Used by node-daemon - not exposed outside Docker"
prompt_secret NODE_RPC_PASSWORD "Password:"
reason="$(password_reject_reason "$NODE_RPC_PASSWORD")"
while [[ -n "$reason" ]]; do
printf "${CYAN}│${RESET} ${RED}%s${RESET}\n" "$reason"
prompt_secret NODE_RPC_PASSWORD "Password:"
reason="$(password_reject_reason "$NODE_RPC_PASSWORD")"
done
ask "Wallet RPC password"
hint "Used by wallet-rpc-daemon - not exposed outside Docker"
prompt_secret WALLET_RPC_PASSWORD "Password:"
reason="$(password_reject_reason "$WALLET_RPC_PASSWORD")"
while [[ -n "$reason" ]]; do
printf "${CYAN}│${RESET} ${RED}%s${RESET}\n" "$reason"
prompt_secret WALLET_RPC_PASSWORD "Password:"
reason="$(password_reject_reason "$WALLET_RPC_PASSWORD")"
done
fi
NODE_RPC_USERNAME="node_user"
WALLET_RPC_USERNAME="wallet_user"
divider
# ─────────────────────────────────────────────────────────────────────────────
# Step 3 - Web UI access (password + TOTP 2FA)
# ─────────────────────────────────────────────────────────────────────────────
step "Web UI access"
hint "Protect the wallet interface with a password and authenticator app (TOTP 2FA)."
hint ""
ask "Web UI password"
hint "Used to sign in to the wallet web interface."
hint "Choose a strong password - this guards access to your wallet."
UI_PASSWORD=""
UI_PASSWORD_CONFIRM=""
prompt_secret UI_PASSWORD "Password:"
reason="$(password_reject_reason "$UI_PASSWORD")"
while [[ -n "$reason" ]]; do
printf "${CYAN}│${RESET} ${RED}%s${RESET}\n" "$reason"
prompt_secret UI_PASSWORD "Password:"
reason="$(password_reject_reason "$UI_PASSWORD")"
done
prompt_secret UI_PASSWORD_CONFIRM "Confirm password:"
while [[ "$UI_PASSWORD" != "$UI_PASSWORD_CONFIRM" ]]; do
printf "${CYAN}│${RESET} ${RED}Passwords do not match, try again${RESET}\n"
prompt_secret UI_PASSWORD "Password:"
reason="$(password_reject_reason "$UI_PASSWORD")"
while [[ -n "$reason" ]]; do
printf "${CYAN}│${RESET} ${RED}%s${RESET}\n" "$reason"
prompt_secret UI_PASSWORD "Password:"
reason="$(password_reject_reason "$UI_PASSWORD")"
done
prompt_secret UI_PASSWORD_CONFIRM "Confirm password:"
done
printf "${CYAN}│${RESET}\n"
hint "Hashing password (this may take a moment)..."
# Password is passed via env, not argv - keeps it out of the host process list.
UI_PASSWORD_HASH=$(UI_PASSWORD="$UI_PASSWORD" node -e "
const c = require('crypto');
const salt = c.randomBytes(32).toString('hex');
c.pbkdf2(process.env.UI_PASSWORD, salt, 210000, 64, 'sha512', (err, key) => {
if (err) { process.stderr.write(err.message + '\n'); process.exit(1); }
process.stdout.write('pbkdf2:sha512:210000:' + salt + ':' + key.toString('hex'));
});
")
[[ -n "$UI_PASSWORD_HASH" ]] || { err "Password hashing produced no output"; exit 1; }
ok "Password hashed"
# Generate TOTP secret (20 random bytes → base32)
UI_TOTP_SECRET=$(node -e "
const bytes = require('crypto').randomBytes(20);
const alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
let result = '', bits = 0, value = 0;
for (let i = 0; i < bytes.length; i++) {
value = (value << 8) | bytes[i];
bits += 8;
while (bits >= 5) {
result += alpha[(value >>> (bits - 5)) & 31];
bits -= 5;
}
}
if (bits > 0) result += alpha[(value << (5 - bits)) & 31];
process.stdout.write(result);
")
# Generate session signing secret (urandom fallback: openssl can be
# absent on minimal hosts and this runs after every question was answered)
SESSION_SECRET=$(openssl rand -hex 32 2>/dev/null || head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n')
# Construct the otpauth URI
TOTP_URI="otpauth://totp/Mintlayer%20Nexus?secret=${UI_TOTP_SECRET}&issuer=Mintlayer"
printf "${CYAN}│${RESET}\n"
[[ -n "$UI_TOTP_SECRET" ]] || { err "TOTP secret generation failed"; exit 1; }
ok "TOTP secret generated"
printf "${CYAN}│${RESET}\n"
printf "${CYAN}│${RESET} ${BOLD}Scan this with Google Authenticator, Authy, or any TOTP app:${RESET}\n"
printf "${CYAN}│${RESET}\n"
# Show QR code if qrencode is available, otherwise show the URI
show_totp_qr
printf "${CYAN}│${RESET}\n"
hint "Or enter the secret manually: ${BOLD}${UI_TOTP_SECRET}${RESET}"
printf "${CYAN}│${RESET}\n"
warn "Scan this QR code NOW before continuing - it will not be shown again."
printf "${CYAN}│${RESET}\n"
SCANNED="no"
confirm SCANNED "I have scanned the QR code / saved the TOTP secret" "N"
while [[ "$SCANNED" != "yes" ]]; do
printf "${CYAN}│${RESET} ${RED}Please scan the QR code or save the secret before continuing.${RESET}\n"
printf "${CYAN}│${RESET}\n"
# Re-display the URI in case they need it again
show_totp_qr
printf "${CYAN}│${RESET}\n"
confirm SCANNED "I have scanned the QR code / saved the TOTP secret" "N"
done
ok "2FA configured"
divider
# ─────────────────────────────────────────────────────────────────────────────
# Step 4 - Web GUI port
# ─────────────────────────────────────────────────────────────────────────────
step "Web interface"
ask "Port for the web GUI"
hint "The Astro web interface will be available at http://localhost:<port>"
prompt WEB_GUI_PORT "Port:" "4321"
# Validate it's a number
while ! [[ "$WEB_GUI_PORT" =~ ^[0-9]{1,5}$ ]] || (( 10#$WEB_GUI_PORT < 1 || 10#$WEB_GUI_PORT > 65535 )); do
printf "${CYAN}│${RESET} ${RED}Enter a valid port number (1-65535)${RESET}\n"
prompt WEB_GUI_PORT "Port:" "4321"
done
# The TLS gateway (mode chosen below) publishes host port 443 - a GUI port
# of 443 would collide only after the mode is picked, so reserve it now.
if (( 10#$WEB_GUI_PORT == 443 )); then
warn "Port 443 is reserved for the HTTPS gateway - using 4321 for the GUI."
WEB_GUI_PORT="4321"
fi
ask "Expose the web GUI to your network?"
# The Tailscale sidecar runs kernel-mode networking and needs a TUN device
# (Docker Desktop's VM provides one; native Linux almost always does).
# Unprivileged LXC, rootless Docker and some NAS setups don't - offering the
# option there would only crash-loop the sidecar.
TAILSCALE_AVAILABLE="true"
if [[ "$(detect_os)" == "linux" && ! -e /dev/net/tun ]]; then
TAILSCALE_AVAILABLE="false"
fi
hint "Access modes:"
hint " localhost only - the GUI is reachable solely from this machine;"
hint " open it through an SSH tunnel. Most secure."
hint " LAN over HTTPS - other devices open it at https://<hostname>; Caddy"
hint " terminates TLS with a local Certificate Authority (works without a"
hint " public domain). Browsers warn once until you import the CA root,"
hint " downloadable from Settings -> HTTPS after setup."
hint " Tailnet (Tailscale) - the GUI joins your tailnet; any device logged"
hint " into it opens https://<name>.<tailnet>.ts.net with valid HTTPS."
hint " Nothing is published to the LAN or the internet. Needs a (free)"
hint " Tailscale account with MagicDNS + HTTPS certificates enabled."
hint " LAN plain HTTP - not recommended: traffic is unencrypted and the"
hint " session cookie is refused on non-localhost origins, so sign-in only"
hint " works from this machine anyway."
if [[ "$TAILSCALE_AVAILABLE" != "true" ]]; then
hint "Tailnet (Tailscale) is unavailable on this host: /dev/net/tun is"
hint " missing, so the sidecar cannot start."
fi
hint "Running your own TLS proxy on a public domain? Pick 'localhost only'"
hint "and set WEB_GUI_HOST + PASSKEY_* in .env manually (see .env.example)."
ACCESS_MODE_OPTIONS=("localhost only (SSH tunnel)" "LAN over HTTPS (Caddy local CA)")
if [[ "$TAILSCALE_AVAILABLE" == "true" ]]; then
ACCESS_MODE_OPTIONS+=("Tailnet (Tailscale - remote access)")
fi
ACCESS_MODE_OPTIONS+=("LAN plain HTTP (not recommended)")
ACCESS_CHOICE=""
choose ACCESS_CHOICE "Access mode:" "${ACCESS_MODE_OPTIONS[@]}"
WEB_GUI_TLS="false"
WEB_GUI_BIND="127.0.0.1"
WEB_GUI_HOST="localhost"
TRUST_PROXY=""
TAILSCALE_ENABLED="false"
TAILSCALE_HOSTNAME="nexus"
TS_AUTHKEY=""
TS_EXTRA_ARGS=""
case "$ACCESS_CHOICE" in
*"LAN over HTTPS"*)
WEB_GUI_TLS="true"
TRUST_PROXY="true"
ask "Hostname for the HTTPS certificate"
hint "Must resolve to this machine from your devices, e.g. ml1.local"
hint "(mDNS) or an entry in your router's DNS / your device's hosts file."
prompt WEB_GUI_HOST "Hostname:" "$(hostname -s 2>/dev/null || echo mintlayer-gui).local"
# Hostname flows into the Caddyfile (pre-parse textual substitution),
# docker-compose env interpolation, and the WebAuthn RP ID - so it must
# be a plain lowercase DNS name. Uppercase is normalized; everything
# else invalid is re-asked. (lower(), not ${var,,}: macOS ships bash 3.2.)
WEB_GUI_HOST="$(lower "$WEB_GUI_HOST")"
while ! [[ "$WEB_GUI_HOST" =~ ^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?(\.[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?)+$ ]]; do
printf "${CYAN}│${RESET} ${RED}Enter a valid hostname (letters, digits, dots, hyphens - uppercase is lowercased automatically; no ports, spaces or underscores)${RESET}\n"
prompt WEB_GUI_HOST "Hostname:" "$(hostname -s 2>/dev/null || echo mintlayer-gui).local"
WEB_GUI_HOST="$(lower "$WEB_GUI_HOST")"
done
warn "The GUI stays bound to 127.0.0.1 - only the HTTPS gateway (port 443) is exposed."
hint "Always open https://${WEB_GUI_HOST} - plain http:// (port 80) is not published."
;;
*"Tailnet (Tailscale"*)
TAILSCALE_ENABLED="true"
# Traffic arrives through the shipped sidecar, which overwrites
# X-Forwarded-For - the same trust model as the caddy gateway.
TRUST_PROXY="true"
ask "Tailscale node name"
hint "Devices on your tailnet will open https://<name>.<tailnet>.ts.net."
prompt TAILSCALE_HOSTNAME "Name:" "nexus"
# Flows into the sidecar hostname, the ts.net certificate name and
# MagicDNS - a plain lowercase DNS label only.
TAILSCALE_HOSTNAME="$(lower "$TAILSCALE_HOSTNAME")"
while ! [[ "$TAILSCALE_HOSTNAME" =~ ^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$ ]]; do
printf "${CYAN}│${RESET} ${RED}Enter a short DNS name (letters, digits, hyphens - uppercase is lowercased automatically)${RESET}\n"
prompt TAILSCALE_HOSTNAME "Name:" "nexus"
TAILSCALE_HOSTNAME="$(lower "$TAILSCALE_HOSTNAME")"
done
printf "${CYAN}│${RESET}\n"
TS_AUTH_CHOICE=""
choose TS_AUTH_CHOICE "How should the node join your tailnet?" \
"Login URL - approve once in the browser, nothing secret is stored" \
"Auth key - paste a key from the Tailscale admin console (headless)"
TS_AUTHKEY=""
if [[ "$TS_AUTH_CHOICE" == *"Auth key"* ]]; then
ask "Tailscale auth key"
hint "Admin console -> Settings -> Keys. The key lands in .env"
hint "(chmod 600, gitignored). Leave blank to use the login URL instead."
prompt_secret TS_AUTHKEY "Auth key:"
# Paste hygiene: strip surrounding whitespace (trailing spaces, CR from Windows clips).
TS_AUTHKEY="$(printf '%s' "$TS_AUTHKEY" | tr -d '[:space:]')"
# Only plain tskey-auth-... tokens: the value lands unquoted in .env,
# where compose expands $VAR/${VAR} references in values - a malformed
# paste would corrupt interpolation or leak other secrets from this
# file into the sidecar environment.
if [[ -n "$TS_AUTHKEY" && ! "$TS_AUTHKEY" =~ ^tskey-auth-[A-Za-z0-9_-]+$ ]]; then
warn "That does not look like a Tailscale auth key (expected tskey-auth-...)."
hint "Falling back to the interactive login-URL flow."
TS_AUTHKEY=""
fi
fi
warn "The GUI stays bound to 127.0.0.1 on the host - only the Tailscale"
warn "sidecar reaches the stack, and only from inside your tailnet."
hint "Note: some hosts (unprivileged LXC, rootless Docker) accept the"
hint "/dev/net/tun device but deny its configuration - the sidecar then"
hint "restart-loops. If that happens: docker compose logs tailscale, and"
hint "re-run ./init.sh to pick a different access mode."
;;
*"LAN plain HTTP"*)
WEB_GUI_BIND="0.0.0.0"
warn "GUI will be reachable from other machines (plain HTTP)."
warn "Login requires a Secure session cookie, which browsers refuse on"
warn "plain HTTP for non-localhost origins - sign-in works only locally."
;;
*)
;;
esac
# Passkeys (WebAuthn) need a proper DNS hostname - they never work from raw
# IPs. The HTTPS mode implies one; localhost/plain-HTTP keep passkeys off.
# Derive passkey config from hostname
if [[ -z "$WEB_GUI_HOST" || "$WEB_GUI_HOST" == "localhost" ]]; then
WEB_GUI_HOST="localhost"
PASSKEY_RP_ID="localhost"
PASSKEY_ORIGIN="http://localhost:${WEB_GUI_PORT}"
else
PASSKEY_RP_ID="${WEB_GUI_HOST}"
PASSKEY_ORIGIN="https://${WEB_GUI_HOST}"
fi
divider
# ─────────────────────────────────────────────────────────────────────────────
# Step 5 - Indexer
# ─────────────────────────────────────────────────────────────────────────────
step "Indexer stack"
hint "The indexer adds PostgreSQL + blockchain scanner + REST API."
hint "It enables Token Management and Trading in the web UI."
hint "Requires more disk space and memory."
hint ""
hint "Disable it only if you don't need to issue tokens or trade."
hint "Staking, sending, and receiving work fine without it."
hint ""
ENABLE_INDEXER="yes"
confirm ENABLE_INDEXER "Enable the indexer? (disable only if you don't need Token Management or Trading)" "Y"
API_WEB_SERVER_PORT="3000"
if [[ "$ENABLE_INDEXER" == "yes" ]]; then
if [[ "$USE_RANDOM_PASSWORDS" == "yes" ]]; then
POSTGRES_PASSWORD=$(rand_pass)
ok "Generated random PostgreSQL password (saved to .env)"
else
ask "PostgreSQL password"
prompt_secret POSTGRES_PASSWORD "Password:"
reason="$(password_reject_reason "$POSTGRES_PASSWORD")"
while [[ -n "$reason" ]]; do
printf "${CYAN}│${RESET} ${RED}%s${RESET}\n" "$reason"
prompt_secret POSTGRES_PASSWORD "Password:"
reason="$(password_reject_reason "$POSTGRES_PASSWORD")"
done
fi
ask "Port for the blockchain REST API"
prompt API_WEB_SERVER_PORT "Port:" "3000"
# Same validation as the web GUI port: garbage here breaks the compose
# port mapping (127.0.0.1:${API_WEB_SERVER_PORT:-3000}:3000).
reason="$(api_port_reject_reason "$API_WEB_SERVER_PORT")"
while [[ -n "$reason" ]]; do
printf "${CYAN}│${RESET} ${RED}%s${RESET}\n" "$reason"
prompt API_WEB_SERVER_PORT "Port:" "3000"
reason="$(api_port_reject_reason "$API_WEB_SERVER_PORT")"
done
else
# Inert while the indexer profile is off, but pre-filled so a later manual
# `docker compose --profile indexer up -d` works instead of crash-looping
# postgres (it refuses an empty superuser password). Parity with the
# deploy flavors.
POSTGRES_PASSWORD=$(rand_pass)
fi
divider
# ─────────────────────────────────────────────────────────────────────────────
# Step - Bitcoin node + BTC wallet (optional)
# ─────────────────────────────────────────────────────────────────────────────
step "Bitcoin node + BTC wallet (optional)"
hint "Adds a Bitcoin Core node and a built-in BTC wallet to the web UI"
hint "(balance, receive, send). The wallet keys are held by a light-wallet"
hint "sidecar; the node only provides chain data and broadcasts transactions."
hint ""
hint "Requirements: extra disk space (mainnet ~700 GB) and a full initial"
hint "sync that can take days. The BTC wallet is a HOT wallet - keep only"
hint "spending amounts there."
hint ""
ENABLE_BITCOIN="no"
confirm ENABLE_BITCOIN "Enable the Bitcoin node + BTC wallet?" "N"
BITCOIN_RPC_USERNAME="bitcoin_user"
BITCOIN_RPC_PASSWORD=""
# Random per-install username: a fixed one confirms the username to anyone
# probing the wallet API endpoint.
BITCOIN_WALLET_HTTP_USERNAME="btcwallet_$(rand_pass | head -c 8)"
BITCOIN_WALLET_HTTP_PASSWORD=""
BITCOIN_NETWORK=""
if [[ "$ENABLE_BITCOIN" == "yes" ]]; then
if [[ "$USE_RANDOM_PASSWORDS" == "yes" ]]; then
BITCOIN_RPC_PASSWORD=$(rand_pass)
BITCOIN_WALLET_HTTP_PASSWORD=$(rand_pass)
ok "Generated random Bitcoin RPC passwords (saved to .env)"
else
ask "Bitcoin node RPC password"
prompt_secret BITCOIN_RPC_PASSWORD "Password:"
reason="$(password_reject_reason "$BITCOIN_RPC_PASSWORD")"
while [[ -n "$reason" ]]; do
printf "${CYAN}│${RESET} ${RED}%s${RESET}\n" "$reason"
prompt_secret BITCOIN_RPC_PASSWORD "Password:"
reason="$(password_reject_reason "$BITCOIN_RPC_PASSWORD")"
done
ask "BTC wallet API password"
prompt_secret BITCOIN_WALLET_HTTP_PASSWORD "Password:"
reason="$(password_reject_reason "$BITCOIN_WALLET_HTTP_PASSWORD")"
while [[ -n "$reason" ]]; do
printf "${CYAN}│${RESET} ${RED}%s${RESET}\n" "$reason"
prompt_secret BITCOIN_WALLET_HTTP_PASSWORD "Password:"
reason="$(password_reject_reason "$BITCOIN_WALLET_HTTP_PASSWORD")"
done
fi
ask "Bitcoin network"
hint "Leave default to follow the Mintlayer network (${NETWORK})."
prompt BITCOIN_NETWORK "Network (mainnet/testnet/regtest/signet):" ""
case "$BITCOIN_NETWORK" in
""|"mainnet"|"testnet"|"regtest"|"signet") ;;
*) hint "Unknown network '${BITCOIN_NETWORK}' - following Mintlayer network instead."; BITCOIN_NETWORK="" ;;
esac
ask "Blockchain storage mode"
hint "FULL mode keeps the whole chain plus a transaction index: complete"
hint "wallet history and rescans of any restored seed."
hint " mainnet ~700 GB of disk - testnet ~50 GB"
hint "PRUNED mode keeps only recent blocks (~15-25 GB on mainnet). The BTC"
hint "wallet you create in the GUI works normally, but restoring an old"
hint "seed cannot rescan ancient history."
BTC_PRUNED="yes"
confirm BTC_PRUNED "Run the Bitcoin node in pruned mode?" "Y"
fi
divider
# ─────────────────────────────────────────────────────────────────────────────
# Step - Auto-update (Watchtower)
# ─────────────────────────────────────────────────────────────────────────────
step "Auto-update (Watchtower)"
hint "Watchtower checks Docker Hub daily at 04:00 and automatically pulls new"
hint "versions of the Mintlayer images (node, wallet, indexer) then restarts"
hint "only the affected containers."
hint "The web GUI (built locally) is never touched by Watchtower."
hint ""
ENABLE_WATCHTOWER="no"
confirm ENABLE_WATCHTOWER "Enable automatic image updates?" "Y"
WATCHTOWER_NOTIFICATION_URL=""
if [[ "$ENABLE_WATCHTOWER" == "yes" ]]; then
ask "Telegram notification on update (optional)"
hint "Get a message when an image is updated."
hint "Format: telegram://BOT_TOKEN@telegram?channels=CHAT_ID"
hint "Leave blank to skip."
prompt WATCHTOWER_NOTIFICATION_URL "Notification URL:" ""
# The value lands unquoted in .env: compose expands $VAR/${VAR} in values,
# which would corrupt the URL or pull other secrets from this file.
if [[ "$WATCHTOWER_NOTIFICATION_URL" == *'$'* ]]; then
err "Notification URL must not contain \$ - compose would expand it."
exit 1
fi
fi
divider
# ─────────────────────────────────────────────────────────────────────────────
# Step - IPFS Storage (optional)
# ─────────────────────────────────────────────────────────────────────────────
step "IPFS Storage (optional)"
hint "Enables automatic upload of token/NFT images and metadata to IPFS."
hint "Without this, URLs can still be entered manually - you can configure this"
hint "later in the web UI Settings page."
hint ""
SETUP_IPFS="no"
confirm SETUP_IPFS "Configure IPFS now?" "N"
IPFS_PROVIDER=""
FILEBASE_TOKEN=""
PINATA_JWT=""
if [[ "$SETUP_IPFS" == "yes" ]]; then
hint " Filebase - 5 GB free, always public - https://filebase.com"
hint " Pinata - requires paid plan for public files - https://app.pinata.cloud"
hint ""
IPFS_CHOICE=""
choose IPFS_CHOICE "Choose IPFS provider:" \
"Filebase (recommended - 5 GB free, always public)" \
"Pinata (paid account required to make files public)"
case "$IPFS_CHOICE" in
*"Filebase"*)
IPFS_PROVIDER="filebase"
ask "Filebase API key"
hint "Find it at https://console.filebase.com/keys - scroll to the bottom"
hint "for the bucket-specific IPFS API keys (not the S3 access keys at the top)."
prompt_secret FILEBASE_TOKEN "API key:"
while [[ -z "$FILEBASE_TOKEN" ]]; do
printf "${CYAN}│${RESET} ${RED}API key cannot be empty${RESET}\n"
prompt_secret FILEBASE_TOKEN "API key:"
done
# The token lands unquoted in .env: compose expands $VAR/${VAR} there,
# which would corrupt the key or pull other secrets from this file.
if [[ "$FILEBASE_TOKEN" == *'$'* ]]; then
err "Filebase API key must not contain \$ - compose would expand it."
exit 1
fi
ok "Filebase API key saved"
;;
*"Pinata"*)
IPFS_PROVIDER="pinata"
ask "Pinata JWT"
prompt_secret PINATA_JWT "JWT:"
while [[ -z "$PINATA_JWT" ]]; do
printf "${CYAN}│${RESET} ${RED}JWT cannot be empty${RESET}\n"
prompt_secret PINATA_JWT "JWT:"
done
# Same .env interpolation hazard: reject $ early.
if [[ "$PINATA_JWT" == *'$'* ]]; then
err "Pinata JWT must not contain \$ - compose would expand it."
exit 1
fi
ok "Pinata JWT saved"
;;
esac
fi
divider
# ─────────────────────────────────────────────────────────────────────────────
# Step - Telegram Notifications (optional)
# ─────────────────────────────────────────────────────────────────────────────
step "Telegram Notifications (optional)"
hint "Receive wallet alerts (payments, staking rewards, node status) via a Telegram bot."
hint "You can configure this later in the web UI Settings page."
hint ""
SETUP_TELEGRAM="no"
confirm SETUP_TELEGRAM "Configure Telegram notifications now?" "N"
TELEGRAM_BOT_TOKEN=""
TELEGRAM_CHAT_ID=""
if [[ "$SETUP_TELEGRAM" == "yes" ]]; then
hint "1. Create a bot with @BotFather on Telegram"
hint "2. Start a chat with your bot and send /start"
hint "3. Use @userinfobot to get your chat ID"
hint ""
ask "Telegram bot token"
prompt_secret TELEGRAM_BOT_TOKEN "Bot token:"
while [[ -z "$TELEGRAM_BOT_TOKEN" ]]; do
printf "${CYAN}│${RESET} ${RED}Bot token cannot be empty${RESET}\n"
prompt_secret TELEGRAM_BOT_TOKEN "Bot token:"
done
ask "Telegram chat ID"
prompt TELEGRAM_CHAT_ID "Chat ID:"
while [[ -z "$TELEGRAM_CHAT_ID" ]]; do
printf "${CYAN}│${RESET} ${RED}Chat ID cannot be empty${RESET}\n"
prompt TELEGRAM_CHAT_ID "Chat ID:"
done
# Same .env interpolation hazard as above: reject $ early.
if [[ "$TELEGRAM_BOT_TOKEN" == *'$'* || "$TELEGRAM_CHAT_ID" == *'$'* ]]; then
err "Telegram token and chat ID must not contain \$ - compose would expand them."
exit 1
fi
ok "Telegram configured"
fi
divider
# ─────────────────────────────────────────────────────────────────────────────
# Summary
# ─────────────────────────────────────────────────────────────────────────────
printf "\n"
step "Summary"
printf "${CYAN}│${RESET}\n"
printf "${CYAN}│${RESET} %-22s %s\n" "Network:" "${BOLD}${NETWORK}${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "Passwords:" "${BOLD}$([ "$USE_RANDOM_PASSWORDS" == "yes" ] && echo "randomly generated" || echo "custom")${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "Web UI auth:" "${BOLD}password + TOTP 2FA${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "Web GUI:" "${BOLD}${PASSKEY_ORIGIN}${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "LAN HTTPS:" "${BOLD}$([ "$WEB_GUI_TLS" == "true" ] && echo "enabled (${WEB_GUI_HOST}, local CA)" || echo "disabled")${RESET}"
[[ "$TAILSCALE_ENABLED" == "true" ]] && printf "${CYAN}│${RESET} %-22s %s\n" "Remote access:" "${BOLD}Tailscale tailnet (${TAILSCALE_HOSTNAME}.<tailnet>.ts.net)${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "Passkeys:" "${BOLD}$([ "$WEB_GUI_HOST" != "localhost" ] && echo "enabled (${WEB_GUI_HOST})" || echo "localhost only")${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "Indexer:" "${BOLD}$([ "$ENABLE_INDEXER" == "yes" ] && echo "enabled (port ${API_WEB_SERVER_PORT}) - Token Management + Trading active" || echo "disabled - Token Management + Trading hidden")${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "Bitcoin:" "${BOLD}$([ "$ENABLE_BITCOIN" == "yes" ] && echo "enabled (node + BTC wallet)" || echo "disabled")${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "IPFS storage:" "${BOLD}$([ -n "$IPFS_PROVIDER" ] && echo "$IPFS_PROVIDER" || echo "disabled - configure later in Settings")${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "Telegram:" "${BOLD}$([ -n "$TELEGRAM_BOT_TOKEN" ] && echo "configured" || echo "disabled - configure later in Settings")${RESET}"
printf "${CYAN}│${RESET} %-22s %s\n" "Auto-update:" "${BOLD}$([ "$ENABLE_WATCHTOWER" == "yes" ] && echo "enabled (daily at 04:00)" || echo "disabled")${RESET}"
printf "${CYAN}│${RESET}\n"
# ─────────────────────────────────────────────────────────────────────────────
# Confirm & write
# ─────────────────────────────────────────────────────────────────────────────
PROCEED="yes"
confirm PROCEED "Write .env and continue?" "Y"
if [[ "$PROCEED" != "yes" ]]; then
printf "\n${YELLOW}Setup cancelled. Nothing was written.${RESET}\n\n"
exit 0
fi
divider
# ─────────────────────────────────────────────────────────────────────────────
# Write .env
# ─────────────────────────────────────────────────────────────────────────────