|
| 1 | +#!/bin/bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 5 | +REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" |
| 6 | +APK_DIR="${APK_DIR:-$REPO_ROOT/build/app/outputs/flutter-apk}" |
| 7 | +APP_NAME="${APP_NAME:-ServerBox}" |
| 8 | + |
| 9 | +require_cmd() { |
| 10 | + local name="$1" |
| 11 | + if ! command -v "$name" >/dev/null 2>&1; then |
| 12 | + echo "command not found: $name" >&2 |
| 13 | + exit 1 |
| 14 | + fi |
| 15 | +} |
| 16 | + |
| 17 | +require_cmd find |
| 18 | +require_cmd readelf |
| 19 | +require_cmd unzip |
| 20 | + |
| 21 | +shopt -s nullglob |
| 22 | + |
| 23 | +tmp_dir="$(mktemp -d)" |
| 24 | +trap 'rm -rf "$tmp_dir"' EXIT |
| 25 | + |
| 26 | +failures=() |
| 27 | +apks=() |
| 28 | +patterns=( |
| 29 | + "${APP_NAME}_*_arm64.apk" |
| 30 | + "${APP_NAME}_*_arm.apk" |
| 31 | + "${APP_NAME}_*_amd64.apk" |
| 32 | +) |
| 33 | + |
| 34 | +for pattern in "${patterns[@]}"; do |
| 35 | + matches=("$APK_DIR"/$pattern) |
| 36 | + if [[ ${#matches[@]} -ne 1 ]]; then |
| 37 | + echo "expected exactly 1 APK for pattern: $pattern" >&2 |
| 38 | + echo "found ${#matches[@]} matches" >&2 |
| 39 | + echo "APK_DIR: $APK_DIR" >&2 |
| 40 | + if [[ ${#matches[@]} -gt 0 ]]; then |
| 41 | + printf ' %s\n' "${matches[@]}" >&2 |
| 42 | + else |
| 43 | + ls -la "$APK_DIR" || true |
| 44 | + fi |
| 45 | + exit 1 |
| 46 | + fi |
| 47 | + apks+=("${matches[0]}") |
| 48 | +done |
| 49 | + |
| 50 | +for apk in "${apks[@]}"; do |
| 51 | + apk_name="$(basename "$apk")" |
| 52 | + extract_dir="$tmp_dir/$apk_name" |
| 53 | + mkdir -p "$extract_dir" |
| 54 | + unzip -qq "$apk" "lib/*/*.so" -d "$extract_dir" |
| 55 | + |
| 56 | + while IFS= read -r so_file; do |
| 57 | + if readelf -n "$so_file" | grep -q 'Build ID'; then |
| 58 | + failures+=("$apk_name:${so_file#$extract_dir/}") |
| 59 | + fi |
| 60 | + done < <(find "$extract_dir" -type f -name '*.so' | sort) |
| 61 | +done |
| 62 | + |
| 63 | +if [[ ${#failures[@]} -ne 0 ]]; then |
| 64 | + echo 'native libraries still contain ELF build-id notes:' >&2 |
| 65 | + printf ' %s\n' "${failures[@]}" >&2 |
| 66 | + exit 1 |
| 67 | +fi |
| 68 | + |
| 69 | +echo 'F-Droid native library verification passed.' |
0 commit comments