From 053391b01035ac0d4a62deea9a86a63865ebd739 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Sun, 22 Sep 2024 15:29:28 -0700 Subject: [PATCH] add script for checking copyright headers --- scripts/check-copyright.sh | 74 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 scripts/check-copyright.sh diff --git a/scripts/check-copyright.sh b/scripts/check-copyright.sh new file mode 100755 index 0000000..8104f9c --- /dev/null +++ b/scripts/check-copyright.sh @@ -0,0 +1,74 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-3.0-or-later +# See Notices.txt for copyright information +set -e + +function fail() +{ + local error="$1" + echo "error: $error" >&2 + exit 1 +} + +function fail_file() +{ + local file="$1" line="$2" error="$3" + fail "$file:$((line + 1)): $error" +} + +function check_file() +{ + local file="$1" regexes=("${@:2}") + local lines + mapfile -t lines < "$file" + local line + for line in "${!regexes[@]}"; do + eval '[[ "${lines[i]}" =~ '"${regexes[i]}"' ]]' || + fail_file "$file" "$line" "doesn't match regex: ${regexes[i]}" + done +} + +POUND_HEADER=('^"# SPDX-License-Identifier: LGPL-3.0-or-later"$' '^"# See Notices.txt for copyright information"$') +SLASH_HEADER=('^"// SPDX-License-Identifier: LGPL-3.0-or-later"$' '^"// See Notices.txt for copyright information"$') +MD_HEADER=('^"