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