Repository navigation
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·3007 lines (2648 loc) · 92.2 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·3007 lines (2648 loc) · 92.2 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
# INTERCEPT Setup Script - Menu-driven installer with profile system
# Supports: first-time wizard, selective module install, health check,
# PostgreSQL setup, environment configurator, update, uninstall.
# ---- Force bash even if launched with sh ----
if [ -z "${BASH_VERSION:-}" ]; then
echo "[x] This script must be run with bash (not sh)."
echo " Run: bash $0"
exec bash "$0" "$@"
fi
set -Eeuo pipefail
# Ensure admin paths are searchable (many tools live here)
export PATH="/usr/local/sbin:/usr/sbin:/sbin:/opt/homebrew/sbin:/opt/homebrew/bin:$PATH"
# ----------------------------
# Pretty output
# ----------------------------
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
BOLD='\033[1m'
DIM='\033[2m'
NC='\033[0m'
info() { echo -e "${BLUE}[*]${NC} $*"; }
ok() { echo -e "${GREEN}[✓]${NC} $*"; }
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
fail() { echo -e "${RED}[x]${NC} $*"; }
# ----------------------------
# Progress tracking
# ----------------------------
CURRENT_STEP=0
TOTAL_STEPS=0
progress() {
local msg="$1"
((CURRENT_STEP++)) || true
local pct=$((CURRENT_STEP * 100 / TOTAL_STEPS))
local filled=$((pct / 5))
local empty=$((20 - filled))
local bar=$(printf '█%.0s' $(seq 1 $filled 2>/dev/null) || true)
bar+=$(printf '░%.0s' $(seq 1 $empty 2>/dev/null) || true)
echo -e "${BLUE}[${CURRENT_STEP}/${TOTAL_STEPS}]${NC} ${bar} ${pct}% - ${msg}"
}
on_error() {
local line="$1"
local cmd="${2:-unknown}"
fail "Setup failed at line ${line}: ${cmd}"
exit 1
}
trap 'on_error $LINENO "$BASH_COMMAND"' ERR
# ----------------------------
# Script directory
# ----------------------------
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
# ----------------------------
# Banner
# ----------------------------
show_banner() {
echo -e "${BLUE}"
echo " ___ _ _ _____ _____ ____ ____ _____ ____ _____ "
echo " |_ _| \\ | |_ _| ____| _ \\ / ___| ____| _ \\_ _|"
echo " | || \\| | | | | _| | |_) | | | _| | |_) || | "
echo " | || |\\ | | | | |___| _ <| |___| |___| __/ | | "
echo " |___|_| \\_| |_| |_____|_| \\_\\\\____|_____|_| |_| "
echo -e "${NC}"
}
# ----------------------------
# Helpers
# ----------------------------
NON_INTERACTIVE=false
CLI_PROFILES=""
CLI_ACTION=""
cmd_exists() {
local c="$1"
command -v "$c" >/dev/null 2>&1 && return 0
[[ -x "/usr/sbin/$c" || -x "/sbin/$c" || -x "/usr/local/sbin/$c" || -x "/opt/homebrew/sbin/$c" ]] && return 0
return 1
}
ask_yes_no() {
local prompt="$1"
local default="${2:-n}" # default to no for safety
local response
if $NON_INTERACTIVE; then
info "Non-interactive mode: defaulting to ${default} for prompt: ${prompt}"
[[ "$default" == "y" ]]
return
fi
if [[ ! -t 0 ]]; then
warn "No TTY available for prompt: ${prompt}"
[[ "$default" == "y" ]]
return
fi
if [[ "$default" == "y" ]]; then
read -r -p "$prompt [Y/n]: " response
[[ -z "$response" || "$response" =~ ^[Yy] ]]
else
read -r -p "$prompt [y/N]: " response
[[ "$response" =~ ^[Yy] ]]
fi
}
have_any() {
local c
for c in "$@"; do
cmd_exists "$c" && return 0
done
return 1
}
need_sudo() {
if [[ "$(id -u)" -eq 0 ]]; then
SUDO=""
ok "Running as root"
else
if cmd_exists sudo; then
SUDO="sudo"
else
fail "sudo is not installed and you're not root."
echo "Either run as root or install sudo first."
exit 1
fi
fi
}
refresh_sudo() {
[[ -z "${SUDO:-}" ]] && return 0
sudo -v 2>/dev/null || true
}
detect_os() {
if [[ "${OSTYPE:-}" == "darwin"* ]]; then
OS="macos"
elif [[ -f /etc/debian_version ]]; then
OS="debian"
else
OS="unknown"
fi
[[ "$OS" != "unknown" ]] || { fail "Unsupported OS (macOS + Debian/Ubuntu only)."; exit 1; }
}
detect_dragonos() {
IS_DRAGONOS=false
if [[ -f /etc/dragonos-release ]] || \
[[ -d /usr/share/dragonos ]] || \
grep -qi "dragonos" /etc/os-release 2>/dev/null; then
IS_DRAGONOS=true
warn "DragonOS detected! This distro has many tools pre-installed."
warn "The script will prompt before making system changes."
fi
}
# ----------------------------
# .env file helpers
# ----------------------------
read_env_var() {
local key="$1"
local fallback="${2:-}"
if [[ -f "$SCRIPT_DIR/.env" ]]; then
local val
val=$(grep -E "^${key}=" "$SCRIPT_DIR/.env" 2>/dev/null | tail -1 | cut -d'=' -f2- || true)
if [[ -n "$val" ]]; then
# Strip surrounding quotes
val="${val#\"}"
val="${val%\"}"
val="${val#\'}"
val="${val%\'}"
echo "$val"
return
fi
fi
echo "$fallback"
}
write_env_var() {
local key="$1"
local value="$2"
local env_file="$SCRIPT_DIR/.env"
if [[ ! -f "$env_file" ]]; then
echo "# INTERCEPT environment configuration" > "$env_file"
echo "# Generated by setup.sh on $(date)" >> "$env_file"
echo "" >> "$env_file"
fi
if grep -qE "^${key}=" "$env_file" 2>/dev/null; then
# Update existing
local tmp
tmp=$(mktemp)
sed "s|^${key}=.*|${key}=${value}|" "$env_file" > "$tmp" && mv "$tmp" "$env_file"
else
echo "${key}=${value}" >> "$env_file"
fi
}
# ============================================================
# TOOL REGISTRY & PROFILE SYSTEM
# ============================================================
# Profile bitmask:
# 1 = Core SIGINT
# 2 = Maritime & Radio
# 4 = Weather & Space
# 8 = RF Security
# 15 = Full SIGINT (all)
PROFILE_CORE=1
PROFILE_MARITIME=2
PROFILE_WEATHER=4
PROFILE_SECURITY=8
PROFILE_FULL=15
# Tool registry as parallel indexed arrays (Bash 3.2 compatible — no associative arrays)
# Format: TOOL_KEYS[i] = key, TOOL_ENTRIES[i] = "profile_mask|check_command|description"
TOOL_KEYS=(
rtl_sdr multimon_ng rtl_433 dump1090 acarsdec dumpvdl2 ffmpeg gpsd
hackrf rtlamr ais_catcher direwolf satdump radiosonde
aircrack_ng hcxdumptool hcxtools bluez ubertooth soapysdr rtlsdr_blog
)
TOOL_ENTRIES=(
"1|rtl_fm|RTL-SDR tools (rtl_fm, rtl_test, rtl_tcp)"
"1|multimon-ng|Pager decoder (POCSAG/FLEX)"
"1|rtl_433|433MHz IoT sensor decoder"
"1|dump1090|ADS-B aircraft decoder"
"1|acarsdec|ACARS aircraft message decoder"
"1|dumpvdl2|VDL2 aircraft datalink decoder"
"1|ffmpeg|Audio/video encoder"
"1|gpsd|GPS daemon"
"8|hackrf_transfer|HackRF tools"
"1|rtlamr|Utility meter decoder (requires Go)"
"2|AIS-catcher|AIS vessel tracker"
"2|direwolf|APRS packet radio decoder"
"4|satdump|Weather satellite decoder (NOAA/Meteor)"
"4|auto_rx.py|Radiosonde weather balloon decoder"
"8|airmon-ng|WiFi security suite"
"8|hcxdumptool|PMKID capture tool"
"8|hcxpcapngtool|PMKID/pcapng conversion"
"8|bluetoothctl|Bluetooth tools (BlueZ)"
"8|ubertooth-btle|Ubertooth BLE sniffer"
"8|SoapySDRUtil|SoapySDR utility"
"1|SKIP|RTL-SDR Blog V4 drivers"
)
# Lookup helper: get entry by key name
_tool_entry() {
local key="$1"
local i
for i in "${!TOOL_KEYS[@]}"; do
if [[ "${TOOL_KEYS[$i]}" == "$key" ]]; then
echo "${TOOL_ENTRIES[$i]}"
return 0
fi
done
return 1
}
profile_name() {
case "$1" in
1) echo "Core SIGINT" ;;
2) echo "Maritime & Radio" ;;
4) echo "Weather & Space" ;;
8) echo "RF Security" ;;
15) echo "Full SIGINT" ;;
*) echo "Custom" ;;
esac
}
tool_is_installed() {
local key="$1"
local entry
entry=$(_tool_entry "$key") || return 1
local check_cmd
check_cmd=$(echo "$entry" | cut -d'|' -f2)
# Special cases
[[ "$check_cmd" == "SKIP" ]] && return 1
if [[ "$key" == "radiosonde" ]]; then
[[ -f /opt/radiosonde_auto_rx/auto_rx/auto_rx.py ]] && \
[[ -f /opt/radiosonde_auto_rx/auto_rx/dft_detect ]] && return 0
return 1
fi
if [[ "$key" == "ais_catcher" ]]; then
have_any AIS-catcher aiscatcher && return 0
return 1
fi
if [[ "$key" == "rtl_433" ]]; then
have_any rtl_433 rtl433 && return 0
return 1
fi
cmd_exists "$check_cmd"
}
tool_version() {
local key="$1"
local entry
entry=$(_tool_entry "$key") || { echo "?"; return; }
local check_cmd
check_cmd=$(echo "$entry" | cut -d'|' -f2)
[[ "$check_cmd" == "SKIP" ]] && echo "n/a" && return
# Try common version flags
local ver=""
ver=$($check_cmd --version 2>&1 | head -1) 2>/dev/null || \
ver=$($check_cmd -V 2>&1 | head -1) 2>/dev/null || \
ver=$($check_cmd -v 2>&1 | head -1) 2>/dev/null || \
ver="installed"
echo "$ver" | head -c 60
}
# ============================================================
# MENU RENDERING
# ============================================================
draw_line() {
printf '%*s\n' "${1:-60}" '' | tr ' ' "${2:-═}"
}
show_main_menu() {
echo
echo -e "${BOLD}${CYAN}INTERCEPT Setup Menu${NC}"
draw_line 40
echo -e " ${BOLD}1)${NC} Install / Add Modules"
echo -e " ${BOLD}2)${NC} System Health Check"
echo -e " ${BOLD}3)${NC} Database Setup (ADS-B History)"
echo -e " ${BOLD}4)${NC} Update Tools"
echo -e " ${BOLD}5)${NC} Environment Configurator"
echo -e " ${BOLD}6)${NC} Uninstall / Cleanup"
echo -e " ${BOLD}7)${NC} View Status"
echo -e " ${BOLD}0)${NC} Exit"
draw_line 40
echo -n "Select option: "
}
show_profile_menu() {
echo
echo -e "${BOLD}${CYAN}Install Profiles${NC} ${DIM}(space-separated for multiple, e.g. \"1 3\")${NC}"
draw_line 50
echo -e " ${BOLD}1)${NC} Core SIGINT — rtl_sdr, multimon-ng, rtl_433, dump1090, acarsdec, dumpvdl2, ffmpeg, gpsd"
echo -e " ${BOLD}2)${NC} Maritime & Radio — AIS-catcher, direwolf"
echo -e " ${BOLD}3)${NC} Weather & Space — SatDump, radiosonde_auto_rx"
echo -e " ${BOLD}4)${NC} RF Security — aircrack-ng, HackRF, BlueZ, hcxtools, Ubertooth, SoapySDR"
echo -e " ${BOLD}5)${NC} Full SIGINT — All of the above"
echo -e " ${BOLD}6)${NC} Custom — Per-tool checklist"
draw_line 50
echo -n "Select profiles: "
}
# Convert profile menu selections to bitmask
selections_to_mask() {
local selections="$1"
local mask=0
for sel in $selections; do
case "$sel" in
1) mask=$((mask | PROFILE_CORE)) ;;
2) mask=$((mask | PROFILE_MARITIME)) ;;
3) mask=$((mask | PROFILE_WEATHER)) ;;
4) mask=$((mask | PROFILE_SECURITY)) ;;
5) mask=$PROFILE_FULL ;;
6) mask=-1 ;; # custom
esac
done
echo $mask
}
# ============================================================
# REQUIRED TOOL CHECKS (preserved from original)
# ============================================================
missing_required=()
missing_recommended=()
check_required() {
local label="$1"; shift
local desc="$1"; shift
if have_any "$@"; then
ok "${label} - ${desc}"
else
warn "${label} - ${desc} (missing, required)"
missing_required+=("$label")
fi
}
check_recommended() {
local label="$1"; shift
local desc="$1"; shift
if have_any "$@"; then
ok "${label} - ${desc}"
else
warn "${label} - ${desc} (missing, recommended)"
missing_recommended+=("$label")
fi
}
check_optional() {
local label="$1"; shift
local desc="$1"; shift
if have_any "$@"; then
ok "${label} - ${desc}"
else
warn "${label} - ${desc} (missing, optional)"
fi
}
check_tools() {
info "Checking required tools..."
missing_required=()
echo
info "Core SDR:"
check_required "rtl_fm" "RTL-SDR FM demodulator" rtl_fm
check_required "rtl_test" "RTL-SDR device detection" rtl_test
check_required "rtl_tcp" "RTL-SDR TCP server" rtl_tcp
check_required "multimon-ng" "Pager decoder" multimon-ng
check_required "rtl_433" "433MHz sensor decoder" rtl_433 rtl433
check_optional "rtlamr" "Utility meter decoder (requires Go)" rtlamr
check_optional "hackrf_transfer" "HackRF SubGHz transceiver" hackrf_transfer
check_optional "hackrf_sweep" "HackRF spectrum analyzer" hackrf_sweep
check_required "dump1090" "ADS-B decoder" dump1090
check_required "acarsdec" "ACARS decoder" acarsdec
check_optional "dumpvdl2" "VDL2 decoder" dumpvdl2
check_required "AIS-catcher" "AIS vessel decoder" AIS-catcher aiscatcher
check_optional "satdump" "Weather satellite decoder (NOAA/Meteor)" satdump
if [[ -f /opt/radiosonde_auto_rx/auto_rx/auto_rx.py ]] && [[ -f /opt/radiosonde_auto_rx/auto_rx/dft_detect ]]; then
ok "auto_rx.py - Radiosonde weather balloon decoder"
else
warn "auto_rx.py - Radiosonde weather balloon decoder (missing, optional)"
fi
echo
info "GPS:"
check_required "gpsd" "GPS daemon" gpsd
echo
info "Audio:"
check_required "ffmpeg" "Audio encoder/decoder" ffmpeg
echo
info "WiFi:"
check_required "airmon-ng" "Monitor mode helper" airmon-ng
check_required "airodump-ng" "WiFi scanner" airodump-ng
check_required "aireplay-ng" "Injection/deauth" aireplay-ng
check_required "hcxdumptool" "PMKID capture" hcxdumptool
check_required "hcxpcapngtool" "PMKID/pcapng conversion" hcxpcapngtool
echo
info "Bluetooth:"
check_required "bluetoothctl" "Bluetooth controller CLI" bluetoothctl
check_required "hcitool" "Bluetooth scan utility" hcitool
check_required "hciconfig" "Bluetooth adapter config" hciconfig
echo
info "SoapySDR:"
check_required "SoapySDRUtil" "SoapySDR CLI utility" SoapySDRUtil
echo
}
# ============================================================
# PYTHON VENV SETUP (preserved from original)
# ============================================================
check_python_version() {
if ! cmd_exists python3; then
fail "python3 not found."
[[ "$OS" == "macos" ]] && echo "Install with: brew install python"
[[ "$OS" == "debian" ]] && echo "Install with: sudo apt-get install python3"
exit 1
fi
local ver
ver="$(python3 -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')"
info "Python version: ${ver}"
python3 - <<'PY'
import sys
raise SystemExit(0 if sys.version_info >= (3,9) else 1)
PY
ok "Python version OK (>= 3.9)"
# meshcore (MeshCore mesh networking) requires Python 3.10+
if python3 - <<'PY'
import sys
raise SystemExit(0 if sys.version_info < (3,10) else 1)
PY
then
warn "Python 3.9 detected: MeshCore support requires Python 3.10+ and will be unavailable."
fi
# Python 3.13+ warning: some packages (gevent, numpy, scipy) may not have
# pre-built wheels yet; prefer wheels over source builds to avoid hanging
# on compilation (--prefer-binary is added to PIP_OPTS in install_python_deps).
if python3 - <<'PY'
import sys
raise SystemExit(0 if sys.version_info >= (3,13) else 1)
PY
then
warn "Python 3.13+ detected: preferring pre-built wheels over source builds (--prefer-binary)."
fi
}
install_python_deps() {
progress "Setting up Python environment"
check_python_version
if [[ ! -f requirements.txt ]]; then
warn "requirements.txt not found; skipping Python dependency install."
return 0
fi
# On Debian/Ubuntu, try apt packages first as they're more reliable
if [[ "$OS" == "debian" ]]; then
info "Installing Python packages via apt (more reliable on Debian/Ubuntu)..."
$SUDO apt-get install -y python3-flask python3-requests python3-serial >/dev/null 2>&1 || true
if ! $SUDO apt-get install -y python3-skyfield >/dev/null 2>&1; then
warn "python3-skyfield not in apt, will try pip later"
fi
ok "Installed available Python packages via apt"
fi
if [[ ! -d venv ]]; then
python3 -m venv --system-site-packages venv
ok "Created venv/ (with system site-packages)"
else
ok "Using existing venv/"
fi
# shellcheck disable=SC1091
source venv/bin/activate
local PIP="venv/bin/python -m pip"
local PY="venv/bin/python"
# --no-cache-dir avoids pip hanging on a corrupt/stale HTTP cache (cachecontrol .pyc issue)
# --timeout prevents pip from hanging indefinitely on slow/unresponsive PyPI connections
local PIP_OPTS="--no-cache-dir --timeout 120"
# Python 3.13+: prefer wheels over source builds (see check_python_version warning)
if "$PY" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3,13) else 1)'; then
PIP_OPTS="$PIP_OPTS --prefer-binary"
fi
# pip wrapper that filters the send2trash malformed-metadata WARNING.
# send2trash ships broken extras metadata on some systems, causing pip to
# print a WARNING on every single invocation. We suppress those three lines
# while preserving all other output and pip's real exit code.
_pip_run() {
$PIP "$@" 2>&1 | \
grep -Ev "^WARNING: Error parsing dependencies of send2trash|sys-platform.*darwin.*objc| +~\^"
return "${PIPESTATUS[0]}"
}
# Silent variant for optional packages: shows nothing on success (suppresses
# "Requirement already satisfied" walls), shows filtered output on failure.
_pip_optional() {
local out rc
out=$($PIP install $PIP_OPTS -q "$@" 2>&1) && return 0
rc=$?
printf '%s\n' "$out" | \
grep -Ev "Error parsing dependencies of send2trash|sys-platform.*darwin.*objc| +~\^"
return "$rc"
}
if ! _pip_run install $PIP_OPTS --upgrade pip setuptools wheel; then
warn "pip/setuptools/wheel upgrade failed - continuing with existing versions"
else
ok "Upgraded pip tooling"
fi
progress "Installing Python dependencies"
info "Installing core packages..."
# --ignore-installed forces packages into the venv even if they already
# exist in ~/.local (user site-packages). Without this, pip sees them as
# satisfied and skips the venv install, causing the health check to fail
# because it runs with 'python -s' which excludes ~/.local.
_pip_run install $PIP_OPTS --ignore-installed "flask>=3.0.0" "flask-wtf>=1.2.0" "flask-compress>=1.15" \
"flask-limiter>=2.5.4" "requests>=2.28.0" \
"Werkzeug>=3.1.5" "pyserial>=3.5" || true
# Verify core packages are installed by checking pip's reported list (avoids hanging imports)
for core_pkg in flask requests flask-limiter flask-compress flask-wtf; do
if ! $PIP show "$core_pkg" >/dev/null 2>&1; then
fail "Critical Python package not installed: ${core_pkg}"
echo "Try: venv/bin/pip install ${core_pkg}"
exit 1
fi
done
ok "Core Python packages installed"
info "Installing optional packages..."
# Optional package specs come from requirements.txt (single source of truth).
# Packages already installed by the core step above are skipped here.
local core_pkgs="flask flask-wtf flask-compress flask-limiter requests Werkzeug pyserial"
# Heavy compiled packages: install with --only-binary :all: to skip slow
# source compilation on RPi. Everything else installs without it (note:
# transitive deps may still be compiled, e.g. meshcore -> pycryptodome;
# failures are tolerated since these features are optional).
local binary_only_pkgs="numpy scipy Pillow psycopg2-binary scapy cryptography gevent"
local pkg pkg_name extra_opts
while IFS= read -r pkg; do
pkg="${pkg%"${pkg##*[![:space:]]}"}" # trim trailing whitespace
[[ -z "$pkg" || "$pkg" == \#* ]] && continue
pkg_name="${pkg%%[><=[]*}"
case " $core_pkgs " in *" $pkg_name "*) continue ;; esac
extra_opts=""
case " $binary_only_pkgs " in *" $pkg_name "*) extra_opts="--only-binary :all:" ;; esac
info " Installing ${pkg_name}..."
if ! _pip_optional $extra_opts "$pkg"; then
warn "${pkg_name} failed to install (optional - related features may be unavailable)"
fi
done < requirements.txt
ok "Optional packages processed"
echo
}
# ============================================================
# macOS HELPERS (preserved from original)
# ============================================================
ensure_brew() {
cmd_exists brew && return 0
warn "Homebrew not found. Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [[ -x /opt/homebrew/bin/brew ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
elif [[ -x /usr/local/bin/brew ]]; then
eval "$(/usr/local/bin/brew shellenv)"
fi
cmd_exists brew || { fail "Homebrew install failed. Install manually then re-run."; exit 1; }
}
brew_install() {
local pkg="$1"
if brew list --formula "$pkg" >/dev/null 2>&1; then
ok "brew: ${pkg} already installed"
return 0
fi
info "brew: installing ${pkg}..."
if brew install "$pkg" 2>&1; then
ok "brew: installed ${pkg}"
return 0
else
return 1
fi
}
# ============================================================
# Debian/Ubuntu APT HELPERS (preserved from original)
# ============================================================
apt_install() {
local pkgs="$*"
local output
local ret=0
output=$($SUDO apt-get install -y --no-install-recommends "$@" 2>&1) || ret=$?
if [[ $ret -ne 0 ]]; then
fail "Failed to install: $pkgs"
echo "$output" | tail -10
fail "Try running: sudo apt-get update && sudo apt-get install -y $pkgs"
return 1
fi
}
wait_for_apt_lock() {
local max_wait=120
local waited=0
while fuser /var/lib/dpkg/lock-frontend /var/lib/apt/lists/lock /var/cache/apt/archives/lock >/dev/null 2>&1; do
if [[ $waited -eq 0 ]]; then
info "Waiting for apt lock (another package manager is running)..."
fi
sleep 5
waited=$((waited + 5))
if [[ $waited -ge $max_wait ]]; then
warn "apt lock held for over ${max_wait}s. Continuing anyway (may fail)."
return 1
fi
done
return 0
}
apt_try_install_any() {
wait_for_apt_lock
local p
for p in "$@"; do
if $SUDO apt-get install -y --no-install-recommends "$p" >/dev/null 2>&1; then
ok "apt: installed ${p}"
return 0
fi
done
return 1
}
apt_install_if_missing() {
local pkg="$1"
if dpkg -l "$pkg" 2>/dev/null | grep -q "^ii"; then
ok "apt: ${pkg} already installed"
return 0
fi
apt_install "$pkg"
}
# ============================================================
# PER-TOOL INSTALL FUNCTIONS (preserved from original)
# ============================================================
# --- rtlamr (Go-based, cross-platform) ---
install_rtlamr_from_source() {
info "Installing rtlamr from source (requires Go)..."
if ! cmd_exists go; then
if [[ "$OS" == "macos" ]]; then
info "Installing Go via Homebrew..."
brew_install go || { warn "Failed to install Go. Cannot install rtlamr."; return 1; }
else
info "Installing Go via apt..."
$SUDO apt-get install -y golang >/dev/null 2>&1 || { warn "Failed to install Go. Cannot install rtlamr."; return 1; }
fi
fi
export GOPATH="${GOPATH:-$HOME/go}"
export PATH="$GOPATH/bin:$PATH"
mkdir -p "$GOPATH/bin"
info "Building rtlamr..."
if go install github.com/bemasher/rtlamr@latest 2>/dev/null; then
if [[ -f "$GOPATH/bin/rtlamr" ]]; then
if [[ "$OS" == "macos" ]]; then
if [[ -w /usr/local/bin ]]; then
ln -sf "$GOPATH/bin/rtlamr" /usr/local/bin/rtlamr
else
$SUDO ln -sf "$GOPATH/bin/rtlamr" /usr/local/bin/rtlamr
fi
else
$SUDO ln -sf "$GOPATH/bin/rtlamr" /usr/local/bin/rtlamr
fi
ok "rtlamr installed successfully"
else
warn "rtlamr binary not found after build"
return 1
fi
else
warn "Failed to build rtlamr"
return 1
fi
}
# --- multimon-ng (macOS from source) ---
install_multimon_ng_from_source_macos() {
info "multimon-ng not available via Homebrew. Building from source..."
brew_install cmake
brew_install libsndfile
(
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
info "Cloning multimon-ng..."
git clone --depth 1 https://github.com/EliasOenal/multimon-ng.git "$tmp_dir/multimon-ng" >/dev/null 2>&1 \
|| { fail "Failed to clone multimon-ng"; exit 1; }
cd "$tmp_dir/multimon-ng"
info "Compiling multimon-ng..."
mkdir -p build && cd build
cmake .. >/dev/null 2>&1 || { fail "cmake failed for multimon-ng"; exit 1; }
make >/dev/null 2>&1 || { fail "make failed for multimon-ng"; exit 1; }
if [[ -w /usr/local/bin ]]; then
install -m 0755 multimon-ng /usr/local/bin/multimon-ng
else
refresh_sudo
$SUDO install -m 0755 multimon-ng /usr/local/bin/multimon-ng
fi
ok "multimon-ng installed successfully from source"
)
}
# --- dump1090 (macOS from source) ---
install_dump1090_from_source_macos() {
info "dump1090 not available via Homebrew. Building from source..."
brew_install cmake
brew_install librtlsdr
brew_install pkg-config
(
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
info "Cloning FlightAware dump1090..."
git clone --depth 1 https://github.com/flightaware/dump1090.git "$tmp_dir/dump1090" >/dev/null 2>&1 \
|| { warn "Failed to clone dump1090"; exit 1; }
cd "$tmp_dir/dump1090"
sed -i '' 's/-Werror//g' Makefile 2>/dev/null || true
info "Compiling dump1090..."
if make BLADERF=no RTLSDR=yes 2>&1 | tail -5; then
if [[ -w /usr/local/bin ]]; then
install -m 0755 dump1090 /usr/local/bin/dump1090
else
refresh_sudo
$SUDO install -m 0755 dump1090 /usr/local/bin/dump1090
fi
ok "dump1090 installed successfully from source"
else
warn "Failed to build dump1090. ADS-B decoding will not be available."
fi
)
}
# --- acarsdec (macOS from source) ---
install_acarsdec_from_source_macos() {
info "acarsdec not available via Homebrew. Building from source..."
brew_install cmake
brew_install librtlsdr
brew_install libsndfile
brew_install pkg-config
(
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
info "Cloning acarsdec..."
git clone --depth 1 https://github.com/TLeconte/acarsdec.git "$tmp_dir/acarsdec" >/dev/null 2>&1 \
|| { warn "Failed to clone acarsdec"; exit 1; }
cd "$tmp_dir/acarsdec"
# Replace deprecated -Ofast (all macOS, not just arm64)
if grep -q '\-Ofast' CMakeLists.txt 2>/dev/null; then
sed -i '' 's/-Ofast/-O3 -ffast-math/g' CMakeLists.txt
info "Patched deprecated -Ofast flag"
fi
# macOS doesn't have -march=native on arm64
if [[ "$(uname -m)" == "arm64" ]]; then
sed -i '' 's/ -march=native//g' CMakeLists.txt
info "Removed -march=native for Apple Silicon"
fi
# HOST_NAME_MAX is Linux-specific; macOS uses _POSIX_HOST_NAME_MAX
if grep -q 'HOST_NAME_MAX' acarsdec.c 2>/dev/null; then
sed -i '' '1i\
#ifndef HOST_NAME_MAX\
#define HOST_NAME_MAX 255\
#endif
' acarsdec.c
info "Patched HOST_NAME_MAX for macOS compatibility"
fi
if grep -q 'pthread_tryjoin_np' rtl.c 2>/dev/null; then
sed -i '' 's/pthread_tryjoin_np(\([^,]*\), NULL)/pthread_join(\1, NULL)/g' rtl.c
info "Patched pthread_tryjoin_np for macOS compatibility"
fi
if grep -q 'LIBACARS_LIBRARIES' CMakeLists.txt 2>/dev/null; then
sed -i '' 's/${LIBACARS_LIBRARIES}/${LIBACARS_LINK_LIBRARIES}/g' CMakeLists.txt
info "Patched libacars linking for macOS"
fi
mkdir -p build && cd build
HOMEBREW_PREFIX="$(brew --prefix)"
export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
export CMAKE_PREFIX_PATH="${HOMEBREW_PREFIX}"
info "Compiling acarsdec..."
build_log="$tmp_dir/acarsdec-build.log"
if cmake .. -Drtl=ON \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
-DCMAKE_C_FLAGS="-I${HOMEBREW_PREFIX}/include" \
-DCMAKE_EXE_LINKER_FLAGS="-L${HOMEBREW_PREFIX}/lib" \
>"$build_log" 2>&1 \
&& make >>"$build_log" 2>&1; then
if [[ -w /usr/local/bin ]]; then
install -m 0755 acarsdec /usr/local/bin/acarsdec
else
refresh_sudo
$SUDO install -m 0755 acarsdec /usr/local/bin/acarsdec
fi
ok "acarsdec installed successfully from source"
else
warn "Failed to build acarsdec. ACARS decoding will not be available."
warn "Build log (last 30 lines):"
tail -30 "$build_log" | while IFS= read -r line; do warn " $line"; done
fi
)
}
# --- dumpvdl2 (macOS from source, with libacars) ---
install_dumpvdl2_from_source_macos() {
info "Building dumpvdl2 from source (with libacars dependency)..."
brew_install cmake
brew_install librtlsdr
brew_install pkg-config
brew_install glib
(
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
HOMEBREW_PREFIX="$(brew --prefix)"
export PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
export CMAKE_PREFIX_PATH="${HOMEBREW_PREFIX}"
info "Cloning libacars..."
git clone --depth 1 https://github.com/szpajder/libacars.git "$tmp_dir/libacars" >/dev/null 2>&1 \
|| { warn "Failed to clone libacars"; exit 1; }
cd "$tmp_dir/libacars"
mkdir -p build && cd build
info "Compiling libacars..."
build_log="$tmp_dir/libacars-build.log"
if cmake .. \
-DCMAKE_C_FLAGS="-I${HOMEBREW_PREFIX}/include" \
-DCMAKE_EXE_LINKER_FLAGS="-L${HOMEBREW_PREFIX}/lib" \
>"$build_log" 2>&1 \
&& make >>"$build_log" 2>&1; then
if [[ -w /usr/local/lib ]]; then
make install >>"$build_log" 2>&1
else
refresh_sudo
$SUDO make install >>"$build_log" 2>&1
fi
ok "libacars installed"
else
warn "Failed to build libacars."
tail -20 "$build_log" | while IFS= read -r line; do warn " $line"; done
exit 1
fi
info "Cloning dumpvdl2..."
git clone --depth 1 https://github.com/szpajder/dumpvdl2.git "$tmp_dir/dumpvdl2" >/dev/null 2>&1 \
|| { warn "Failed to clone dumpvdl2"; exit 1; }
cd "$tmp_dir/dumpvdl2"
mkdir -p build && cd build
info "Compiling dumpvdl2..."
build_log="$tmp_dir/dumpvdl2-build.log"
if cmake .. \
-DCMAKE_C_FLAGS="-I${HOMEBREW_PREFIX}/include" \
-DCMAKE_EXE_LINKER_FLAGS="-L${HOMEBREW_PREFIX}/lib" \
>"$build_log" 2>&1 \
&& make >>"$build_log" 2>&1; then
if [[ -w /usr/local/bin ]]; then
install -m 0755 src/dumpvdl2 /usr/local/bin/dumpvdl2
else
refresh_sudo
$SUDO install -m 0755 src/dumpvdl2 /usr/local/bin/dumpvdl2
fi
ok "dumpvdl2 installed successfully from source"
else
warn "Failed to build dumpvdl2. VDL2 decoding will not be available."
warn "Build log (last 30 lines):"
tail -30 "$build_log" | while IFS= read -r line; do warn " $line"; done
fi
)
}
# --- AIS-catcher (macOS from source) ---
install_aiscatcher_from_source_macos() {
info "AIS-catcher not available via Homebrew. Building from source..."
brew_install cmake
brew_install librtlsdr
brew_install curl
brew_install pkg-config
(
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' EXIT
info "Cloning AIS-catcher..."
git clone --depth 1 https://github.com/jvde-github/AIS-catcher.git "$tmp_dir/AIS-catcher" >/dev/null 2>&1 \
|| { warn "Failed to clone AIS-catcher"; exit 1; }
cd "$tmp_dir/AIS-catcher"
mkdir -p build && cd build
info "Compiling AIS-catcher..."
if cmake .. >/dev/null 2>&1 && make >/dev/null 2>&1; then
if [[ -w /usr/local/bin ]]; then
install -m 0755 AIS-catcher /usr/local/bin/AIS-catcher