blob: 7a9deb99bd861e1d98757919cf7f15ce06723b70 [file] [log] [blame]
Joey Armstrong04cdd9f2023-06-09 15:18:23 -04001#!/usr/bin/env bash
2
3# -----------------------------------------------------------------------
Joey Armstrong9fadcbe2024-01-17 19:00:37 -05004# Copyright 2022-2024 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong04cdd9f2023-06-09 15:18:23 -04005#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# -----------------------------------------------------------------------
18
19# licensecheck.sh
20# checks for copyright/license headers on files
21# excludes filename extensions where this check isn't pertinent
22
23# --strict
24# --strict-dates
25# see https://github...
26
27## ---------------------------------------------------------------------------
28## find: warning: ‘-name’ matches against basenames only, but the given pattern
29## contains a directory separator (‘/’), thus the expression will evaluate to
30## false all the time. Did you mean ‘-wholename’?
31##
32## [TODO] find and fix plugin script, change --name to --path:
33## find ! -name "*/docs/*"
34## ---------------------------------------------------------------------------
35## [TODO] see license/include.mk, grep -L will ignore binaries so no need to
36## explicitly filter images, spreadsheets, etc. Files containing utf-8 are
37## the only question mark.
38## ---------------------------------------------------------------------------
39
40echo "BLAH"
41exit 1
42
43set +e -u -o pipefail
44fail_licensecheck=0
45
46declare -a gargs=()
47gargs+=('--extended-regexp')
48
49# Evil regex -- scripts detecting pattern are excluded from checking.
50gargs+=('-e' 'Apache License')
51
52# Good regex -- no false positives.
53gargs+=('-e' 'Copyright[[:space:]]+[[:digit:]]{4}')
54
55while IFS= read -r -d '' path
56do
57 case "$path" in
58 *venv*) echo "GERR: $path"
59 exit 1
60 ;;
61 esac
62 if ! grep -q "${gargs[@]}" "${path}";
63 then
64 echo "ERROR: $path does not contain License Header"
65 fail_licensecheck=1
66 fi
67done < <(find . \( -name ".git" -o -name '.venv' -o 'vst_venv' \) -prune -o -type f \
68 ! -iname "*.png" \
69 ! -name "*.asc" \
70 ! -name "*.bat" \
71 ! -name "*.bin" \
72 ! -name "*.cert" \
73 ! -name "*.cfg" \
74 ! -name "*.cnf" \
75 ! -name "*.conf" \
76 ! -name "*.cql" \
77 ! -name "*.crt" \
78 ! -name "*.csar" \
79 ! -name "*.csr" \
80 ! -name "*.csv" \
81 ! -name "*.ctmpl" \
82 ! -name "*.curl" \
83 ! -name "*.db" \
84 ! -name "*.der" \
85 ! -name "*.desc" \
86 ! -name "*.diff" \
87 ! -name "*.dnsmasq" \
88 ! -name "*.do" \
89 ! -name "*.docx" \
90 ! -name "*.eot" \
91 ! -name "*.gif" \
92 ! -name "*.gpg" \
93 ! -name "*.graffle" \
94 ! -name "*.ico" \
95 ! -name "*.iml" \
96 ! -name "*.in" \
97 ! -name "*.inc" \
98 ! -name "*.install" \
99 ! -name "*.j2" \
100 ! -name "*.jar" \
101 ! -name "*.jks" \
102 ! -name "*.jpg" \
103 ! -name "*.json" \
104 ! -name "*.jsonld" \
105 ! -name "*.JSON" \
106 ! -name "*.key" \
107 ! -name "*.list" \
108 ! -name "*.local" \
109 ! -path "*.lock" \
110 ! -name "*.log" \
111 ! -name "*.mak" \
112 ! -name "*.md" \
113 ! -name "*.MF" \
114 ! -name "*.oar" \
115 ! -name "*.p12" \
116 ! -name "*.patch" \
117 ! -name "*.pb.go" \
118 ! -name "*.pb.gw.go" \
119 ! -name "*.pdf" \
120 ! -name "*.pcap" \
121 ! -name "*.pem" \
122 ! -name "*.properties" \
123 ! -name "*.proto" \
124 ! -name "*.protoset" \
125 ! -name "*.pyc" \
126 ! -name "*.repo" \
127 ! -name "*.robot" \
128 ! -name "*.rst" \
129 ! -name "*.rules" \
130 ! -name "*.service" \
131 ! -name "*.svg" \
132 ! -name "*.swp" \
133 ! -name "*.tar" \
134 ! -name "*.tar.gz" \
135 ! -name "*.toml" \
136 ! -name "*.ttf" \
137 ! -name "*.txt" \
138 ! -name "*.woff" \
139 ! -name "*.xproto" \
140 ! -name "*.xtarget" \
141 ! -name "*ignore" \
142 ! -name "*rc" \
143 ! -name "*_pb2.py" \
144 ! -name "*_pb2_grpc.py" \
145 ! -name "Dockerfile" \
146 ! -name "Dockerfile.*" \
147 ! -name "go.mod" \
148 ! -name "go.sum" \
149 ! -name "README" \
150 ! -path "*/vendor/*" \
151 ! -path "*conf*" \
152 ! -path "*git*" \
153 ! -path "*swagger*" \
154 ! -path "*.drawio" \
155 ! -name "*.pb.h" \
156 ! -name "*.pb.cc" \
157 ! -path "*/docs/*" \
158 ! -name 'output.xml' \
159 ! -path "*/vst_venv/*" \
160 ! -name '*#*' \
161 ! -path '*scripts/flog/*' \
162 ! -name '*~' \
163 ! -name 'VERSION' \
164 ! -name 'patch' \
165 -print0 )
166
167exit ${fail_licensecheck}