blob: 1f692e94b59e865c80dfc3c371b83615a13c008a [file] [log] [blame]
Joey Armstrong83874cc2022-11-26 09:40:08 -05001#!/usr/bin/env bash
2
3# -----------------------------------------------------------------------
Joey Armstrong57bd70f2023-01-12 05:25:51 -05004# Copyright 2022-2023 Open Networking Foundation (ONF) and the ONF Contributors
Joey Armstrong83874cc2022-11-26 09:40:08 -05005#
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
40set +e -u -o pipefail
41fail_licensecheck=0
42
43declare -a gargs=()
44gargs+=('--extended-regexp')
45
46# Evil regex -- scripts detecting pattern are excluded from checking.
47gargs+=('-e' 'Apache License')
48
49# Good regex -- no false positives.
50gargs+=('-e' 'Copyright[[:space:]]+[[:digit:]]{4}')
51
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040052declare -a excl=()
53excl+=('-name' '.git')
54excl+=('-o' '-name' '.venv')
55excl+=('-o' '-name' 'vst_venv')
56
Joey Armstrong83874cc2022-11-26 09:40:08 -050057while IFS= read -r -d '' path
58do
59 if ! grep -q "${gargs[@]}" "${path}";
60 then
61 echo "ERROR: $path does not contain License Header"
62 fail_licensecheck=1
63 fi
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040064done < <(find . \
65 \( "${excl[@]}" \) \
66 -prune -o -type f \
Joey Armstrong83874cc2022-11-26 09:40:08 -050067 ! -iname "*.png" \
68 ! -name "*.asc" \
69 ! -name "*.bat" \
70 ! -name "*.bin" \
71 ! -name "*.cert" \
72 ! -name "*.cfg" \
73 ! -name "*.cnf" \
74 ! -name "*.conf" \
75 ! -name "*.cql" \
76 ! -name "*.crt" \
77 ! -name "*.csar" \
78 ! -name "*.csr" \
79 ! -name "*.csv" \
80 ! -name "*.ctmpl" \
81 ! -name "*.curl" \
82 ! -name "*.db" \
83 ! -name "*.der" \
84 ! -name "*.desc" \
85 ! -name "*.diff" \
86 ! -name "*.dnsmasq" \
87 ! -name "*.do" \
88 ! -name "*.docx" \
89 ! -name "*.eot" \
90 ! -name "*.gif" \
91 ! -name "*.gpg" \
92 ! -name "*.graffle" \
93 ! -name "*.ico" \
94 ! -name "*.iml" \
95 ! -name "*.in" \
96 ! -name "*.inc" \
97 ! -name "*.install" \
98 ! -name "*.j2" \
99 ! -name "*.jar" \
100 ! -name "*.jks" \
101 ! -name "*.jpg" \
102 ! -name "*.json" \
103 ! -name "*.jsonld" \
104 ! -name "*.JSON" \
105 ! -name "*.key" \
106 ! -name "*.list" \
107 ! -name "*.local" \
108 ! -path "*.lock" \
109 ! -name "*.log" \
110 ! -name "*.mak" \
111 ! -name "*.md" \
112 ! -name "*.MF" \
113 ! -name "*.oar" \
114 ! -name "*.p12" \
115 ! -name "*.patch" \
116 ! -name "*.pb.go" \
117 ! -name "*.pb.gw.go" \
118 ! -name "*.pdf" \
119 ! -name "*.pcap" \
120 ! -name "*.pem" \
121 ! -name "*.properties" \
122 ! -name "*.proto" \
123 ! -name "*.protoset" \
124 ! -name "*.pyc" \
125 ! -name "*.repo" \
126 ! -name "*.robot" \
127 ! -name "*.rst" \
128 ! -name "*.rules" \
129 ! -name "*.service" \
130 ! -name "*.svg" \
131 ! -name "*.swp" \
132 ! -name "*.tar" \
133 ! -name "*.tar.gz" \
134 ! -name "*.toml" \
135 ! -name "*.ttf" \
136 ! -name "*.txt" \
137 ! -name "*.woff" \
138 ! -name "*.xproto" \
139 ! -name "*.xtarget" \
140 ! -name "*ignore" \
141 ! -name "*rc" \
142 ! -name "*_pb2.py" \
143 ! -name "*_pb2_grpc.py" \
144 ! -name "Dockerfile" \
145 ! -name "Dockerfile.*" \
146 ! -name "go.mod" \
147 ! -name "go.sum" \
148 ! -name "README" \
149 ! -path "*/vendor/*" \
150 ! -path "*conf*" \
151 ! -path "*git*" \
152 ! -path "*swagger*" \
153 ! -path "*.drawio" \
154 ! -name "*.pb.h" \
155 ! -name "*.pb.cc" \
156 ! -path "*/docs/*" \
157 ! -name 'output.xml' \
158 ! -path "*/vst_venv/*" \
159 ! -name '*#*' \
160 ! -path '*scripts/flog/*' \
161 ! -name '*~' \
162 ! -name 'VERSION' \
163 ! -name 'patch' \
164 -print0 )
165
166exit ${fail_licensecheck}