|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Behavioral test for the apl-feed import wiring inside airplanes-first-run. |
| 3 | +# Static grep in update-airplanes-rootfs-smoke.sh covers "the line is in the |
| 4 | +# installed file"; this test covers "the script actually calls apl-feed |
| 5 | +# import legacy-config --no-restart with the right path when it runs". |
| 6 | +# |
| 7 | +# The first-run script hardcodes absolute paths (/boot, /usr/local/bin), |
| 8 | +# so we sed-rewrite a copy that uses a temporary fake root and stub every |
| 9 | +# binary the script touches through PATH. apl-feed is the assertion |
| 10 | +# target; systemctl / create-uuid.sh / fix-config.sh are silenced so the |
| 11 | +# rest of the script runs to completion without side effects. |
| 12 | + |
| 13 | +set -euo pipefail |
| 14 | + |
| 15 | +UPDATE_DIR="${AIRPLANES_UPDATE_DIR:-$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)}" |
| 16 | +SCRIPT_SRC="$UPDATE_DIR/skeleton/usr/bin/airplanes-first-run" |
| 17 | + |
| 18 | +WORK="$(mktemp -d)" |
| 19 | +trap 'rm -rf "$WORK"' EXIT |
| 20 | + |
| 21 | +ROOT="$WORK/root" |
| 22 | +STUB="$WORK/bin" |
| 23 | +APL_FEED_LOG="$WORK/apl-feed.argv" |
| 24 | +mkdir -p "$ROOT/boot" "$ROOT/usr/local/bin" "$STUB" |
| 25 | + |
| 26 | +# Stub apl-feed: log one invocation per line as tab-joined argv tokens. |
| 27 | +# Tab is safe — none of the script's call sites pass an argv token that |
| 28 | +# contains a literal tab. The script's bash `if ! …; then warn` gate is |
| 29 | +# exercised on the success path here; the failure-warning path is |
| 30 | +# covered by the static smoke assertion in update-airplanes-rootfs- |
| 31 | +# smoke.sh. |
| 32 | +cat > "$STUB/apl-feed" <<APL_FEED |
| 33 | +#!/usr/bin/env bash |
| 34 | +printf '%s' "\$1" >> "$APL_FEED_LOG" |
| 35 | +shift |
| 36 | +for arg in "\$@"; do |
| 37 | + printf '\t%s' "\$arg" >> "$APL_FEED_LOG" |
| 38 | +done |
| 39 | +printf '\n' >> "$APL_FEED_LOG" |
| 40 | +exit 0 |
| 41 | +APL_FEED |
| 42 | +chmod +x "$STUB/apl-feed" |
| 43 | + |
| 44 | +# Silence everything else. systemctl gets called with is-enabled / is-active |
| 45 | +# / enable / disable / stop / start — all return success in this test. |
| 46 | +cat > "$STUB/systemctl" <<'SYSTEMCTL' |
| 47 | +#!/usr/bin/env bash |
| 48 | +exit 0 |
| 49 | +SYSTEMCTL |
| 50 | +chmod +x "$STUB/systemctl" |
| 51 | + |
| 52 | +cat > "$ROOT/usr/local/bin/create-uuid.sh" <<'CREATE_UUID' |
| 53 | +#!/usr/bin/env bash |
| 54 | +exit 0 |
| 55 | +CREATE_UUID |
| 56 | +chmod +x "$ROOT/usr/local/bin/create-uuid.sh" |
| 57 | +cp "$ROOT/usr/local/bin/create-uuid.sh" "$ROOT/usr/local/bin/fix-config.sh" |
| 58 | + |
| 59 | +# Seed a legacy-shaped boot config — the post-bridge migrate-config.sh form. |
| 60 | +cat > "$ROOT/boot/airplanes-config.txt" <<'BOOT_CONFIG' |
| 61 | +LATITUDE=52.5 |
| 62 | +LONGITUDE=13.4 |
| 63 | +ALTITUDE=120m |
| 64 | +USER=alice |
| 65 | +MLAT_USER="alice" |
| 66 | +MLAT_ENABLED=true |
| 67 | +MLAT_MARKER=yes |
| 68 | +MLAT_PRIVATE=false |
| 69 | +DUMP978=no |
| 70 | +DUMP1090=yes |
| 71 | +GRAPHS1090=yes |
| 72 | +BOOT_CONFIG |
| 73 | + |
| 74 | +# Sed-rewrite absolute paths in a copy of the script. The substitutions |
| 75 | +# are narrow — only the paths this test cares about — so a future |
| 76 | +# unrelated absolute path in the script won't be silently rerouted. |
| 77 | +SCRIPT_COPY="$WORK/airplanes-first-run" |
| 78 | +sed \ |
| 79 | + -e "s|/boot/airplanes-config\.txt|$ROOT/boot/airplanes-config.txt|g" \ |
| 80 | + -e "s|/run/airplanes-config\.txt|$ROOT/run-airplanes-config.txt|g" \ |
| 81 | + -e "s|/usr/local/bin/create-uuid\.sh|$ROOT/usr/local/bin/create-uuid.sh|g" \ |
| 82 | + -e "s|/usr/local/bin/fix-config\.sh|$ROOT/usr/local/bin/fix-config.sh|g" \ |
| 83 | + -e "s|/boot/firstboot\.sh|$ROOT/boot/firstboot.sh|g" \ |
| 84 | + "$SCRIPT_SRC" > "$SCRIPT_COPY" |
| 85 | +chmod +x "$SCRIPT_COPY" |
| 86 | + |
| 87 | +PATH="$STUB:$PATH" bash "$SCRIPT_COPY" |
| 88 | + |
| 89 | +if [[ ! -s "$APL_FEED_LOG" ]]; then |
| 90 | + echo "FAIL: apl-feed was not invoked" >&2 |
| 91 | + exit 1 |
| 92 | +fi |
| 93 | + |
| 94 | +expected_line=$'import\tlegacy-config\t--no-restart\t'"$ROOT/boot/airplanes-config.txt" |
| 95 | +if ! grep -Fxq -- "$expected_line" "$APL_FEED_LOG"; then |
| 96 | + echo "FAIL: apl-feed argv not as expected." >&2 |
| 97 | + echo " expected: $expected_line" >&2 |
| 98 | + echo " actual log:" >&2 |
| 99 | + cat "$APL_FEED_LOG" >&2 |
| 100 | + exit 1 |
| 101 | +fi |
| 102 | + |
| 103 | +echo "first-run import call test passed" |
0 commit comments