| beierlm | 9da3312 | 2020-12-10 15:22:15 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U. |
| 4 | # |
| 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 | # |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 17 | |
| 18 | apache=0 |
| 19 | nolicense=0 |
| 20 | other=0 |
| beierlm | bdca472 | 2020-09-03 14:02:30 -0400 | [diff] [blame] | 21 | exception_list="':(exclude)*.pdf' ':(exclude)*.png' ':(exclude)*.jpeg' ':(exclude)*.jpg' ':(exclude)*.gif' ':(exclude)*.json' ':(exclude)*.ico' ':(exclude)*.svg' ':(exclude)*.tiff'" |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 22 | git fetch |
| 23 | |
| madavi | b6e0266 | 2019-09-05 14:05:14 +0530 | [diff] [blame] | 24 | for file in $(echo ${exception_list} | xargs git diff --name-only origin/$GERRIT_BRANCH -- . ); do |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 25 | |
| 26 | file_type=$(file -b --mime-type $file | sed 's|/.*||') |
| 27 | echo $file is $file_type |
| 28 | case "$file_type" in |
| 29 | text) |
| 30 | binary=false |
| 31 | ;; |
| 32 | *) |
| 33 | binary=true |
| 34 | ;; |
| 35 | esac |
| 36 | |
| 37 | if $binary ; then |
| 38 | license=Binary |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 39 | else |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 40 | license="No Apache license found" |
| 41 | if [ -f $file ]; then |
| 42 | if [ -s $file ]; then |
| 43 | if [ $(grep -c "http://www.apache.org/licenses/LICENSE-2.0" $file) -ge 1 ] ; then |
| 44 | license="Apache-2.0" |
| 45 | fi |
| 46 | fi |
| 47 | else |
| 48 | license="DELETED" |
| 49 | fi |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 50 | fi |
| beierlm | 9da3312 | 2020-12-10 15:22:15 -0500 | [diff] [blame] | 51 | echo "$file $license" |
| 52 | case "$license" in |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 53 | "Apache-2.0") |
| 54 | apache=$((apache + 1)) |
| 55 | ;; |
| beierlm | 9da3312 | 2020-12-10 15:22:15 -0500 | [diff] [blame] | 56 | No*) |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 57 | nolicense=$((nolicense + 1)) |
| 58 | ;; |
| 59 | "DELETED") |
| 60 | ;; |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 61 | "Binary") |
| 62 | ;; |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 63 | *) |
| 64 | echo "BAD LICENSE ON FILE $file" |
| 65 | other=$((other + 1)) |
| 66 | ;; |
| 67 | esac |
| 68 | done |
| 69 | |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 70 | |
| 71 | if [ $nolicense -gt 0 ]; then |
| beierlm | 9da3312 | 2020-12-10 15:22:15 -0500 | [diff] [blame] | 72 | echo "FATAL: Files without apache license found" |
| madavi | 7273dfb | 2019-07-25 11:32:57 +0530 | [diff] [blame] | 73 | exit 2 |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 74 | fi |
| 75 | |
| 76 | exit 0 |