-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathcheck_spdx_licenses.sh
More file actions
executable file
·58 lines (50 loc) · 1.42 KB
/
check_spdx_licenses.sh
File metadata and controls
executable file
·58 lines (50 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env bash
# Check that all Solidity contracts use the expected SPDX license identifier.
set -euo pipefail
EXPECTED_LICENSE="BSD-3-Clause-Clear"
EXIT_CODE=0
DIRS=()
EXCLUDES=()
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
--exclude)
EXCLUDES+=("$2")
shift 2
;;
*)
DIRS+=("$1")
shift
;;
esac
done
# Default to contracts/ if no directories specified
if [[ ${#DIRS[@]} -eq 0 ]]; then
DIRS=("contracts")
fi
for dir in "${DIRS[@]}"; do
while IFS= read -r -d '' file; do
# Check if file matches any exclude pattern
skip=false
for exclude in ${EXCLUDES[@]+"${EXCLUDES[@]}"}; do
if [[ "$file" == *"$exclude"* ]]; then
skip=true
break
fi
done
if "$skip"; then
continue
fi
first_line=$(head -n 1 "$file")
if [[ "$first_line" != "// SPDX-License-Identifier: ${EXPECTED_LICENSE}" ]]; then
echo "ERROR: Wrong or missing license in $file"
echo " Found: $first_line"
echo " Expected: // SPDX-License-Identifier: ${EXPECTED_LICENSE}"
EXIT_CODE=1
fi
done < <(find "$dir" -name '*.sol' -print0 | sort -z)
done
if [ "$EXIT_CODE" -eq 0 ]; then
echo "All Solidity files use SPDX-License-Identifier: ${EXPECTED_LICENSE}"
fi
exit "$EXIT_CODE"