blob: 99fc07f1095d5881d93fa7b30c3014985a0e26ca [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
Joey Armstronga5278142023-06-28 16:56:54 -040040<<<<<<< HEAD
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040041echo "BLAH"
42exit 1
43
Joey Armstronga5278142023-06-28 16:56:54 -040044=======
45>>>>>>> dc6caae ([VOL-5064] - Build and deploy voltha-system-tests)
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040046set +e -u -o pipefail
47fail_licensecheck=0
48
49declare -a gargs=()
50gargs+=('--extended-regexp')
51
52# Evil regex -- scripts detecting pattern are excluded from checking.
53gargs+=('-e' 'Apache License')
54
55# Good regex -- no false positives.
56gargs+=('-e' 'Copyright[[:space:]]+[[:digit:]]{4}')
57
58while IFS= read -r -d '' path
59do
Joey Armstronga5278142023-06-28 16:56:54 -040060<<<<<<< HEAD
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040061 case "$path" in
62 *venv*) echo "GERR: $path"
63 exit 1
64 ;;
65 esac
Joey Armstronga5278142023-06-28 16:56:54 -040066=======
67>>>>>>> dc6caae ([VOL-5064] - Build and deploy voltha-system-tests)
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040068 if ! grep -q "${gargs[@]}" "${path}";
69 then
70 echo "ERROR: $path does not contain License Header"
71 fail_licensecheck=1
72 fi
Joey Armstronga5278142023-06-28 16:56:54 -040073<<<<<<< HEAD
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040074done < <(find . \( -name ".git" -o -name '.venv' -o 'vst_venv' \) -prune -o -type f \
Joey Armstronga5278142023-06-28 16:56:54 -040075=======
76done < <(find . -name ".git" -prune -o -type f \
77>>>>>>> dc6caae ([VOL-5064] - Build and deploy voltha-system-tests)
Joey Armstrong04cdd9f2023-06-09 15:18:23 -040078 ! -iname "*.png" \
79 ! -name "*.asc" \
80 ! -name "*.bat" \
81 ! -name "*.bin" \
82 ! -name "*.cert" \
83 ! -name "*.cfg" \
84 ! -name "*.cnf" \
85 ! -name "*.conf" \
86 ! -name "*.cql" \
87 ! -name "*.crt" \
88 ! -name "*.csar" \
89 ! -name "*.csr" \
90 ! -name "*.csv" \
91 ! -name "*.ctmpl" \
92 ! -name "*.curl" \
93 ! -name "*.db" \
94 ! -name "*.der" \
95 ! -name "*.desc" \
96 ! -name "*.diff" \
97 ! -name "*.dnsmasq" \
98 ! -name "*.do" \
99 ! -name "*.docx" \
100 ! -name "*.eot" \
101 ! -name "*.gif" \
102 ! -name "*.gpg" \
103 ! -name "*.graffle" \
104 ! -name "*.ico" \
105 ! -name "*.iml" \
106 ! -name "*.in" \
107 ! -name "*.inc" \
108 ! -name "*.install" \
109 ! -name "*.j2" \
110 ! -name "*.jar" \
111 ! -name "*.jks" \
112 ! -name "*.jpg" \
113 ! -name "*.json" \
114 ! -name "*.jsonld" \
115 ! -name "*.JSON" \
116 ! -name "*.key" \
117 ! -name "*.list" \
118 ! -name "*.local" \
119 ! -path "*.lock" \
120 ! -name "*.log" \
121 ! -name "*.mak" \
122 ! -name "*.md" \
123 ! -name "*.MF" \
124 ! -name "*.oar" \
125 ! -name "*.p12" \
126 ! -name "*.patch" \
127 ! -name "*.pb.go" \
128 ! -name "*.pb.gw.go" \
129 ! -name "*.pdf" \
130 ! -name "*.pcap" \
131 ! -name "*.pem" \
132 ! -name "*.properties" \
133 ! -name "*.proto" \
134 ! -name "*.protoset" \
135 ! -name "*.pyc" \
136 ! -name "*.repo" \
137 ! -name "*.robot" \
138 ! -name "*.rst" \
139 ! -name "*.rules" \
140 ! -name "*.service" \
141 ! -name "*.svg" \
142 ! -name "*.swp" \
143 ! -name "*.tar" \
144 ! -name "*.tar.gz" \
145 ! -name "*.toml" \
146 ! -name "*.ttf" \
147 ! -name "*.txt" \
148 ! -name "*.woff" \
149 ! -name "*.xproto" \
150 ! -name "*.xtarget" \
151 ! -name "*ignore" \
152 ! -name "*rc" \
153 ! -name "*_pb2.py" \
154 ! -name "*_pb2_grpc.py" \
155 ! -name "Dockerfile" \
156 ! -name "Dockerfile.*" \
157 ! -name "go.mod" \
158 ! -name "go.sum" \
159 ! -name "README" \
160 ! -path "*/vendor/*" \
161 ! -path "*conf*" \
162 ! -path "*git*" \
163 ! -path "*swagger*" \
164 ! -path "*.drawio" \
165 ! -name "*.pb.h" \
166 ! -name "*.pb.cc" \
167 ! -path "*/docs/*" \
Joey Armstronga5278142023-06-28 16:56:54 -0400168<<<<<<< HEAD
Joey Armstrong04cdd9f2023-06-09 15:18:23 -0400169 ! -name 'output.xml' \
170 ! -path "*/vst_venv/*" \
Joey Armstronga5278142023-06-28 16:56:54 -0400171=======
172 ! -name 'output.xml' \
173 ! -path "*/.venv/*" \
174>>>>>>> dc6caae ([VOL-5064] - Build and deploy voltha-system-tests)
Joey Armstrong04cdd9f2023-06-09 15:18:23 -0400175 ! -name '*#*' \
176 ! -path '*scripts/flog/*' \
177 ! -name '*~' \
178 ! -name 'VERSION' \
179 ! -name 'patch' \
180 -print0 )
181
182exit ${fail_licensecheck}