Repository navigation
Expand file tree
/
Copy pathairstack.sh
More file actions
executable file
·2467 lines (2209 loc) · 109 KB
/
Copy pathairstack.sh
File metadata and controls
executable file
·2467 lines (2209 loc) · 109 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
# airstack - A convenience tool for AirStack development
#
# This script provides a unified interface for common development tasks
# in the AirStack project, including setup, installation, and container management.
# Re-exec under bash 4+ if necessary. macOS ships bash 3.2 which can't handle
# `declare -A` (associative arrays) used throughout this script. Searches for
# a newer bash via $AIRSTACK_BASH, then common Homebrew install paths, then
# any `bash` on PATH that reports version >= 4. Sets AIRSTACK_REEXEC_BASH=1
# to guard against infinite re-exec loops.
if [ -z "${AIRSTACK_REEXEC_BASH:-}" ] && [ "${BASH_VERSINFO[0]:-0}" -lt 4 ]; then
_airstack_candidates=(
"${AIRSTACK_BASH:-}"
/opt/homebrew/bin/bash # Apple Silicon Homebrew
/usr/local/bin/bash # Intel Homebrew
/opt/local/bin/bash # MacPorts
)
if command -v bash5 >/dev/null 2>&1; then
_airstack_candidates+=("$(command -v bash5)")
fi
# Add any `bash` on PATH whose version is >= 4 (other than the one we just
# got here from, which is < 4 by the if-check above).
for _alt in $(command -v -a bash 2>/dev/null); do
_airstack_candidates+=("$_alt")
done
for _airstack_alt_bash in "${_airstack_candidates[@]}"; do
[ -z "$_airstack_alt_bash" ] && continue
[ -x "$_airstack_alt_bash" ] || continue
# Probe BASH_VERSINFO[0] without sourcing the script.
if "$_airstack_alt_bash" -c '[ "${BASH_VERSINFO[0]:-0}" -ge 4 ]' 2>/dev/null; then
export AIRSTACK_REEXEC_BASH=1
exec "$_airstack_alt_bash" "$0" "$@"
fi
done
cat >&2 <<'EOF'
[ERROR] airstack.sh requires bash 4 or newer (your bash is 3.x).
macOS ships bash 3.2 by default; install a modern bash with:
brew install bash
Or set AIRSTACK_BASH=/path/to/bash >= 4 before invoking this script.
EOF
exit 1
fi
unset AIRSTACK_REEXEC_BASH
set -e
# Script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$SCRIPT_DIR"
# Directory for command modules
MODULES_DIR="$PROJECT_ROOT/.airstack/modules"
# Create modules directory if it doesn't exist
mkdir -p "$MODULES_DIR"
# Shared helpers (_require_python_yaml, _env_value, _robot_containers,
# _container_identity) — sourced explicitly BEFORE load_command_modules so
# both built-in commands and every command module can rely on them.
if [ -f "$MODULES_DIR/_lib.sh" ]; then
source "$MODULES_DIR/_lib.sh"
fi
# Color codes for output formatting
BOLDCYAN='\033[38;5;14;1m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print usage information
function print_usage {
local version
version="$(get_VERSION)"
echo -e "${BOLDCYAN}AirStack Development Tool v${version} ($SCRIPT_DIR)${NC}"
echo ""
echo "Usage: airstack <command> [options]"
echo ""
echo "Available commands:"
# Sort commands alphabetically
local sorted_commands=($(echo "${!COMMANDS[@]}" | tr ' ' '\n' | sort))
# Calculate the longest command name for padding
local max_len=0
for cmd in "${sorted_commands[@]}"; do
if [ ${#cmd} -gt $max_len ]; then
max_len=${#cmd}
fi
done
# Add 4 spaces of padding
max_len=$((max_len + 4))
# Print each command with its help text
for cmd in "${sorted_commands[@]}"; do
# Skip hidden commands (those starting with _ or marked hidden)
if [[ "$cmd" == _* || -n "${COMMAND_HIDDEN[$cmd]:-}" ]]; then
continue
fi
# Get help text or use a default
local help_text="${COMMAND_HELP[$cmd]:-No description available}"
# Calculate padding
local padding=$((max_len - ${#cmd}))
local pad=$(printf '%*s' "$padding" '')
echo " $cmd$pad$help_text"
done
echo ""
echo "For more information on a command, run: airstack help <command>"
echo "To see all available commands, run: airstack commands"
echo ""
echo "Note: The airstack command will automatically use the airstack.sh script from the"
echo "current directory or nearest parent directory containing an AirStack repository."
}
# Print command-specific help
function print_command_help {
local command="$1"
# Check if command exists
if [[ -z "${COMMANDS[$command]}" ]]; then
log_error "Unknown command: $command"
print_usage
return 1
fi
# Get help text
local help_text="${COMMAND_HELP[$command]:-No description available}"
# Print command-specific help
echo -e "${BLUE}airstack $command${NC} - $help_text"
echo ""
# Command-specific usage and options
case "$command" in
install)
echo "Usage: airstack install [options]"
echo ""
echo "Options:"
echo " --force Force reinstallation of components"
echo " --no-docker Skip Docker installation"
;;
setup)
echo "Usage: airstack setup [options]"
echo ""
echo "Options:"
echo " --no-shell Don't modify shell configuration"
echo " --no-config Skip configuration tasks (Isaac Sim, Nucleus, Git hooks)"
echo ""
echo "This command adds an 'airstack' function to your shell profile that will"
echo "automatically find and use the airstack.sh script from the current directory"
echo "or nearest parent directory containing an AirStack repository."
;;
up)
echo "Usage: airstack up [service_name] [options]"
echo ""
echo "Launch-intent options (consumed by airstack; they derive + export env vars):"
echo " --sim isaac|airsim|simple"
echo " Select the simulator: swaps the compose profile and"
echo " the matching URDF_FILE. 'simple' launches the"
echo " lightweight kinematic simple-sim (no PX4/MAVROS):"
echo " the simple-robot service replaces robot-desktop"
echo " (SIM_TYPE=simple), the 'desktop' profile is dropped"
echo " (no GCS), and URDF_FILE is left unchanged."
echo " --robots N Robot count (NUM_ROBOTS); on Isaac also selects the"
echo " matching one-/multi-drone launch script."
echo " --stack NAME Launch a stack folder (stacks/NAME/launch/stack.launch.xml)."
echo " Stacks are the only launch dispatch; no --stack (and no stack"
echo " env) launches the trunk reference stack full_default."
echo " NAME:ENTRY selects an alternate entry file"
echo " (launch/ENTRY.launch.xml). See docs/development/stacks.md."
echo " --fleet NAME Launch a fleet (config/fleets/NAME.yaml): exports FLEET_CONFIG_FILE,"
echo " derives NUM_ROBOTS, selects the Isaac fleet spawner, and (for"
echo " heterogeneous fleets) generates the per-robot services plus"
echo " split-stack DDS-router configs. Mutually exclusive with"
echo " --robots. See docs/development/fleets.md."
echo " --scene NAME Select the simulation scene by shortname (simulation/scenes.yaml):"
echo " maps NAME to the selected simulator's scene reference and"
echo " exports it (Isaac: ISAAC_SIM_SCENE [+ ISAAC_SIM_STAGE_SCALE] —"
echo " a Pegasus catalog key or Nucleus USD URL; MS AirSim:"
echo " MS_AIRSIM_SCENE — a pre-built UE4 scene, auto-fetched if"
echo " missing). Unknown scene = error + table of available scenes."
echo " --headless Run the sim without a GUI (ISAAC_SIM_HEADLESS/MS_AIRSIM_HEADLESS)."
echo " --play / --no-play Start the sim playing, or paused (PLAY_SIM_ON_START)."
echo " --no-autolaunch Start containers idle (AUTOLAUNCH=false; launch manually)."
echo " --wait After starting, block until flight-ready (airstack ready)."
echo " --dry-run Validate + print the derived launch config; start nothing."
echo " --config-only Like --dry-run, but only logical launch-config checks"
echo " (no Docker, credentials, images, or submodule prereqs)."
echo ""
echo "Anything else (e.g. --build, service names) is passed through to"
echo "'docker compose up'."
;;
fleet)
echo "Usage: airstack fleet <subcommand>"
echo ""
echo "Manage fleet files (RFC #380 §2): config/fleets/*.yaml declare who"
echo "exists, which vehicle (body), which stack (brain), and which ground"
echo "hosts run each split stack's offboard half."
echo "Guide: docs/development/fleets.md"
echo ""
echo "Subcommands:"
echo " list Table of fleets: robots, vehicles, stacks, shape"
echo " (homogeneous / heterogeneous / +split)."
echo " generate <fleet> Write .airstack/generated/docker-compose.fleet.yaml:"
echo " one self-contained service per robot plus one per"
echo " (ground host x offboard tenant) — AND the DDS-router"
echo " configs for every split stack the fleet places"
echo " (.airstack/generated/dds_router.<stack>.yaml)."
echo " Homogeneous fleets need no generation"
echo " (deploy.replicas handles them) — the command says so"
echo " and writes nothing."
echo ""
echo "Run a fleet: airstack up --fleet <name> [--sim isaac|airsim]"
;;
osmo)
echo "Usage: airstack osmo <subcommand> [options]"
echo ""
echo "Develop AirStack on an ephemeral OSMO GPU pod from any laptop (Mac/"
echo "Windows/Linux) — wraps 'osmo workflow submit/port-forward/logs/cancel'"
echo "for osmo/workflows/airstack-dev.yaml. Needs only the cross-platform"
echo "'osmo' CLI (no local Docker). Tutorial: docs/tutorials/airstack_on_osmo.md"
echo ""
echo "Subcommands:"
echo " setup One-time per-user credential registration (airlab-docker-"
echo " registry, airlab-docker-login, airlab-nucleus). Re-run to"
echo " rotate credentials (e.g. a new Nucleus API token)."
echo " up [--pool POOL] [--key PATH] [--branch BRANCH]"
echo " Submit the airstack-dev workflow with your SSH pubkey"
echo " injected. --branch defaults to your current local branch;"
echo " the workflow id is saved to ~/.airstack/osmo-state for the"
echo " other subcommands (override with AIRSTACK_OSMO_WF)."
echo " logs Follow the workspace task logs (OSMO_LOGS_TASK /"
echo " OSMO_LOGS_TAIL override task and tail length)."
echo " ide [--no-open] [code|cursor]"
echo " Port-forward sshd (2200:22) and open VS Code/Cursor on"
echo " Host airstack-osmo."
echo " webrtc Port-forward the Isaac Sim WebRTC ports (TCP foreground"
echo " + UDP background)."
echo " foxglove Install the AirStack Foxglove extensions locally, then"
echo " port-forward the GCS Foxglove websocket (8766:8766)."
echo " OSMO_FOXGLOVE_EXT_DIR overrides the target dir;"
echo " OSMO_FOXGLOVE_SKIP_EXTENSIONS=1 skips the install."
echo " down Cancel the active workflow (push your work to git first"
echo " — the pod filesystem is ephemeral)."
echo ""
echo "Typical session: airstack osmo up --pool airstack && airstack osmo ide"
;;
sync)
echo "Usage: airstack sync [--no-hooks]"
echo ""
echo "Options:"
echo " --no-hooks Skip module host_setup hooks during the module sync step"
echo ""
echo "Sync the checkout from airstack.yaml (RFC #380 §3): upsert its"
echo "modules: additions into modules.repos (naming every deviation), run"
echo "the module sync, fetch declared external stack repos into gitignored"
echo "stacks/.external/<alias>/ (fleets address them as <alias>/<stack>),"
echo "validate the declared fleet, warn if release: has drifted off the"
echo ".env VERSION line, and record the resolved sources in"
echo ".airstack/generated/effective_sources.yaml."
echo ""
echo "NOT done (future work): rewriting .env (it stays hand-edited) and"
echo "release-set pin resolution against a registry (RFC #379 §7)."
;;
images)
echo "Usage: airstack images [subcommand] [service_name...] [options]"
echo ""
echo "Manage the Docker Compose service images. Compose subcommands pass"
echo "env variables from .env and any prepended environment variables"
echo "(e.g. VERSION=x airstack images build robot-desktop)."
echo ""
echo "Subcommands:"
echo " list (default) List Docker images whose repository/tag contains the"
echo " PROJECT_NAME value from .env (all images if unset)."
echo " build [service...]"
echo " Build or rebuild Docker Compose services."
echo " Options (any other flags pass through to"
echo " 'docker compose build'):"
echo " --no-cache Build without using the cache"
echo " --pull Always pull newer base images"
echo " --push Push service images after build"
echo " --progress=VALUE auto|tty|plain|json|quiet"
echo " --env-file FILE Alternate environment file"
echo " push [service...]"
echo " Push service images to the registry."
echo " pull [service...]"
echo " Pull service images from the registry."
echo " delete [-y|--yes]"
echo " Delete all local images matching PROJECT_NAME"
echo " (lists the matches and asks first unless -y)."
echo " rm [-f|--force] [-y|--yes] <search_term>"
echo " Remove images whose repository:tag contains the"
echo " search term (fixed-string match; asks first"
echo " unless -y). E.g. airstack images rm -f -y myimage"
;;
connect)
echo "Usage: airstack connect [container_name] [options]"
echo ""
echo "By default, attaches to an existing tmux session inside the container."
echo "Exiting tmux fully disconnects from the container."
echo ""
echo "Options:"
echo " --command=CMD Run a specific command instead of attaching to tmux (e.g., --command=bash)"
;;
down)
echo "Usage: airstack down [service_name]"
echo ""
echo "If no service name is provided, all services will be shutdown."
;;
status)
echo "Usage: airstack status"
echo ""
echo "Shows the status of all running containers."
;;
logs)
echo "Usage: airstack logs [container_name] [options]"
echo ""
echo "View logs for the specified container."
echo ""
echo "Options:"
echo " --no-follow Don't follow log output"
echo " --tail=N Show only the last N lines (default: all)"
;;
version)
echo "Usage: airstack version"
echo ""
echo "Display the current AirStack version from VERSION in .env file."
;;
config)
echo "Usage: airstack config [subcommand]"
echo ""
echo "Configure the AirStack environment. With no subcommand, runs all"
echo "configuration tasks in order (isaac-sim, nucleus, git-hooks)."
echo ""
echo "Subcommands:"
echo " all (default) Run all configuration tasks below."
echo " isaac-sim Generate the default Isaac Sim user.config.json"
echo " (asks before resetting an existing one)."
echo " nucleus Configure the AirLab Omniverse Nucleus login"
echo " (prompts for an API token; blank to skip)."
echo " git-hooks Install the repo's pre-commit hook"
echo " (docker image tag versioning)."
;;
ready)
echo "Usage: airstack ready [--json]"
echo ""
echo "Wait until the running stack is flight-ready, gate by gate:"
echo " 1. robot containers running"
echo " 2. sim publishing /clock"
echo " 3. sentinel autonomy nodes up (per robot)"
echo " 4. PX4 ready: MAVROS connected, then EKF odometry streaming"
echo ""
echo "Options:"
echo " --json Print a JSON verdict on stdout (progress goes to stderr):"
echo " {\"ready\": bool, \"elapsed_s\": N, \"gates\": {...}}"
echo ""
echo "Budgets are env-overridable: READY_CONTAINERS_TIMEOUT, READY_CLOCK_TIMEOUT,"
echo "READY_NODES_TIMEOUT, READY_PX4_TIMEOUT, READY_POLL_INTERVAL."
;;
test)
echo "Usage: airstack test [pytest options]"
echo ""
echo "Build the containerized test runner (tests/docker/) and run pytest"
echo "inside it. All arguments are forwarded directly to pytest."
echo "Results are written to tests/results/<timestamp>/."
echo ""
echo "Test marks (-m) — see tests/pytest.ini:"
echo " unit Fast hermetic tests (no Docker stack)"
echo " build_docker Docker image build tests (no GPU needed)"
echo " build_packages colcon workspace build tests (no GPU needed)"
echo " integration Robot container + a host-side component (no sim/GPU)"
echo " liveliness Container and process health (Docker, tmux, sentinel nodes)"
echo " wiring Observed wiring snapshot, drift-checked vs the committed golden"
echo " sensors Sim and robot sensor topic rates, LiDAR validation, sim RTF"
echo " takeoff_hover_land Takeoff / hover / land flight chain"
echo " autonomy Fixed-pattern trajectory path-tracker benchmark"
echo " waypoint_flight Ordered-waypoint navigation judged on the odometry track"
echo " simple_sim Simple-sim smoke test (containers, /clock, sentinel nodes;"
echo " run with --sim simplesim --num-robots 1)"
echo " optitrack OptiTrack NatNet end-to-end (tests live in the asm_optitrack module)"
echo " infrastructure Readiness/prerequisite checks (CI environment faults)"
echo ""
echo "AirStack-specific options (defaults from tests/conftest.py):"
echo " --sim=TARGETS Comma-separated sim targets: isaacsim, msairsim,"
echo " simplesim (default: isaacsim)"
echo " --num-robots=COUNTS Comma-separated robot counts (default: 1,3)"
echo " --stack=NAME Stack folder under stacks/ to launch (default:"
echo " the full_default dispatch)"
echo " --fleet=NAME Fleet preset under config/fleets/ (derives the"
echo " robot count, overriding --num-robots)"
echo " --stress-iterations=N Up/down cycles per config (default: 1)"
echo " --stable-duration=SECS Seconds test_stable polls for (default: 120)"
echo " --stable-interval=SECS Seconds between polls (default: 10)"
echo " --takeoff-velocities=LIST Comma-separated takeoff/land speeds in m/s"
echo " (default: 0.5)"
echo " --trajectory-types=LIST Fixed trajectory types for the autonomy mark"
echo " (default: Circle,Figure8,Racetrack,Line)"
echo " --waypoints='x,y,z; ...' Ordered waypoint route for waypoint_flight"
echo " (default: open 30 m square, 3 corners, +10 m)"
echo " --waypoint-tolerance=M Pass distance to intermediate waypoints (default: 15)"
echo " --goal-tolerance=M Pass distance to the final waypoint (default: 2.5)"
echo " --waypoint-timeout=SECS Per-waypoint time budget (default: 120)"
echo " --gui Show simulator GUI (default: headless)"
echo " --no-image-build CI flag for system-tests.yml (ignored by pytest)"
echo ""
echo "Examples:"
echo " # Build tests only — fast, no GPU needed"
echo " airstack test -m 'build_docker or build_packages' -v"
echo ""
echo " # Liveliness run — ms-airsim, 1 robot, 60 s stability window"
echo " airstack test -m liveliness --sim msairsim --num-robots 1 \\"
echo " --stress-iterations 1 --stable-duration 60 -v"
echo ""
echo " # Takeoff/hover/land run — at 0.5, 1, and 2 m/s"
echo " airstack test -m takeoff_hover_land --sim msairsim --num-robots 1 \\"
echo " --stress-iterations 1 --takeoff-velocities 0.5,1,2 -v"
;;
docs)
echo "Usage: airstack docs [serve]"
echo ""
echo "Build documentation. If 'serve' is specified, also start a local server."
;;
module)
echo "Usage: airstack module <subcommand> [options]"
echo ""
echo "Manage AirStack modules (RFC #379): thin external repos declared in"
echo "./modules.repos (vcs2l format, PINNED to tags/SHAs — never branches),"
echo "synced into the gitignored ./modules/ dir and overlaid into the checkout"
echo "by tools/module_overlay.py. Guide: docs/development/modules.md"
echo ""
echo "Subcommands:"
echo " add <git-url|local-path> [--version <tag-or-sha>] [--no-hooks]"
echo " Record a module in modules.repos and sync. Git URLs MUST be"
echo " pinned with --version (branch names like main/develop are"
echo " refused). Local paths are recorded under x-local-modules."
echo " sync [--no-hooks]"
echo " Clone/link everything in modules.repos (vcs import --recursive),"
echo " validate each module.yaml, place overlay symlinks, regenerate"
echo " .airstack/generated/docker-compose.modules.yaml, run host_setup"
echo " hooks (skipped with --no-hooks)."
echo " list Table of modules: name, type, version/pin, targets, valid."
echo " remove <name> Drop the modules.repos entry, checkout, and overlay artifacts."
echo " create --in-tree <name>"
echo " Scaffold robot/ros_ws/src/modules/<name>/ (stub module.yaml,"
echo " ament_python package, launch file with canonical-default topic"
echo " args and no remaps, test/) for fork research (RFC #379 §11)."
echo " lock [--check-conflicts] [--build]"
echo " Recompute the Docker layer plan + modules.lock (RFC #379 §6:"
echo " .airstack/generated/layer_plan.json); extra flags pass through"
echo " to tools/compose_module_layers.py."
echo " doctor [--drift]"
echo " No args: validate all manifests + overlay integrity (exit 1"
echo " only when the overlay is broken). --drift: classify changes"
echo " vs merge-base with origin/develop into module-contained vs"
echo " extraction debt — informs, never blocks (always exit 0)."
echo ""
echo "After sync, just start the stack: 'airstack up' includes the generated"
echo "module mounts automatically (opt out with AIRSTACK_NO_MODULE_COMPOSE=1)."
;;
stack)
echo "Usage: airstack stack <subcommand> [options]"
echo ""
echo "Manage stack folders (RFC #379 §3): self-contained topologies under"
echo "stacks/ — pinned modules.repos, launch/ entry points (one per host"
echo "role for split stacks, plus bridge.yaml), docker-compose stub, and a"
echo "generated wiring.md. Guide: docs/development/stacks.md"
echo ""
echo "Subcommands:"
echo " list Table of stacks: name, entry points (+bridge marker for"
echo " split stacks), wiring.md present?, airstack_compat."
echo " new <source> <dest>"
echo " Copy a reference stack to stacks/<dest>. Refuses to"
echo " overwrite; deliberately does NOT copy wiring.md (it is"
echo " the source's observed graph) — regenerate it with"
echo " 'airstack test -m wiring --stack <dest>'."
echo " diff <a> <b> [--json]"
echo " Compare two stacks' generated wiring.md graphs"
echo " (tools/stack_diff.py over the wiring-graph trailers):"
echo " nodes/edges/topics added or removed, QoS and type"
echo " mismatches — topology differences, not XML noise."
echo ""
echo "Run a stack: airstack up --stack <name>[:<entry>]"
echo "Check a checkout: airstack doctor"
;;
doctor)
echo "Usage: airstack doctor [--live | --snapshot] [--stack NAME] [--strict]"
echo ""
echo "Observe-and-report health checks (RFC #379 §4). Doctor never edits"
echo "anything and exits non-zero in default mode only on the two enumerated"
echo "hard gates."
echo ""
echo "Default (compose-time) checks, in order:"
echo " 1. module manifests valid (tools/validate_module.py)"
echo " 2. overlay integrity (module_overlay.py --check)"
echo " 3. HARD GATE #1: module dep conflicts (compose_module_layers.py"
echo " --check-conflicts — a conflict would compose a broken image)"
echo " 4. stack folder anatomy (incl. split stack => bridge.yaml required)"
echo " 5. HARD GATE #2: control-setpoint / trajectory-group names in any"
echo " bridge.yaml (gen_dds_router.py --check — command authority stays"
echo " onboard, RFC #380 §2)"
echo ""
echo "Modes:"
echo " --live Capture the RUNNING graph (docker exec per robot) and"
echo " diff it against the stack's committed wiring.md; exit 1"
echo " on drift. Also scans for publishers of control-setpoint"
echo " / trajectory-group topics outside the blessed controller"
echo " chain (reported loudly; fatal only with --strict)."
echo " --snapshot Same capture, WRITTEN to stacks/<name>/wiring.md with a"
echo " provenance line ('observed on <host>, <date>, <sha> —"
echo " unverified-in-CI') — the hardware bring-up path."
echo " --stack NAME Stack to diff/snapshot (default: inferred from"
echo " AIRSTACK_STACK_DIR as exported by 'airstack up ...stack')."
echo " --strict Make --live safety-floor warnings fatal."
echo ""
echo "Module-scoped checks only: airstack module doctor [--drift]"
;;
*)
# For commands without specific help, just show the general help
echo "Usage: airstack $command [options]"
echo ""
echo "For more information, check the documentation or source code."
;;
esac
}
# Log messages with different severity levels
function log_info {
echo -e "${GREEN}[INFO]${NC} $1"
}
function log_warn {
echo -e "${YELLOW}[WARN]${NC} $1"
}
function log_error {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
# Get VERSION from .env file (parsing shared with cmd_version via _env_value)
function get_VERSION {
local version
version=$(_env_value VERSION "$PROJECT_ROOT/.env")
if [ -z "$version" ]; then
log_warn "VERSION not found in .env, using 'latest' tag"
echo "latest"
return
fi
echo "$version"
}
# Check if Docker is installed and running
function check_docker {
if ! command -v docker &> /dev/null; then
log_error "Docker is not installed. Run 'airstack install' first."
exit 1
fi
if ! docker info &> /dev/null; then
log_error "Docker daemon is not running."
exit 1
fi
}
# Wrapper function to run docker compose natively on the host.
# The base compose file ($PROJECT_ROOT/docker-compose.yaml) is folded in here —
# callers pass only ADDITIONAL -f overlay files (module/fleet overlays), never
# the base one. (The tests runner uses its own separate compose file and calls
# `docker compose` directly — see .airstack/modules/dev.sh.)
function run_docker_compose {
local env_args=()
local env_file="$PROJECT_ROOT/.env"
if [ -f "$env_file" ]; then
env_args+=("--env-file" "$env_file")
fi
docker compose "${env_args[@]}" -f "$PROJECT_ROOT/docker-compose.yaml" "$@"
}
# Find container by partial name using regex
function find_container {
local search_term="$1"
local containers
# Get list of running containers
containers=$(docker ps --format "{{.Names}}\t{{.Image}}\t{{.Status}}")
# Find matches using grep
matches=$(echo "$containers" | grep -i "$search_term" || true)
match_count=$(echo "$matches" | grep -v "^$" | wc -l)
if [ "$match_count" -eq 0 ]; then
# Try a more flexible search if exact match fails
log_warn "No exact matches for '$search_term', trying fuzzy search..." >&2
matches=$(echo "$containers" | grep -i ".*$search_term.*" || true)
match_count=$(echo "$matches" | grep -v "^$" | wc -l)
if [ "$match_count" -eq 0 ]; then
log_error "No running containers match '$search_term'"
# Show available containers as a suggestion
available=$(docker ps --format "{{.Names}}")
if [ -n "$available" ]; then
log_info "Available containers:" >&2
echo "$available" >&2
fi
return 1
fi
fi
if [ "$match_count" -eq 1 ]; then
# Extract just the container name (first column)
container_name=$(echo "$matches" | awk '{print $1}')
echo "$container_name"
return 0
else
log_warn "Multiple containers match '$search_term'. Please be more specific or select from the list below:" >&2
# Format the output as a table with numbers (redirect to stderr so it's not captured)
echo -e "${BLUE}NUM\tCONTAINER NAME\tIMAGE\tSTATUS${NC}" >&2
echo "$matches" | awk '{print NR "\t" $0}' >&2
echo "" >&2
echo "Options:" >&2
echo " 1. Enter a number to select a container" >&2
echo " 2. Type 'q' to quit" >&2
echo " 3. Press Ctrl+C to cancel and try again with a more specific name" >&2
echo "" >&2
read -p "Your selection: " selection <&2
if [ "$selection" = "q" ]; then
log_info "Operation canceled" >&2
return 1
elif [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -gt 0 ] && [ "$selection" -le "$match_count" ]; then
# Extract just the container name from the selected line
container_name=$(echo "$matches" | sed -n "${selection}p" | awk '{print $1}')
echo "$container_name"
# Provide a tip for future use
log_info "Tip: Next time, you can directly use 'airstack connect $container_name' for this container" >&2
return 0
else
log_error "Invalid selection. Please enter a number between 1 and $match_count, or 'q' to quit."
# Give the user another chance to select
echo "" >&2
read -p "Try again (or 'q' to quit): " selection <&2
if [ "$selection" = "q" ]; then
log_info "Operation canceled" >&2
return 1
elif [[ "$selection" =~ ^[0-9]+$ ]] && [ "$selection" -gt 0 ] && [ "$selection" -le "$match_count" ]; then
container_name=$(echo "$matches" | sed -n "${selection}p" | awk '{print $1}')
echo "$container_name"
return 0
else
log_error "Invalid selection again. Please try the command again with a more specific container name."
return 1
fi
fi
fi
}
# Command implementations
function cmd_install {
log_info "Installing dependencies..."
# Check for --force flag
local force=false
# Check for --no-docker flag
local install_docker=true
for arg in "$@"; do
if [ "$arg" == "--force" ]; then
force=true
elif [ "$arg" == "--no-docker" ]; then
install_docker=false
fi
done
# Install Docker if needed
if [ "$install_docker" = true ]; then
if command -v docker &> /dev/null && [ "$force" = false ]; then
log_info "Docker is already installed"
else
log_info "Installing Docker..."
# Detect OS
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
else
OS=$(uname -s)
fi
case "$OS" in
ubuntu|debian)
log_info "Detected Debian/Ubuntu system"
# Update package index
log_info "Updating package index..."
sudo apt-get update
# Install prerequisites
log_info "Installing prerequisites..."
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
# Add Docker's official GPG key
log_info "Adding Docker's GPG key..."
curl -fsSL https://download.docker.com/linux/$OS/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Set up the stable repository
log_info "Setting up Docker repository..."
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/$OS $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update package index again
sudo apt-get update
# Install Docker Engine
log_info "Installing Docker Engine..."
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
;;
fedora|centos|rhel)
log_info "Detected Fedora/CentOS/RHEL system"
# Install prerequisites
log_info "Installing prerequisites..."
sudo dnf -y install dnf-plugins-core
# Add Docker repository
log_info "Setting up Docker repository..."
sudo dnf config-manager --add-repo https://download.docker.com/linux/$OS/docker-ce.repo
# Install Docker Engine
log_info "Installing Docker Engine..."
sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
;;
darwin)
log_info "Detected macOS system"
log_info "Please install Docker Desktop for Mac from https://www.docker.com/products/docker-desktop"
log_info "After installation, run 'airstack setup' to complete the configuration"
;;
*)
log_error "Unsupported operating system: $OS"
log_info "Please install Docker manually from https://docs.docker.com/engine/install/"
;;
esac
# Start Docker service if not running
if systemctl status docker &>/dev/null; then
log_info "Starting Docker service..."
sudo systemctl enable --now docker
# Add current user to docker group
log_info "Adding user to docker group..."
sudo usermod -aG docker "$USER"
log_info "You may need to log out and back in for group changes to take effect"
fi
log_info "Docker installation complete"
fi
# Install NVIDIA Container Toolkit for GPU support
if [ "$OS" = "ubuntu" ] || [ "$OS" = "debian" ]; then
log_info "Installing NVIDIA Container Toolkit..."
# Install prerequisites
log_info "Installing prerequisites for NVIDIA Container Toolkit..."
sudo apt-get update && sudo apt-get install -y --no-install-recommends \
curl \
gnupg2
# Configure the production repository
log_info "Configuring NVIDIA Container Toolkit repository..."
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \
&& curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list > /dev/null
# Update the packages list from the repository
log_info "Updating package list..."
sudo apt-get update
# Install the NVIDIA Container Toolkit packages
log_info "Installing NVIDIA Container Toolkit packages..."
export NVIDIA_CONTAINER_TOOLKIT_VERSION=1.18.1-1
sudo apt-get install -y \
nvidia-container-toolkit=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
nvidia-container-toolkit-base=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
libnvidia-container-tools=${NVIDIA_CONTAINER_TOOLKIT_VERSION} \
libnvidia-container1=${NVIDIA_CONTAINER_TOOLKIT_VERSION}
# Configure Docker to use NVIDIA runtime
log_info "Configuring Docker to use NVIDIA runtime..."
sudo nvidia-ctk runtime configure --runtime=docker
# Restart Docker service to apply changes
if systemctl is-active --quiet docker; then
log_info "Restarting Docker service to apply NVIDIA runtime configuration..."
sudo systemctl restart docker
fi
log_info "NVIDIA Container Toolkit installation complete"
else
log_warn "NVIDIA Container Toolkit installation is only supported on Ubuntu/Debian systems"
log_info "For other systems, please install manually: https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html"
fi
# Check Docker Compose version
local compose_min_version="5.0.0"
local compose_targt_version="5.0.2"
log_info "Checking Docker Compose version..."
local compose_current
if compose_current=$(docker compose version --short 2>/dev/null); then
if ! printf '%s\n%s\n' "$compose_min_version" "$compose_current" | sort -V -C; then
log_warn "Docker Compose version $compose_current is older than the minimum required version $compose_min_version"
read -p "Would you like to upgrade Docker Compose to the latest version (v$compose_targt_version)? [y/N] " upgrade_choice
if [[ "$upgrade_choice" =~ ^[Yy]$ ]]; then
log_info "Upgrading Docker Compose..."
local _dc_config=${DOCKER_CONFIG:-$HOME/.docker}
local arch
arch=$(uname -m)
mkdir -p "$_dc_config/cli-plugins"
curl -SL "https://github.com/docker/compose/releases/download/v$compose_targt_version/docker-compose-linux-$arch" \
-o "$_dc_config/cli-plugins/docker-compose"
chmod +x "$_dc_config/cli-plugins/docker-compose"
log_info "Docker Compose upgraded successfully"
log_info "New version: $(docker compose version --short)"
else
log_warn "Skipping Docker Compose upgrade. Some features may not work correctly."
fi
else
log_info "Docker Compose version $compose_current meets the minimum requirement ($compose_min_version)"
fi
else
log_warn "Could not determine Docker Compose version. Please ensure Docker Compose v$compose_min_version or newer is installed."
fi
fi
log_info "Installation complete!"
}
function cmd_setup {
log_info "Setting up AirStack environment..."
# Check for --no-shell flag
local modify_shell=true
local skip_config=false
for arg in "$@"; do
if [ "$arg" == "--no-shell" ]; then
modify_shell=false
elif [ "$arg" == "--no-config" ]; then
skip_config=true
fi
done
# Add to shell profile if requested
if [ "$modify_shell" = true ]; then
local shell_profile=""
if [ -f "$HOME/.zshrc" ]; then
shell_profile="$HOME/.zshrc"
elif [ -f "$HOME/.bashrc" ]; then
shell_profile="$HOME/.bashrc"
else
log_warn "Could not determine shell profile. Please add the airstack function to your shell profile manually."
echo "You can find the function definition in the setup section of $PROJECT_ROOT/airstack.sh"
return
fi
if grep -q "# AirStack function" "$shell_profile"; then
log_info "'airstack' function already registered"
else
log_info "Adding 'airstack' function in $shell_profile"
echo "" >> "$shell_profile"
echo "# AirStack function" >> "$shell_profile"
echo 'function airstack() {' >> "$shell_profile"
echo ' # Start from the current directory and look for airstack.sh' >> "$shell_profile"
echo ' local current_dir="$(pwd)"' >> "$shell_profile"
echo ' local found_scripts=()' >> "$shell_profile"
echo ' local script_path=""' >> "$shell_profile"
echo '' >> "$shell_profile"
echo ' # First check if there is an airstack.sh in the current directory or any parent directory' >> "$shell_profile"
echo ' while [[ "$current_dir" != "" ]]; do' >> "$shell_profile"
echo ' if [[ -f "$current_dir/airstack.sh" ]]; then' >> "$shell_profile"
echo ' found_scripts+=("$current_dir/airstack.sh")' >> "$shell_profile"
echo ' # We found one, but keep looking to check for ambiguities' >> "$shell_profile"
echo ' fi' >> "$shell_profile"
echo ' # Stop if we reach the root directory' >> "$shell_profile"
echo ' if [[ "$current_dir" == "/" ]]; then' >> "$shell_profile"
echo ' break' >> "$shell_profile"
echo ' fi' >> "$shell_profile"
echo ' # Move up one directory' >> "$shell_profile"
echo ' current_dir="$(dirname "$current_dir")"' >> "$shell_profile"
echo ' done' >> "$shell_profile"
echo '' >> "$shell_profile"
echo ' # Check how many scripts we found' >> "$shell_profile"
echo ' if [[ ${#found_scripts[@]} -eq 0 ]]; then' >> "$shell_profile"
echo ' echo -e "\033[0;31m[ERROR]\033[0m No airstack.sh script found in the current directory or any parent directory."' >> "$shell_profile"
echo ' return 1' >> "$shell_profile"
echo ' elif [[ ${#found_scripts[@]} -gt 1 ]]; then' >> "$shell_profile"
echo ' echo -e "\033[0;31m[ERROR]\033[0m Multiple airstack.sh scripts found in the directory hierarchy:"' >> "$shell_profile"
echo ' for script in "${found_scripts[@]}"; do' >> "$shell_profile"
echo ' echo " - $script"' >> "$shell_profile"
echo ' done' >> "$shell_profile"
echo ' echo "Please cd to the specific AirStack repository you want to use."' >> "$shell_profile"
echo ' return 1' >> "$shell_profile"
echo ' else' >> "$shell_profile"
echo ' # We found exactly one script, use it' >> "$shell_profile"
echo ' script_path="${found_scripts[@]:0:1}"' >> "$shell_profile"
echo ' "$script_path" "$@"' >> "$shell_profile"
echo ' fi' >> "$shell_profile"
echo '}' >> "$shell_profile"
echo "Added to $shell_profile. Please restart your shell or run 'source $shell_profile'. Then you'll be able to use the 'airstack' command from any sub-directory."
fi
fi
# Run configuration tasks if not skipped
if [ "$skip_config" = false ]; then
# Check if the config module is available
if declare -f "cmd_config_all" > /dev/null; then
log_info "Running configuration tasks..."
cmd_config_all
else
log_warn "Configuration module not loaded. Skipping configuration tasks."
fi
fi
log_info "Making sure git submodules are initialized and updated..."
git submodule update --init --recursive || log_warn "Failed to update git submodules. Some packages may not launch, please check your git credentials."
# Sync modules (RFC #379): module hooks (hooks.host_setup) cover host-side
# setup steps like proprietary SDK downloads, so setup just re-runs sync.
if [ -f "$PROJECT_ROOT/modules.repos" ]; then
if declare -f "cmd_module_dispatch" > /dev/null; then
log_info "Syncing modules from modules.repos..."
cmd_module_dispatch sync || log_warn "Module sync failed — run 'airstack module sync' manually."
else
log_warn "Module command module not loaded — skipping module sync. Run 'airstack module sync' manually."
fi
fi
log_info "Setup complete!"
}
# Classify arguments for a docker compose invocation.
# Global docker compose flags (must appear before the subcommand) are separated
# from subcommand-specific arguments.
#
# Usage: classify_compose_args <global_array_name> <subcmd_array_name> "$@"
#
# Example:
# local global_args=() subcmd_args=()
# classify_compose_args global_args subcmd_args "$@"
function classify_compose_args {
local -n _global=$1
local -n _subcmd=$2
shift 2
# Global flags that consume the next argument as their value
local -A _takes_value=(
[--ansi]=1 [--env-file]=1 [-f]=1 [--file]=1
[--parallel]=1 [--profile]=1 [--progress]=1
[--project-directory]=1 [--workdir]=1
[-p]=1 [--project-name]=1 [-H]=1 [--host]=1
)
# Global flags that are boolean (standalone, no value)
local -A _is_bool=(
[--compatibility]=1 [--dry-run]=1 [--verbose]=1 [--version]=1
)
local args=("$@")
local i=0
while [ $i -lt ${#args[@]} ]; do
local arg="${args[$i]}"
if [[ -n "${_takes_value[$arg]+x}" ]]; then
# Flag + value pair -> global
_global+=("$arg")
i=$((i+1))
if [ $i -lt ${#args[@]} ]; then
_global+=("${args[$i]}")
else
log_error "Missing value for compose global flag: $arg"
return 1
fi