-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·769 lines (679 loc) · 23.5 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·769 lines (679 loc) · 23.5 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
#!/bin/bash
set -uo pipefail
trap 'warn "Failed at line ${LINENO}: ${BASH_COMMAND}"; exit 1' ERR
COMPOSE_FILE="docker-compose.yml"
ENV_FILE=".env"
CACHE_FILE=".adsb_publisher_setup_save"
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
NC='\033[0m'
AUTO=false
[[ "${1:-}" == "--auto" || "${1:-}" == "-y" ]] && AUTO=true
ULTRAFEEDER_IMAGE="ghcr.io/sdr-enthusiasts/docker-adsb-ultrafeeder:telegraf"
log() { echo -e "${GREEN}[+]${NC} $1"; }
warn() { echo -e "${RED}[!]${NC} $1"; }
ask() { echo -ne "${CYAN}[?]${NC} $1"; }
load_cache() {
[[ -f "${CACHE_FILE}" ]] || return
log "Found previous answers in ${CACHE_FILE}"
# shellcheck source=/dev/null
source "${CACHE_FILE}"
}
save_answer() {
local key="$1" val="$2"
if grep -q "^${key}=" "${CACHE_FILE}" 2>/dev/null; then
sed -i "s|^${key}=.*|${key}=${val}|" "${CACHE_FILE}"
return
fi
echo "${key}=${val}" >> "${CACHE_FILE}"
}
# prompt with cached default: prompt_cached VAR_NAME "prompt text" "fallback_default"
prompt_cached() {
local var_name="$1" prompt_text="$2" fallback="${3:-}"
local cached="${!var_name:-${fallback}}"
if [[ "${AUTO}" == true && -n "${!var_name:-}" ]]; then
eval "${var_name}=\"\${cached}\""
log "${prompt_text}: ${cached}"
return
fi
local full_prompt="${prompt_text}"
[[ -n "${cached}" ]] && full_prompt="${full_prompt} [${cached}]"
ask "${full_prompt}: "
local input
read -r input < /dev/tty
eval "${var_name}=\"\${input:-\${cached}}\""
save_answer "${var_name}" "${!var_name}"
}
# prompt for port with cached default: prompt_port VAR_NAME "prompt text" "fallback_default"
prompt_port() {
local var_name="$1" prompt_text="$2" fallback="${3:-}"
local cached="${!var_name:-${fallback}}"
if [[ "${AUTO}" == true && -n "${!var_name:-}" ]]; then
eval "${var_name}=\"\${cached}\""
log "${prompt_text}: ${cached}"
return
fi
local full_prompt="${prompt_text} (- = no expose)"
[[ -n "${cached}" ]] && full_prompt="${full_prompt} [${cached}]"
ask "${full_prompt}: "
local input
read -r input < /dev/tty
if [[ "${input}" == "-" ]]; then
eval "${var_name}=''"
else
eval "${var_name}=\"\${input:-\${cached}}\""
fi
save_answer "${var_name}" "${!var_name}"
}
check_sudo() {
if ! sudo -v 2>/dev/null; then
warn "sudo access required. Run with a user that has sudo privileges."
exit 1
fi
}
check_deps() {
local missing=()
for cmd in docker curl jq; do
command -v "${cmd}" &>/dev/null && continue
missing+=("${cmd}")
done
if [[ ${#missing[@]} -eq 0 ]]; then
return
fi
warn "Missing required tools: ${missing[*]}"
warn "Install them and re-run this script."
exit 1
}
blacklist_kernel_drivers() {
local modules=(dvb_usb_rtl28xxu rtl2832 rtl2830 dvb_usb_rtl2832u dvb_usb_v2 dvb_core)
local missing=()
for mod in "${modules[@]}"; do
grep -rq "blacklist ${mod}" /etc/modprobe.d/ 2>/dev/null && continue
missing+=("${mod}")
done
if [[ ${#missing[@]} -eq 0 ]]; then
log "Kernel DVB drivers already blacklisted, skipping."
return
fi
log "Blacklisting kernel DVB drivers: ${missing[*]}..."
for mod in "${missing[@]}"; do
echo "blacklist ${mod}" | sudo tee -a /etc/modprobe.d/blacklist-rtlsdr.conf > /dev/null
done
sudo rmmod dvb_usb_rtl28xxu 2>/dev/null || true
sudo rmmod rtl2832 2>/dev/null || true
sudo rmmod rtl2830 2>/dev/null || true
log "Kernel drivers blacklisted."
}
pull_ultrafeeder_image() {
log "Pulling ultrafeeder image (used for SDR tools + runtime)..."
docker pull "${ULTRAFEEDER_IMAGE}" -q
log "Image pulled."
}
detect_location() {
log "Detecting location from IP..."
local geo
geo=$(curl -sf --max-time 5 "http://ip-api.com/json/?fields=lat,lon,timezone,city" 2>/dev/null) || return
DEFAULT_LAT=$(echo "${geo}" | jq -r '.lat // empty')
DEFAULT_LON=$(echo "${geo}" | jq -r '.lon // empty')
DEFAULT_TZ=$(echo "${geo}" | jq -r '.timezone // empty')
DEFAULT_CITY=$(echo "${geo}" | jq -r '.city // empty')
if [[ -z "${DEFAULT_LAT}" || -z "${DEFAULT_LON}" ]]; then
return
fi
log "Detected: ${DEFAULT_CITY} (${DEFAULT_LAT}, ${DEFAULT_LON}) ${DEFAULT_TZ}"
local elev
elev=$(curl -sf --max-time 5 "https://api.open-meteo.com/v1/elevation?latitude=${DEFAULT_LAT}&longitude=${DEFAULT_LON}" 2>/dev/null) || return
DEFAULT_ALT=$(echo "${elev}" | jq -r '.elevation[0] // empty' | cut -d. -f1)
if [[ -n "${DEFAULT_ALT}" ]]; then
log "Detected ground elevation: ${DEFAULT_ALT}m"
fi
}
collect_info() {
echo ""
log "=== Station Configuration ==="
echo ""
# geo-detect only fills in gaps not already cached
if [[ -z "${STATION_NAME:-}" || -z "${LAT:-}" || -z "${LON:-}" ]]; then
detect_location
STATION_NAME="${STATION_NAME:-${DEFAULT_CITY:-}}"
LAT="${LAT:-${DEFAULT_LAT:-}}"
LON="${LON:-${DEFAULT_LON:-}}"
ALT="${ALT:-${DEFAULT_ALT:-}}"
TZ_VAL="${TZ_VAL:-${DEFAULT_TZ:-Europe/Bucharest}}"
fi
prompt_cached STATION_NAME "Station name (no spaces, letters/numbers/-/_ only)"
prompt_cached LAT "Latitude"
prompt_cached LON "Longitude"
prompt_cached ALT "Altitude in meters above sea level"
prompt_cached TZ_VAL "Timezone" "Europe/Bucharest"
if [[ -z "${UUID:-}" ]]; then
UUID=$(cat /proc/sys/kernel/random/uuid)
fi
save_answer UUID "${UUID}"
log "UUID: ${UUID}"
echo ""
log "=== Port Configuration ==="
echo ""
prompt_port ULTRAFEEDER_PORT "Ultrafeeder web UI (tar1090/graphs1090) port" "10980"
prompt_port GRAFANA_PORT "Grafana dashboard port" "10984"
}
detect_sdr() {
echo ""
log "=== SDR Detection ==="
log "Detecting RTL-SDR devices via container..."
local output
output=$(docker run --rm --device /dev/bus/usb \
--entrypoint rtl_test "${ULTRAFEEDER_IMAGE}" -t 2>&1 | head -30) || true
local device_lines
device_lines=$(echo "${output}" | grep -E "^\s+[0-9]+:" || true)
if [[ -z "${device_lines}" ]]; then
warn "No RTL-SDR devices found. Plug one in and re-run."
exit 1
fi
local count
count=$(echo "${device_lines}" | wc -l)
echo ""
log "Found ${count} device(s):"
echo ""
while IFS= read -r line; do
local idx mfg product serial
idx=$(echo "${line}" | sed -E 's/^\s+([0-9]+):.*/\1/')
mfg=$(echo "${line}" | sed -E 's/^\s+[0-9]+:\s+//' | cut -d, -f1)
product=$(echo "${line}" | cut -d, -f2 | xargs)
serial=$(echo "${line}" | grep -oP 'SN:\s*\K.*' | xargs)
echo " [${idx}] ${mfg} ${product}"
echo " Serial: ${serial}"
echo ""
done <<< "${device_lines}"
if [[ "${count}" -eq 1 ]]; then
SDR_DEVICE_INDEX=0
save_answer SDR_DEVICE_INDEX 0
log "Single device found, using index 0."
else
prompt_cached SDR_DEVICE_INDEX "Which device index to use for ADS-B?" "0"
fi
prompt_cached SDR_PPM "SDR frequency correction in PPM (0 for TCXO dongles like RTL-SDR Blog V4)" "0"
}
signup_fr24() {
echo ""
prompt_cached DO_FR24 "Set up FlightRadar24? (y/n)" "${DO_FR24:-n}"
if [[ "${DO_FR24}" != "y" ]]; then
FR24_KEY=""
return
fi
if [[ -n "${FR24_KEY:-}" ]]; then
prompt_cached FR24_KEY "FR24 sharing key"
else
ask "Already have a FR24 sharing key? (y/n): "
read -r HAS_KEY < /dev/tty
if [[ "${HAS_KEY}" == "y" ]]; then
prompt_cached FR24_KEY "Enter your FR24 sharing key"
else
log "Starting FR24 signup process..."
docker run --rm -it --entrypoint /usr/bin/fr24feed \
ghcr.io/sdr-enthusiasts/docker-flightradar24 --signup
echo ""
prompt_cached FR24_KEY "Enter the sharing key you just received"
fi
fi
prompt_port FR24_PORT "FR24 status page port" "10981"
}
signup_piaware() {
echo ""
prompt_cached DO_PIAWARE "Set up FlightAware (piaware)? (y/n)" "${DO_PIAWARE:-n}"
if [[ "${DO_PIAWARE}" != "y" ]]; then
DO_PIAWARE="n"
PIAWARE_ID=""
return
fi
if [[ -n "${PIAWARE_ID:-}" ]]; then
prompt_cached PIAWARE_ID "FlightAware feeder ID"
else
ask "Already have a FlightAware feeder ID? (y/n): "
read -r HAS_PIAWARE < /dev/tty
if [[ "${HAS_PIAWARE}" == "y" ]]; then
prompt_cached PIAWARE_ID "Enter your FlightAware feeder ID"
else
PIAWARE_ID=""
log "Piaware will auto-generate a feeder ID on first start."
log "After launch, find it with: docker compose logs piaware | grep 'feeder ID'"
log "Then claim it at: https://flightaware.com/adsb/piaware/claim"
fi
fi
prompt_port PIAWARE_PORT "Piaware web UI port" "10982"
}
setup_planesnitch() {
echo ""
prompt_cached DO_PLANESNITCH "Set up planesnitch (aircraft alerts to Telegram/webhooks)? (y/n)" "${DO_PLANESNITCH:-n}"
if [[ "${DO_PLANESNITCH}" != "y" ]]; then
DO_PLANESNITCH="n"
return
fi
}
write_planesnitch_config() {
log "Writing planesnitch config..."
mkdir -p planesnitch/csv
mkdir -p planesnitch/images
# download all plane-alert-db CSVs
local csv_base="https://raw.githubusercontent.com/sdr-enthusiasts/plane-alert-db/main"
local csvs=("plane-alert-db" "plane-alert-mil" "plane-alert-gov" "plane-alert-pol" "plane-alert-pia" "plane-alert-civ")
for csv in "${csvs[@]}"; do
log "Downloading ${csv}.csv..."
curl -sf "${csv_base}/${csv}.csv" -o "planesnitch/csv/${csv}.csv" 2>/dev/null || warn "Failed to download ${csv}.csv"
done
cat > planesnitch/config.yaml.example <<EOF
poll_interval: 1m
display_units: aviation
locations:
${STATION_NAME}:
name: "${STATION_NAME}"
lat: ${LAT}
lon: ${LON}
radius: 150km
sources:
- type: ultrafeeder
url: http://ultrafeeder:80/data/aircraft.json
- type: adsb_lol
- type: adsb_fi
- type: airplanes_live
- type: adsb_one
watchlists:
emergencies:
type: squawk
values: ["7500", "7600", "7700", "7400", "7777"]
military:
type: icao_csv
source: /csv/plane-alert-mil.csv
government:
type: icao_csv
source: /csv/plane-alert-gov.csv
police:
type: icao_csv
source: /csv/plane-alert-pol.csv
interesting:
type: icao_csv
source: /csv/plane-alert-db.csv
pia:
type: icao_csv
source: /csv/plane-alert-pia.csv
civilian:
type: icao_csv
source: /csv/plane-alert-civ.csv
low_flyers:
type: proximity
min_altitude: 0ft
max_altitude: 3000ft
# No alerts enabled yet. Uncomment and edit the sections below.
# Full docs: https://github.com/psyb0t/docker-planesnitch
alerts: []
# alerts:
# - name: "Emergency Alert"
# watchlists: [emergencies]
# cooldown: 1m
# notify: [my_telegram]
#
# - name: "Military Spotter"
# watchlists: [military]
# cooldown: 5m
# notify: [my_telegram]
#
# - name: "Government Watch"
# watchlists: [government]
# cooldown: 5m
# notify: [my_telegram]
#
# - name: "Police Activity"
# watchlists: [police]
# cooldown: 5m
# notify: [my_telegram]
#
# - name: "Interesting Aircraft"
# watchlists: [interesting, pia, civilian]
# cooldown: 5m
# notify: [my_telegram]
#
# - name: "Low Flyer"
# watchlists: [low_flyers]
# cooldown: 10m
# notify: [my_telegram]
# notifications:
# my_telegram:
# type: telegram
# bot_token: "YOUR_BOT_TOKEN"
# chat_id: "YOUR_CHAT_ID"
#
# my_webhook:
# type: webhook
# url: "https://example.com/hook"
# headers:
# Authorization: "Bearer YOUR_TOKEN"
EOF
log "planesnitch example config written to planesnitch/config.yaml.example"
if [[ ! -f planesnitch/config.yaml ]]; then
cp planesnitch/config.yaml.example planesnitch/config.yaml
log "No existing config found — copied example to planesnitch/config.yaml"
fi
echo ""
log "Edit planesnitch/config.yaml to set up alerts and notifications."
log "Docs: https://github.com/psyb0t/docker-planesnitch"
}
write_env() {
log "Writing ${ENV_FILE}..."
cat > "${ENV_FILE}" <<EOF
FEEDER_TZ=${TZ_VAL}
FEEDER_LAT=${LAT}
FEEDER_LONG=${LON}
FEEDER_ALT_M=${ALT}
FEEDER_NAME=${STATION_NAME}
ADSB_SDR_DEVICE=${SDR_DEVICE_INDEX}
ADSB_SDR_GAIN=autogain
ADSB_SDR_PPM=${SDR_PPM}
UUID=${UUID}
FR24_SHARING_KEY=${FR24_KEY}
PIAWARE_FEEDER_ID=${PIAWARE_ID}
EOF
log "Environment file written."
}
write_compose() {
log "Writing ${COMPOSE_FILE}..."
cat > "${COMPOSE_FILE}" <<'YAML'
services:
ultrafeeder:
image: ghcr.io/sdr-enthusiasts/docker-adsb-ultrafeeder:telegraf-build-373
restart: unless-stopped
device_cgroup_rules:
- 'c 189:* rwm'
environment:
- LOGLEVEL=error
- TZ=${FEEDER_TZ}
- READSB_DEVICE_TYPE=rtlsdr
- READSB_RTLSDR_DEVICE=${ADSB_SDR_DEVICE}
- READSB_RTLSDR_PPM=${ADSB_SDR_PPM}
- READSB_LAT=${FEEDER_LAT}
- READSB_LON=${FEEDER_LONG}
- READSB_ALT=${FEEDER_ALT_M}m
- READSB_GAIN=${ADSB_SDR_GAIN}
- READSB_RX_LOCATION_ACCURACY=2
- READSB_STATS_RANGE=true
- UUID=${UUID}
- MLAT_USER=${FEEDER_NAME}
- ULTRAFEEDER_CONFIG=
adsb,feed.adsb.fi,30004,beast_reduce_plus_out;
adsb,feed.adsb.one,64004,beast_reduce_plus_out;
adsb,feed.planespotters.net,30004,beast_reduce_plus_out;
adsb,feed.theairtraffic.com,30004,beast_reduce_plus_out;
adsb,data.avdelphi.com,24999,beast_reduce_plus_out;
adsb,feed.adsbexchange.com,30004,beast_reduce_plus_out;
adsb,feed.airplanes.live,30004,beast_reduce_plus_out;
adsb,in.adsb.lol,30004,beast_reduce_plus_out;
adsb,skyfeed.hpradar.com,30004,beast_reduce_plus_out;
adsb,dati.flyitalyadsb.com,4905,beast_reduce_plus_out;
mlat,feed.adsb.fi,31090,39000;
mlat,feed.adsb.one,64006,39002;
mlat,mlat.planespotters.net,31090,39003;
mlat,feed.theairtraffic.com,31090,39004;
mlat,feed.adsbexchange.com,31090,39005;
mlat,feed.airplanes.live,31090,39006;
mlat,in.adsb.lol,31090,39007;
mlat,skyfeed.hpradar.com,31090,39008;
mlat,dati.flyitalyadsb.com,30100,39009;
mlathub,piaware,30105,beast_in;
mlathub,fr24,30105,beast_in
- TAR1090_DEFAULTCENTERLAT=${FEEDER_LAT}
- TAR1090_DEFAULTCENTERLON=${FEEDER_LONG}
- TAR1090_MESSAGERATEINTITLE=true
- TAR1090_PAGETITLE=${FEEDER_NAME}
- TAR1090_PLANECOUNTINTITLE=true
- TAR1090_ENABLE_AC_DB=true
- TAR1090_FLIGHTAWARELINKS=true
- GRAPHS1090_DARKMODE=true
- PROMETHEUS_ENABLE=true
volumes:
- ./ultrafeeder/globe_history:/var/globe_history
- ./ultrafeeder/graphs1090:/var/lib/collectd
- /proc/diskstats:/proc/diskstats:ro
- /dev:/dev:ro
tmpfs:
- /run:exec,size=256M
- /tmp:size=128M
- /var/log:size=32M
healthcheck:
test: ["CMD-SHELL", "timeout 5 nc -z localhost 30003 && test -f /run/readsb/aircraft.json"]
interval: 10s
timeout: 10s
retries: 5
start_period: 120s
YAML
# Remove mlathub lines for disabled services
if [[ "${DO_PIAWARE}" != "y" ]]; then
sed -i '/mlathub,piaware/d' "${COMPOSE_FILE}"
fi
if [[ -z "${FR24_KEY}" ]]; then
sed -i '/mlathub,fr24/d' "${COMPOSE_FILE}"
fi
if [[ -n "${ULTRAFEEDER_PORT}" ]]; then
sed -i '/^ ultrafeeder:/a\ ports:\n - '"${ULTRAFEEDER_PORT}"':80' "${COMPOSE_FILE}"
fi
if [[ -n "${FR24_KEY}" ]]; then
cat >> "${COMPOSE_FILE}" <<'YAML'
fr24:
image: ghcr.io/sdr-enthusiasts/docker-flightradar24:latest@sha256:47c376bb02ff42e292c191fff5c76163aab1767cf7514781475dbd4dfca8dd61
restart: unless-stopped
depends_on:
ultrafeeder:
condition: service_healthy
environment:
- BEASTHOST=ultrafeeder
- FR24KEY=${FR24_SHARING_KEY}
tmpfs:
- /var/log
YAML
if [[ -n "${FR24_PORT}" ]]; then
sed -i '/^ fr24:/a\ ports:\n - '"${FR24_PORT}"':8754' "${COMPOSE_FILE}"
fi
fi
if [[ "${DO_PIAWARE}" == "y" ]]; then
cat >> "${COMPOSE_FILE}" <<'YAML'
piaware:
image: ghcr.io/sdr-enthusiasts/docker-piaware:v10.0
restart: unless-stopped
depends_on:
ultrafeeder:
condition: service_healthy
environment:
- BEASTHOST=ultrafeeder
- TZ=${FEEDER_TZ}
- FEEDER_ID=${PIAWARE_FEEDER_ID}
- LAT=${FEEDER_LAT}
- LONG=${FEEDER_LONG}
tmpfs:
- /run:exec,size=64M
- /var/log
YAML
if [[ -n "${PIAWARE_PORT}" ]]; then
sed -i '/^ piaware:/a\ ports:\n - '"${PIAWARE_PORT}"':8080' "${COMPOSE_FILE}"
fi
fi
cat >> "${COMPOSE_FILE}" <<'YAML'
prometheus:
image: prom/prometheus:v3.11.3
restart: unless-stopped
volumes:
- ./prometheus/config:/etc/prometheus:ro
- ./prometheus/data:/prometheus
tmpfs:
- /tmp
grafana:
image: grafana/grafana-oss:13.0.1
restart: unless-stopped
depends_on:
- prometheus
environment:
- GF_INSTALL_PLUGINS=marcusolsson-json-datasource
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_SECURITY_ADMIN_USER=admin
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_AUTH_DISABLE_SIGNOUT_MENU=false
- GF_SECURITY_ALLOW_EMBEDDING=true
volumes:
- ./grafana/appdata:/var/lib/grafana
- ./grafana/provisioning:/etc/grafana/provisioning:ro
- ./grafana/dashboards:/var/lib/grafana/dashboards:ro
YAML
if [[ -n "${GRAFANA_PORT}" ]]; then
sed -i '/^ grafana:/a\ ports:\n - '"${GRAFANA_PORT}"':3000' "${COMPOSE_FILE}"
fi
if [[ "${DO_PLANESNITCH}" == "y" ]]; then
cat >> "${COMPOSE_FILE}" <<'YAML'
planesnitch:
image: psyb0t/planesnitch:v1.7.0
restart: unless-stopped
depends_on:
ultrafeeder:
condition: service_healthy
volumes:
- ./planesnitch/config.yaml:/app/config.yaml:ro
- ./planesnitch/csv:/csv:ro
- ./planesnitch/images:/images
YAML
fi
log "Docker compose file written."
}
create_dirs() {
mkdir -p ultrafeeder/globe_history
mkdir -p ultrafeeder/graphs1090
mkdir -p prometheus/config
mkdir -p prometheus/data
sudo chown 65534:65534 prometheus/data
mkdir -p grafana/appdata
sudo chown 472:0 grafana/appdata
mkdir -p grafana/provisioning/datasources
mkdir -p grafana/provisioning/dashboards
mkdir -p grafana/dashboards
write_prometheus_config
write_grafana_provisioning
}
write_prometheus_config() {
log "Writing Prometheus config..."
cat > prometheus/config/prometheus.yml <<'EOF'
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'ultrafeeder'
static_configs:
- targets: ['ultrafeeder:9273', 'ultrafeeder:9274']
EOF
}
write_grafana_provisioning() {
log "Writing Grafana datasource provisioning..."
cat > grafana/provisioning/datasources/prometheus.yml <<'EOF'
apiVersion: 1
datasources:
- name: ultrafeeder
uid: ultrafeeder-prometheus
type: prometheus
access: proxy
url: http://prometheus:9090/
isDefault: true
EOF
log "Writing Grafana dashboard provisioning..."
cat > grafana/provisioning/dashboards/dashboards.yml <<'EOF'
apiVersion: 1
providers:
- name: default
orgId: 1
folder: ''
type: file
disableDeletion: false
updateIntervalSeconds: 10
options:
path: /var/lib/grafana/dashboards
foldersFromFilesStructure: false
EOF
log "Downloading ultrafeeder Grafana dashboard..."
curl -sf "https://grafana.com/api/dashboards/18398/revisions/latest/download" \
-o grafana/dashboards/ultrafeeder.json 2>/dev/null || warn "Failed to download dashboard, import manually: ID 18398"
if [[ -f grafana/dashboards/ultrafeeder.json ]]; then
log "Patching dashboard..."
sed -i 's/\${DS_PROMETHEUS}/ultrafeeder-prometheus/g' grafana/dashboards/ultrafeeder.json
# Replace feeder_url placeholder with actual server address
local ip
ip=$(hostname -I | awk '{print $1}')
sed -i "s|http://feeder_url|http://${ip}:${ULTRAFEEDER_PORT}|g" grafana/dashboards/ultrafeeder.json
# Remove library panels (UAT/dump978 stuff that needs library elements we don't have)
jq 'del(.__inputs, .__requires, .__elements) | .id = null | .panels = [.panels[] | select(.libraryPanel == null) | if .panels then .panels = [.panels[] | select(.libraryPanel == null)] else . end]' \
grafana/dashboards/ultrafeeder.json > grafana/dashboards/ultrafeeder.json.tmp \
&& mv grafana/dashboards/ultrafeeder.json.tmp grafana/dashboards/ultrafeeder.json
# Add missing Mode-S metric and fix refId sequence
python3 -c '
import json
with open("grafana/dashboards/ultrafeeder.json") as f:
d = json.load(f)
for p in d["panels"]:
if p.get("title") == "Aircraft Counts":
if not any("mode_s" in t.get("expr","") for t in p.get("targets",[])):
t = dict(p["targets"][-1])
t["expr"] = "readsb_aircraft_mode_s{job=\"ultrafeeder\"}"
t["legendFormat"] = "Mode-S"
p["targets"].append(t)
for i, t in enumerate(p["targets"]):
t["refId"] = chr(65 + i)
break
with open("grafana/dashboards/ultrafeeder.json","w") as f:
json.dump(d, f, indent=2)
'
fi
}
launch() {
echo ""
log "=== Launching ADS-B Publisher ==="
docker compose down --remove-orphans 2>/dev/null || true
docker compose pull
docker compose up -d --force-recreate
LOCAL_IP=$(hostname -I | awk '{print $1}')
echo ""
log "=== DONE ==="
echo ""
[[ -n "${ULTRAFEEDER_PORT}" ]] && log "tar1090 map: http://${LOCAL_IP}:${ULTRAFEEDER_PORT}"
[[ -n "${ULTRAFEEDER_PORT}" ]] && log "graphs1090 stats: http://${LOCAL_IP}:${ULTRAFEEDER_PORT}/graphs1090"
[[ -n "${FR24_KEY}" && -n "${FR24_PORT}" ]] && log "FR24 status: http://${LOCAL_IP}:${FR24_PORT}"
[[ "${DO_PIAWARE}" == "y" && -n "${PIAWARE_PORT}" ]] && log "Piaware: http://${LOCAL_IP}:${PIAWARE_PORT}"
[[ -n "${GRAFANA_PORT}" ]] && log "Grafana: http://${LOCAL_IP}:${GRAFANA_PORT}"
[[ "${DO_PLANESNITCH}" == "y" ]] && log "planesnitch: running (no alerts until you edit planesnitch/config.yaml)"
echo ""
log "Publishing to: adsb.fi, adsb.one, adsb.lol, planespotters.net, theairtraffic.com, avdelphi.com, adsbexchange.com, airplanes.live, hpradar.com, flyitalyadsb.com"
[[ -n "${FR24_KEY}" ]] && log "Publishing to: FlightRadar24"
[[ "${DO_PIAWARE}" == "y" ]] && log "Publishing to: FlightAware"
echo ""
if [[ -z "${PIAWARE_ID}" && "${DO_PIAWARE}" == "y" ]]; then
warn "Claim your piaware feeder at: https://flightaware.com/adsb/piaware/claim"
warn "Find your feeder ID with: docker compose logs piaware | grep 'feeder ID'"
fi
log "Station UUID: ${UUID}"
log "Manage: docker compose [up -d|down|logs -f]"
}
main() {
echo ""
echo " ╔══════════════════════════════════════╗"
echo " ║ ADS-B Publisher Setup ║"
echo " ║ Publish ALL the things. ║"
echo " ╚══════════════════════════════════════╝"
echo ""
load_cache
check_sudo
check_deps
blacklist_kernel_drivers
pull_ultrafeeder_image
collect_info
detect_sdr
signup_fr24
signup_piaware
setup_planesnitch
write_env
write_compose
create_dirs
[[ "${DO_PLANESNITCH}" == "y" ]] && write_planesnitch_config
launch
}
main "$@"