1
+ #! /bin/bash
2
+ # #===----------------------------------------------------------------------===##
3
+ # #
4
+ # # This source file is part of the WebAuthn Swift open source project
5
+ # #
6
+ # # Copyright (c) 2022 the WebAuthn Swift project authors
7
+ # # Licensed under Apache License v2.0
8
+ # #
9
+ # # See LICENSE.txt for license information
10
+ # # See CONTRIBUTORS.txt for the list of WebAuthn Swift project authors
11
+ # #
12
+ # # SPDX-License-Identifier: Apache-2.0
13
+ # #
14
+ # #===----------------------------------------------------------------------===##
15
+
16
+ set -eu
17
+ here=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd ) "
18
+
19
+ function replace_acceptable_years() {
20
+ # this needs to replace all acceptable forms with 'YEARS'
21
+ sed -e ' s/20[12][78901]-20[12][89012]/YEARS/' -e ' s/20[12][89012]/YEARS/'
22
+ }
23
+
24
+ printf " => Checking for unacceptable language... "
25
+ # This greps for unacceptable terminology. The square bracket[s] are so that
26
+ # "git grep" doesn't find the lines that greps :).
27
+ unacceptable_terms=(
28
+ -e blacklis[t]
29
+ -e whitelis[t]
30
+ -e slav[e]
31
+ -e sanit[y]
32
+ )
33
+
34
+ # We have to exclude the code of conduct as it gives examples of unacceptable
35
+ # language.
36
+ if git grep --color=never -i " ${unacceptable_terms[@]} " -- . " :(exclude)CODE_OF_CONDUCT.md" > /dev/null; then
37
+ printf " \033[0;31mUnacceptable language found.\033[0m\n"
38
+ git grep -i " ${unacceptable_terms[@]} " -- . " :(exclude)CODE_OF_CONDUCT.md"
39
+ exit 1
40
+ fi
41
+ printf " \033[0;32mokay.\033[0m\n"
42
+
43
+ printf " => Checking license headers... "
44
+ tmp=$( mktemp /tmp/.webauthn-swift-soundness_XXXXXX)
45
+
46
+ for language in swift bash; do
47
+ declare -a matching_files
48
+ declare -a exceptions
49
+ expections=( )
50
+ matching_files=( -name ' *' )
51
+ case " $language " in
52
+ swift)
53
+ exceptions=( -name Package.swift )
54
+ matching_files=( -name ' *.swift' )
55
+ cat > " $tmp " << "EOF "
56
+ //===----------------------------------------------------------------------===//
57
+ //
58
+ // This source file is part of the WebAuthn Swift open source project
59
+ //
60
+ // Copyright (c) YEARS the WebAuthn Swift project authors
61
+ // Licensed under Apache License v2.0
62
+ //
63
+ // See LICENSE.txt for license information
64
+ // See CONTRIBUTORS.txt for the list of WebAuthn Swift project authors
65
+ //
66
+ // SPDX-License-Identifier: Apache-2.0
67
+ //
68
+ //===----------------------------------------------------------------------===//
69
+ EOF
70
+ ;;
71
+ bash)
72
+ matching_files=( -name ' *.sh' )
73
+ cat > " $tmp " << "EOF "
74
+ #!/bin/bash
75
+ ##===----------------------------------------------------------------------===##
76
+ ##
77
+ ## This source file is part of the WebAuthn Swift open source project
78
+ ##
79
+ ## Copyright (c) 2022 the WebAuthn Swift project authors
80
+ ## Licensed under Apache License v2.0
81
+ ##
82
+ ## See LICENSE.txt for license information
83
+ ## See CONTRIBUTORS.txt for the list of WebAuthn Swift project authors
84
+ ##
85
+ ## SPDX-License-Identifier: Apache-2.0
86
+ ##
87
+ ##===----------------------------------------------------------------------===##
88
+ EOF
89
+ ;;
90
+ * )
91
+ echo >&2 " ERROR: unknown language '$language '"
92
+ ;;
93
+ esac
94
+
95
+ expected_lines=$( cat " $tmp " | wc -l)
96
+ expected_sha=$( cat " $tmp " | shasum)
97
+
98
+ (
99
+ cd " $here /.."
100
+ {
101
+ find . \
102
+ \( \! -path ' ./.build/*' -a \
103
+ \( " ${matching_files[@]} " \) -a \
104
+ \( \! \( " ${exceptions[@]} " \) \) \)
105
+
106
+ if [[ " $language " = bash ]]; then
107
+ # add everything with a shell shebang too
108
+ git grep --full-name -l ' #!/bin/bash'
109
+ git grep --full-name -l ' #!/bin/sh'
110
+ fi
111
+ } | while read line; do
112
+ if [[ " $( cat " $line " | replace_acceptable_years | head -n $expected_lines | shasum) " != " $expected_sha " ]]; then
113
+ printf " \033[0;31mmissing headers in file '$line '!\033[0m\n"
114
+ diff -u <( cat " $line " | replace_acceptable_years | head -n $expected_lines ) " $tmp "
115
+ exit 1
116
+ fi
117
+ done
118
+ printf " \033[0;32mokay.\033[0m\n"
119
+ )
120
+ done
121
+
122
+ rm " $tmp "
0 commit comments