forked from vmware-tanzu/tanzu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-license.sh
executable file
·45 lines (38 loc) · 1.32 KB
/
check-license.sh
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
#!/bin/bash
# Copyright 2021 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
set -o errexit
set -o nounset
set -o pipefail
# TODO(navidshaikh): Add shellcheck and merge
verify_license() {
printf "Checking License in shell scripts and Makefiles ...\n"
local required_keywords=("VMware, Inc." "SPDX-License-Identifier: Apache-2.0")
local file_patterns_to_check=("*.sh" "Makefile")
local result
result=$(mktemp /tmp/tf-licence-check.XXXXXX)
for ext in "${file_patterns_to_check[@]}"; do
# ignore ./vendor dir, ./pinniped dir ( the dir is cloned while building CLI) and node_modules dir
find . -type d \( -path ./vendor -o -path ./pinniped -o -name node_modules \) -prune -o -name "$ext" -type f -print0 |
while IFS= read -r -d '' path; do
for rword in "${required_keywords[@]}"; do
if ! grep -q "$rword" "$path"; then
echo " $path" >> "$result"
fi
done
done
done
if [ -s "$result" ]; then
echo "No required license header found in:"
sort < "$result" | uniq
echo "License check failed!"
echo "Please add the license in each listed file and verify using './hack/check-license.sh'"
rm "$result"
return 1
else
echo "License check passed!"
rm "$result"
return 0
fi
}
verify_license || exit 1; exit 0