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