blob: d3b3fcefb9123377b2b96e72765c9ec255287814 [file] [log] [blame]
Joey Armstrong83874cc2022-11-26 09:40:08 -05001#!/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 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
36set +e -u -o pipefail
37fail_licensecheck=0
38
39declare -a gargs=()
40gargs+=('--extended-regexp')
41gargs+=('-e' 'Copyright[[:space:]]+[[:digit:]]{4}')
42# gargs+=('-e' 'Apache License')
43
44while IFS= read -r -d '' f
45do
46 grep -q "${gargs[@]}" "${f}"
47 rc=$?
48 if [[ $rc != 0 ]]; then
49 echo "ERROR: $f does not contain License Header"
50 fail_licensecheck=1
51 fi
52done < <(find . -name ".git" -prune -o -type f \
53 -name "*.*" \
54 ! -name "*.PNG" \
55 ! -name "*.asc" \
56 ! -name "*.bat" \
57 ! -name "*.bin" \
58 ! -name "*.cert" \
59 ! -name "*.cfg" \
60 ! -name "*.cnf" \
61 ! -name "*.conf" \
62 ! -name "*.cql" \
63 ! -name "*.crt" \
64 ! -name "*.csar" \
65 ! -name "*.csr" \
66 ! -name "*.csv" \
67 ! -name "*.ctmpl" \
68 ! -name "*.curl" \
69 ! -name "*.db" \
70 ! -name "*.der" \
71 ! -name "*.desc" \
72 ! -name "*.diff" \
73 ! -name "*.dnsmasq" \
74 ! -name "*.do" \
75 ! -name "*.docx" \
76 ! -name "*.eot" \
77 ! -name "*.gif" \
78 ! -name "*.gpg" \
79 ! -name "*.graffle" \
80 ! -name "*.ico" \
81 ! -name "*.iml" \
82 ! -name "*.in" \
83 ! -name "*.inc" \
84 ! -name "*.install" \
85 ! -name "*.j2" \
86 ! -name "*.jar" \
87 ! -name "*.jks" \
88 ! -name "*.jpg" \
89 ! -name "*.json" \
90 ! -name "*.jsonld" \
91 ! -name "*.JSON" \
92 ! -name "*.key" \
93 ! -name "*.list" \
94 ! -name "*.local" \
95 ! -path "*.lock" \
96 ! -name "*.log" \
97 ! -name "*.mak" \
98 ! -name "*.md" \
99 ! -name "*.MF" \
100 ! -name "*.mk" \
101 ! -name "*.oar" \
102 ! -name "*.p12" \
103 ! -name "*.patch" \
104 ! -name "*.pb.go" \
105 ! -name "*.pb.gw.go" \
106 ! -name "*.pdf" \
107 ! -name "*.pcap" \
108 ! -name "*.pem" \
109 ! -name "*.png" \
110 ! -name "*.properties" \
111 ! -name "*.proto" \
112 ! -name "*.protoset" \
113 ! -name "*.pyc" \
114 ! -name "*.repo" \
115 ! -name "*.robot" \
116 ! -name "*.rst" \
117 ! -name "*.rules" \
118 ! -name "*.service" \
119 ! -name "*.svg" \
120 ! -name "*.swp" \
121 ! -name "*.tar" \
122 ! -name "*.tar.gz" \
123 ! -name "*.toml" \
124 ! -name "*.ttf" \
125 ! -name "*.txt" \
126 ! -name "*.woff" \
127 ! -name "*.xproto" \
128 ! -name "*.xtarget" \
129 ! -name "*ignore" \
130 ! -name "*rc" \
131 ! -name "*_pb2.py" \
132 ! -name "*_pb2_grpc.py" \
133 ! -name "Dockerfile" \
134 ! -name "Dockerfile.*" \
135 ! -name "go.mod" \
136 ! -name "go.sum" \
137 ! -name "Makefile" \
138 ! -name "Makefile.*" \
139 ! -name "README" \
140 ! -path "*/vendor/*" \
141 ! -path "*conf*" \
142 ! -path "*git*" \
143 ! -path "*swagger*" \
144 ! -path "*.drawio" \
145 ! -name "*.pb.h" \
146 ! -name "*.pb.cc" \
147 ! -path "*/docs/*" \
148 ! -name 'output.xml' \
149 ! -path "*/vst_venv/*" \
150 ! -name '*#*' \
151 ! -name '*~' \
152 -print0 )
153
154exit ${fail_licensecheck}