forked from Orcpub/orcpub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu
More file actions
executable file
·789 lines (733 loc) · 24.7 KB
/
menu
File metadata and controls
executable file
·789 lines (733 loc) · 24.7 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
#!/usr/bin/env bash
set -euo pipefail
# =============================================================================
# menu - OrcPub Development Hub
# =============================================================================
# A wrapper/hub for starting, stopping, and checking OrcPub services.
# Intended for LOCAL DEVELOPMENT - an alternative to Calva/IDE-based workflows.
#
# Usage:
# ./menu Interactive menu
# ./menu start Start all services (calls start.sh)
# ./menu stop Stop all services (calls stop.sh)
# ./menu status Show service status (calls stop.sh --dry-run)
# ./menu help Show help
# =============================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Source shared utilities (colors, logging, port config)
# shellcheck source=scripts/common.sh
source "$SCRIPT_DIR/scripts/common.sh"
# -----------------------------------------------------------------------------
# Help
# -----------------------------------------------------------------------------
show_help() {
cat << 'EOF'
OrcPub Development Hub
Usage:
./menu Interactive menu (recommended)
./menu start [service] Start services (passthrough to start.sh)
./menu stop [service] Stop services (passthrough to stop.sh)
./menu status Show service status
./menu cleanup Kill duplicate processes & show memory
Quick CLI examples:
./menu start datomic Start just Datomic
./menu start server Start just server
./menu stop datomic Stop just Datomic
./menu stop --yes Stop all without prompting
./menu status Check what's running
User management (email = <name>@test.com):
./menu add <name> <pass> Create user (auto-verified)
./menu add <name> <pass> --no-verify Create without verification
./menu add user Interactive prompt
./menu verify <name> Verify existing user
./menu delete <name> Delete user
./menu user Show user commands
Start options (passed through to start.sh):
datomic|server|figwheel|garden Specific service
init-db Initialize database
--quiet Suppress output
--idempotent Skip if already running
--background Run in background
--tmux Run in tmux session
Stop options (passed through to stop.sh):
datomic|server|repl|figwheel Specific service
--yes, -y Skip confirmation
--force, -f Use SIGKILL if needed
Tmux tips:
Attach: tmux attach -t orcpub
Detach: Ctrl+B, then D
Kill: tmux kill-session -t orcpub
EOF
}
# -----------------------------------------------------------------------------
# Status Display
# -----------------------------------------------------------------------------
show_status_header() {
"$SCRIPT_DIR/scripts/stop.sh" --dry-run 2>/dev/null || true
}
# -----------------------------------------------------------------------------
# Start Services Submenu
# -----------------------------------------------------------------------------
show_start_submenu() {
echo ""
echo -e "${BOLD}Start Services${NC}"
echo "───────────────────────────────────────"
echo " 1) Datomic only"
echo " 2) Server only"
echo " 3) Figwheel (ClojureScript)"
echo " 4) Garden Auto (CSS watcher)"
echo ""
echo " a) All (foreground)"
echo " b) All (background)"
echo ""
echo " 0) Back"
echo ""
}
handle_start_submenu() {
local choice
while true; do
show_start_submenu
read -r -p "Select: " -n 1 choice
echo ""
case "$choice" in
1)
if ! "$SCRIPT_DIR/scripts/start.sh" datomic; then
echo ""
read -r -p "Press Enter to return to menu..."
fi
return
;;
2)
if ! "$SCRIPT_DIR/scripts/start.sh" server; then
echo ""
read -r -p "Press Enter to return to menu..."
fi
return
;;
3)
if ! "$SCRIPT_DIR/scripts/start.sh" figwheel; then
echo ""
read -r -p "Press Enter to return to menu..."
fi
return
;;
4)
if ! "$SCRIPT_DIR/scripts/start.sh" garden; then
echo ""
read -r -p "Press Enter to return to menu..."
fi
return
;;
a|A)
if ! "$SCRIPT_DIR/scripts/start.sh"; then
echo ""
read -r -p "Press Enter to return to menu..."
fi
return
;;
b|B)
"$SCRIPT_DIR/scripts/start.sh" --background || true
echo ""
read -r -p "Press Enter to continue..."
return
;;
0|""|$'\e'|$'\x7f') # 0, Enter, Escape, or Backspace
return
;;
*)
echo -e "${YELLOW}Invalid choice${NC}"
sleep 0.5
;;
esac
done
}
# -----------------------------------------------------------------------------
# Stop Services Submenu
# -----------------------------------------------------------------------------
show_stop_submenu() {
echo ""
echo -e "${BOLD}Stop Services${NC}"
echo "───────────────────────────────────────"
echo " 1) Stop all"
echo " 2) Datomic only"
echo " 3) Server only"
echo " 4) nREPL only"
echo " 5) Figwheel only"
echo ""
echo " 0) Back"
echo ""
}
handle_stop_submenu() {
local choice
while true; do
show_stop_submenu
read -r -p "Select: " -n 1 choice
echo ""
case "$choice" in
1)
"$SCRIPT_DIR/scripts/stop.sh" || true
echo ""
read -r -p "Press Enter to continue..."
return
;;
2)
"$SCRIPT_DIR/scripts/stop.sh" datomic || true
echo ""
read -r -p "Press Enter to continue..."
return
;;
3)
"$SCRIPT_DIR/scripts/stop.sh" server || true
echo ""
read -r -p "Press Enter to continue..."
return
;;
4)
"$SCRIPT_DIR/scripts/stop.sh" repl || true
echo ""
read -r -p "Press Enter to continue..."
return
;;
5)
"$SCRIPT_DIR/scripts/stop.sh" figwheel || true
echo ""
read -r -p "Press Enter to continue..."
return
;;
0|""|$'\e'|$'\x7f')
return
;;
*)
echo -e "${YELLOW}Invalid choice${NC}"
sleep 0.5
;;
esac
done
}
# -----------------------------------------------------------------------------
# Tmux Submenu
# -----------------------------------------------------------------------------
show_tmux_submenu() {
local session_status
if tmux has-session -t orcpub 2>/dev/null; then
session_status="${GREEN}(session exists)${NC}"
else
session_status="${YELLOW}(no session)${NC}"
fi
echo ""
echo -e "${BOLD}Tmux${NC} $session_status"
echo "───────────────────────────────────────"
echo " 1) Start all in tmux"
echo " 2) Attach to session"
echo " 3) Kill session"
echo ""
echo " 0) Back"
echo ""
}
handle_tmux_submenu() {
local choice
while true; do
show_tmux_submenu
read -r -p "Select: " -n 1 choice
echo ""
case "$choice" in
1)
if "$SCRIPT_DIR/scripts/start.sh" --tmux; then
echo ""
echo -e "${CYAN}Services started in tmux session 'orcpub'.${NC}"
echo ""
echo "To attach: tmux attach -t orcpub"
echo "To detach: Ctrl+B, then D"
fi
echo ""
read -r -p "Press Enter to continue..."
return
;;
2)
if tmux has-session -t orcpub 2>/dev/null; then
echo ""
echo "Attaching to tmux session 'orcpub'..."
echo "(Detach with Ctrl+B, then D)"
echo ""
sleep 1
tmux attach -t orcpub || {
echo ""
echo -e "${YELLOW}Session ended or detached.${NC}"
}
else
echo ""
echo -e "${YELLOW}No tmux session 'orcpub' found.${NC}"
echo "Use option 1 to start services in tmux first."
fi
echo ""
read -r -p "Press Enter to continue..."
return
;;
3)
if tmux has-session -t orcpub 2>/dev/null; then
if tmux kill-session -t orcpub 2>/dev/null; then
echo ""
echo -e "${GREEN}Killed tmux session 'orcpub'.${NC}"
else
echo ""
echo -e "${YELLOW}Session may have already ended.${NC}"
fi
else
echo ""
echo -e "${YELLOW}No tmux session 'orcpub' to kill.${NC}"
fi
echo ""
read -r -p "Press Enter to continue..."
return
;;
0|""|$'\e'|$'\x7f')
return
;;
*)
echo -e "${YELLOW}Invalid choice${NC}"
sleep 0.5
;;
esac
done
}
# -----------------------------------------------------------------------------
# Tail Logs Submenu
# -----------------------------------------------------------------------------
show_tail_submenu() {
echo ""
echo -e "${BOLD}Tail Logs${NC}"
echo "───────────────────────────────────────"
echo " 1) Datomic"
echo " 2) Server"
echo " 3) Figwheel"
echo " 4) All (interleaved)"
echo ""
echo " (Press Ctrl+C to stop tailing)"
echo ""
echo " 0) Back"
echo ""
}
handle_tail_submenu() {
local choice
while true; do
show_tail_submenu
read -r -p "Select: " -n 1 choice
echo ""
case "$choice" in
1)
local log="$LOG_DIR/datomic.log"
if [[ -f "$log" ]]; then
echo ""
echo -e "${CYAN}Tailing $log (Ctrl+C to stop)${NC}"
echo ""
tail -f "$log" || true
echo ""
else
echo -e "${YELLOW}Log not found: $log${NC}"
fi
read -r -p "Press Enter to continue..."
return
;;
2)
local log="$LOG_DIR/server.log"
if [[ -f "$log" ]]; then
echo ""
echo -e "${CYAN}Tailing $log (Ctrl+C to stop)${NC}"
echo ""
tail -f "$log" || true
echo ""
else
echo -e "${YELLOW}Log not found: $log${NC}"
fi
read -r -p "Press Enter to continue..."
return
;;
3)
local log="$LOG_DIR/figwheel.log"
if [[ -f "$log" ]]; then
echo ""
echo -e "${CYAN}Tailing $log (Ctrl+C to stop)${NC}"
echo ""
tail -f "$log" || true
echo ""
else
echo -e "${YELLOW}Log not found: $log${NC}"
fi
read -r -p "Press Enter to continue..."
return
;;
4)
echo ""
echo -e "${CYAN}Tailing all logs (Ctrl+C to stop)${NC}"
echo ""
# Use tail -f on all existing logs
local logs=()
[[ -f "$LOG_DIR/datomic.log" ]] && logs+=("$LOG_DIR/datomic.log")
[[ -f "$LOG_DIR/server.log" ]] && logs+=("$LOG_DIR/server.log")
[[ -f "$LOG_DIR/figwheel.log" ]] && logs+=("$LOG_DIR/figwheel.log")
if [[ ${#logs[@]} -gt 0 ]]; then
tail -f "${logs[@]}" || true
echo ""
else
echo -e "${YELLOW}No log files found in $LOG_DIR${NC}"
fi
read -r -p "Press Enter to continue..."
return
;;
0|""|$'\e'|$'\x7f')
return
;;
*)
echo -e "${YELLOW}Invalid choice${NC}"
sleep 0.5
;;
esac
done
}
# -----------------------------------------------------------------------------
# Open in VS Code Submenu
# -----------------------------------------------------------------------------
show_vscode_submenu() {
echo ""
echo -e "${BOLD}Open Log in VS Code${NC}"
echo "───────────────────────────────────────"
echo " 1) Datomic log"
echo " 2) Server log"
echo " 3) Figwheel log"
echo ""
echo " 0) Back"
echo ""
}
handle_vscode_submenu() {
local choice
while true; do
show_vscode_submenu
read -r -p "Select: " -n 1 choice
echo ""
case "$choice" in
1)
open_log_in_editor "$LOG_DIR/datomic.log"
return
;;
2)
open_log_in_editor "$LOG_DIR/server.log"
return
;;
3)
open_log_in_editor "$LOG_DIR/figwheel.log"
return
;;
0|""|$'\e'|$'\x7f')
return
;;
*)
echo -e "${YELLOW}Invalid choice${NC}"
sleep 0.5
;;
esac
done
}
open_log_in_editor() {
local log="$1"
if [[ ! -f "$log" ]]; then
echo ""
echo -e "${YELLOW}Log not found: $log${NC}"
read -r -p "Press Enter to continue..."
return
fi
if command -v code >/dev/null 2>&1; then
echo ""
echo -e "${GREEN}Opening in VS Code: $log${NC}"
code --goto "$log:1" || {
echo -e "${YELLOW}Failed to open VS Code. Path: $log${NC}"
}
else
echo ""
echo -e "${YELLOW}VS Code CLI not found.${NC}"
echo "Log path: $log"
fi
read -r -p "Press Enter to continue..."
}
# -----------------------------------------------------------------------------
# Utilities Submenu
# -----------------------------------------------------------------------------
show_utils_submenu() {
echo ""
echo -e "${BOLD}Utilities${NC}"
echo "───────────────────────────────────────"
echo " l) Tail logs →"
echo " o) Open log in VS Code →"
echo ""
echo " u) Create test user (verified)"
echo " i) Install Datomic"
echo " c) Check prerequisites"
echo " m) Memory cleanup (kill duplicates)"
echo " r) Refresh status"
echo ""
echo " 0) Back"
echo ""
}
handle_utils_submenu() {
local choice
while true; do
show_utils_submenu
read -r -p "Select: " -n 1 choice
echo ""
case "$choice" in
l|L)
handle_tail_submenu
;;
o|O)
handle_vscode_submenu
;;
u|U)
echo ""
echo -e "${CYAN}Creating test user (test@example.com / testpass)...${NC}"
if "$SCRIPT_DIR/scripts/create_dummy_user.sh" test test@example.com testpass verify; then
echo -e "${GREEN}Test user created successfully${NC}"
else
echo -e "${YELLOW}User creation failed (may already exist)${NC}"
fi
echo ""
read -r -p "Press Enter to continue..."
return
;;
i|I)
"$SCRIPT_DIR/scripts/start.sh" --install || true
echo ""
read -r -p "Press Enter to continue..."
return
;;
c|C)
"$SCRIPT_DIR/scripts/start.sh" --check || true
echo ""
read -r -p "Press Enter to continue..."
return
;;
m|M)
echo ""
"$SCRIPT_DIR/scripts/cleanup-duplicates.sh"
echo ""
read -r -p "Press Enter to continue..."
return
;;
r|R)
return # Just return to refresh main menu
;;
0|""|$'\e'|$'\x7f')
return
;;
*)
echo -e "${YELLOW}Invalid choice${NC}"
sleep 0.5
;;
esac
done
}
# -----------------------------------------------------------------------------
# User Management CLI
# -----------------------------------------------------------------------------
# Append credentials to .test-users so you can look them up later.
# File is gitignored. Format: username | email | password | status | timestamp
log_test_user() {
local user="$1" email="$2" pass="$3" status="${4:-unverified}"
local file="$SCRIPT_DIR/.test-users"
# Add header on first use
if [[ ! -f "$file" ]]; then
echo "# Test users created by dev tooling (gitignored)" > "$file"
echo "# username | email | password | status | created" >> "$file"
fi
echo "$user | $email | $pass | $status | $(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$file"
}
# Create a user. Auto-verified unless --no-verify.
# Email auto-generates as <username>@test.com.
do_add_user() {
local username="$1" password="$2" flag="${3:-}"
local email="${username}@test.com"
if [[ "$flag" == "--no-verify" ]]; then
log_test_user "$username" "$email" "$password" "unverified"
lein with-profile init-db run -m user create-user "$username" "$email" "$password"
else
log_test_user "$username" "$email" "$password" "verified"
lein with-profile init-db run -m user create-user "$username" "$email" "$password" verify
fi
}
# Interactive user creation prompt
do_add_user_interactive() {
echo ""
read -rp "Username: " username
if [[ -z "$username" ]]; then echo "Username required."; exit 1; fi
read -rsp "Password: " password; echo ""
if [[ -z "$password" ]]; then echo "Password required."; exit 1; fi
do_add_user "$username" "$password"
}
# User submenu (./menu user)
handle_user_submenu() {
echo ""
echo "User commands (email = <name>@test.com):"
echo ""
echo " ./menu add <name> <pass> Create (auto-verified)"
echo " ./menu add <name> <pass> --no-verify Create (skip verification)"
echo " ./menu add user Create (interactive prompt)"
echo " ./menu verify <name> Verify existing user"
echo " ./menu delete <name> Delete user"
echo ""
}
# -----------------------------------------------------------------------------
# Main Menu
# -----------------------------------------------------------------------------
show_main_menu() {
echo ""
echo -e "${BOLD}OrcPub Development Hub${NC}"
echo "══════════════════════════════════════════════════════════════════"
echo ""
echo -e "${GREEN}Quick Actions${NC}"
echo " 1) Start Datomic"
echo " 2) Init Database"
echo " 3) Stop all services"
echo " q) Quit"
echo ""
echo " 4) Start Services →"
echo " 5) Stop Services →"
echo " 6) Utilities →"
echo " 7) Tmux →"
echo " 8) Help"
echo ""
}
interactive_menu() {
local choice
local timeout_sec=120 # Auto-refresh status every 2 minutes
while true; do
# Show status at top of menu
show_status_header
show_main_menu
# Read with timeout for auto-refresh, -r to handle backslash
if read -t "$timeout_sec" -r -p "Select: " -n 1 choice; then
echo "" # Newline after single-char input
else
# Timeout reached - just refresh
echo ""
echo -e "${CYAN}[Auto-refresh]${NC}"
continue
fi
case "$choice" in
1)
echo ""
if ! "$SCRIPT_DIR/scripts/start.sh" datomic; then
# start.sh failed (port conflict declined, prereq error, etc.)
echo ""
read -r -p "Press Enter to return to menu..."
fi
;;
2)
echo ""
"$SCRIPT_DIR/scripts/start.sh" init-db || true
echo ""
read -r -p "Press Enter to continue..."
;;
3)
echo ""
"$SCRIPT_DIR/scripts/stop.sh" || true
echo ""
read -r -p "Press Enter to continue..."
;;
4)
handle_start_submenu
;;
5)
handle_stop_submenu
;;
6)
handle_utils_submenu
;;
7)
handle_tmux_submenu
;;
8)
echo ""
show_help
echo ""
read -r -p "Press Enter to continue..."
;;
q|Q|$'\e') # q, Q, or Escape
echo ""
echo "Goodbye."
exit 0
;;
"")
# Enter pressed - just refresh
;;
*)
echo ""
echo -e "${YELLOW}Invalid choice: '$choice'${NC}"
sleep 1
;;
esac
done
}
# -----------------------------------------------------------------------------
# Main
# -----------------------------------------------------------------------------
main() {
local command="${1:-}"
case "$command" in
"")
interactive_menu
;;
start)
shift
"$SCRIPT_DIR/scripts/start.sh" "$@"
;;
stop)
shift
"$SCRIPT_DIR/scripts/stop.sh" "$@"
;;
status)
"$SCRIPT_DIR/scripts/stop.sh" --dry-run
;;
cleanup)
"$SCRIPT_DIR/scripts/cleanup-duplicates.sh"
;;
add)
shift
if [[ "${1:-}" == "user" ]] || [[ -z "${1:-}" ]]; then
do_add_user_interactive
elif [[ -z "${2:-}" ]]; then
echo "Usage: ./menu add <username> <password> [--no-verify]"
exit 1
else
do_add_user "$@"
fi
;;
verify)
shift
local username="${1:-}"
if [[ -z "$username" ]]; then
echo "Usage: ./menu verify <username>"
exit 1
fi
lein with-profile init-db run -m user verify-user "${username}@test.com"
;;
delete)
shift
local username="${1:-}"
if [[ -z "$username" ]]; then
echo "Usage: ./menu delete <username>"
exit 1
fi
lein with-profile init-db run -m user delete-user "${username}@test.com"
;;
user)
handle_user_submenu
;;
help|--help|-h)
show_help
;;
*)
echo "Unknown command: $command"
show_help
exit 1
;;
esac
}
main "$@"