diff --git a/scripts/customize-wireless-regdb.py b/scripts/customize-wireless-regdb.py index 01e11b6..71a2229 100644 --- a/scripts/customize-wireless-regdb.py +++ b/scripts/customize-wireless-regdb.py @@ -40,8 +40,6 @@ def transform(lines: list[str]) -> tuple[list[str], bool]: out = list(lines) if out and not out[-1].endswith("\n"): out[-1] = f"{out[-1]}\n" - if out and out[-1].strip(): - out.append("\n") out.append("country BJ:\n") out.extend(f"{rule}\n" for rule in TEMPLATE_LINES) return out, True @@ -58,7 +56,9 @@ def main() -> int: transformed, added = transform(original) rendered = "".join(transformed) - if "country BJ:\n" not in rendered or " (5150 - 5350 @ 160), (36)\n" not in rendered or " (5925 - 7125 @ 320), (36)\n" not in rendered: + if "country BJ:\n" not in rendered or ( + added and any(f"{rule}\n" not in rendered for rule in TEMPLATE_LINES) + ): print("wireless-regdb customization failed: BJ template validation failed", file=sys.stderr) return 1 diff --git a/scripts/verify-custom-regdb.sh b/scripts/verify-custom-regdb.sh index 71601fa..9b737fb 100644 --- a/scripts/verify-custom-regdb.sh +++ b/scripts/verify-custom-regdb.sh @@ -19,9 +19,33 @@ test -s "$REGDB" || fail "regulatory.db is absent from the root filesystem" test -n "$MANIFEST" || fail "firmware manifest was not found" extract_country() { - awk -v header="country $1:" '$0 == header { inside = 1 } inside { if ($0 ~ /^country [A-Z0-9][A-Z0-9]:/ && $0 != header) exit; print }' "$2" + awk -v country="$1" ' + $0 ~ ("^country " country ":") { inside = 1 } + inside { + if ($0 ~ /^country [A-Z0-9][A-Z0-9]:/ && $0 !~ ("^country " country ":")) exit + print + } + ' "$2" } +country_codes() { + awk '/^country [A-Z0-9][A-Z0-9]:/ { print substr($2, 1, 2) }' "$1" +} + +stock_countries="$(country_codes "$STOCK_DB_TXT")" +if grep -Fxq 'BJ' <<< "$stock_countries"; then + expected_countries="$stock_countries" +else + expected_countries="${stock_countries}"$'\nBJ' +fi +custom_countries="$(country_codes "$DB_TXT")" +diff -u <(printf '%s\n' "$expected_countries") <(printf '%s\n' "$custom_countries") >/dev/null || fail "country list was modified unexpectedly" + +while IFS= read -r country; do + test -n "$country" || continue + diff -u <(extract_country "$country" "$STOCK_DB_TXT") <(extract_country "$country" "$DB_TXT") >/dev/null || fail "country $country was modified" +done <<< "$stock_countries" + grep -qx 'country BJ:' "$DB_TXT" || fail "country BJ is absent" stock_world="$(extract_country 00 "$STOCK_DB_TXT")" custom_world="$(extract_country 00 "$DB_TXT")"