Skip to content

Commit 9c19b5d

Browse files
authored
Merge pull request #2245 from lorenzozanee/fix/termux-portable-guard
fix(install): reject unsupported Android portable installs
2 parents afe5736 + 7a7ecb7 commit 9c19b5d

3 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎install.sh‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,19 @@ detect_arch() {
148148
esac
149149
}
150150

151+
is_android() {
152+
[ "$(uname -o 2>/dev/null || true)" = "Android" ] \
153+
|| [ -n "${TERMUX_VERSION:-}" ] \
154+
|| [[ "${PREFIX:-}" == /data/data/com.termux/* ]]
155+
}
156+
151157
OS=$(detect_os)
152158
ARCH=$(detect_arch)
159+
if [ "$OS" = "linux" ] && is_android; then
160+
echo 'error: Android/Termux cannot run the Linux portable binary (static glibc; Android kills it with "Bad system call").' >&2
161+
echo "Building from source in Termux may work but is not a supported platform yet - see issue #1202." >&2
162+
exit 1
163+
fi
153164

154165
echo "codebase-memory-mcp installer"
155166
echo " os: $OS"

‎scripts/test.sh‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ bash "$ROOT/tests/test_language_count_contract.sh"
364364
echo "=== Step 0x: packaging version-metadata contract ==="
365365
bash "$ROOT/tests/test_version_metadata_contract.sh"
366366

367+
echo "=== Step 0x2: installer Android/Termux guard contract (#1202) ==="
368+
bash "$ROOT/tests/test_install_android_guard.sh"
369+
367370
# Step 0y: the Windows leg must not decide its verdict from an exit status that
368371
# the ssh/msys2_shell chain can mangle — a channel that turns 0 into 1 can turn
369372
# 1 into 0, and that direction reports a RED Windows leg as green. Runs
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
5+
WORK=$(mktemp -d)
6+
trap 'rm -rf "$WORK"' EXIT
7+
8+
mkdir -p "$WORK/bin" "$WORK/home"
9+
cat >"$WORK/bin/uname" <<'EOF'
10+
#!/usr/bin/env bash
11+
case "$1" in
12+
-s) printf '%s\n' Linux ;;
13+
-m) printf '%s\n' aarch64 ;;
14+
-o) printf '%s\n' Android ;;
15+
*) exit 1 ;;
16+
esac
17+
EOF
18+
cat >"$WORK/bin/curl" <<'EOF'
19+
#!/usr/bin/env bash
20+
printf 'curl must not run for Android/Termux\n' >&2
21+
exit 99
22+
EOF
23+
chmod +x "$WORK/bin/uname" "$WORK/bin/curl"
24+
25+
# The stubs must be what install.sh sees, or this test proves nothing.
26+
if [ "$(PATH="$WORK/bin:$PATH" uname -o)" != "Android" ]; then
27+
printf 'FAIL: the uname stub is not picked up from PATH\n' >&2
28+
exit 1
29+
fi
30+
31+
set +e
32+
output=$(PATH="$WORK/bin:$PATH" HOME="$WORK/home" \
33+
CBM_DOWNLOAD_URL="http://127.0.0.1:9/cbm-android-guard-test" \
34+
bash "$ROOT/install.sh" --skip-config 2>&1)
35+
rc=$?
36+
set -e
37+
38+
if [ "$rc" -eq 0 ]; then
39+
printf 'FAIL: installer accepted Android/Termux\n' >&2
40+
exit 1
41+
fi
42+
if ! grep -Fq 'Android/Termux' <<<"$output"; then
43+
printf 'FAIL: missing Android/Termux guidance\n%s\n' "$output" >&2
44+
exit 1
45+
fi
46+
if grep -Fq 'curl must not run' <<<"$output"; then
47+
printf 'FAIL: installer downloaded before rejecting Android/Termux\n' >&2
48+
exit 1
49+
fi
50+
51+
printf 'PASS: Android/Termux is rejected before download\n'

0 commit comments

Comments
 (0)