| 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 | apache=0 |
| 18 | nolicense=0 |
| 19 | other=0 |
| garciadeblas | 15199a1 | 2025-05-21 11:23:13 +0200 | [diff] [blame] | 20 | binaries=0 |
| 21 | deleted=0 |
| beierlm | bdca472 | 2020-09-03 14:02:30 -0400 | [diff] [blame] | 22 | 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] | 23 | git fetch |
| 24 | |
| garciadeblas | 15199a1 | 2025-05-21 11:23:13 +0200 | [diff] [blame] | 25 | if [ -n "${GERRIT_BRANCH}" ]; then |
| 26 | COMMIT_TO_COMPARE="origin/${GERRIT_BRANCH}" |
| 27 | else |
| 28 | COMMIT_TO_COMPARE="HEAD^" |
| 29 | fi |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 30 | |
| garciadeblas | 15199a1 | 2025-05-21 11:23:13 +0200 | [diff] [blame] | 31 | total_changes=$(git diff --name-only ${COMMIT_TO_COMPARE} -- . $(echo ${exception_list}) | wc -l) |
| 32 | for file in $(git diff --name-only ${COMMIT_TO_COMPARE} -- . $(echo ${exception_list})); do |
| 33 | # Skip deleted files |
| 34 | if [ ! -f "$file" ]; then |
| 35 | deleted=$((deleted + 1)) |
| 36 | continue |
| 37 | fi |
| 38 | |
| 39 | file_type=$(file -b --mime-type "$file" | sed 's|/.*||') |
| 40 | echo "$file is $file_type" |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 41 | case "$file_type" in |
| 42 | text) |
| 43 | binary=false |
| 44 | ;; |
| 45 | *) |
| 46 | binary=true |
| 47 | ;; |
| 48 | esac |
| 49 | |
| 50 | if $binary ; then |
| 51 | license=Binary |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 52 | else |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 53 | license="No Apache license found" |
| garciadeblas | 15199a1 | 2025-05-21 11:23:13 +0200 | [diff] [blame] | 54 | if [ -s "$file" ]; then |
| 55 | if grep -q "http://www.apache.org/licenses/LICENSE-2.0" "$file"; then |
| 56 | license="Apache-2.0" |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 57 | fi |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 58 | fi |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 59 | fi |
| beierlm | 9da3312 | 2020-12-10 15:22:15 -0500 | [diff] [blame] | 60 | echo "$file $license" |
| 61 | case "$license" in |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 62 | "Apache-2.0") |
| 63 | apache=$((apache + 1)) |
| 64 | ;; |
| beierlm | 9da3312 | 2020-12-10 15:22:15 -0500 | [diff] [blame] | 65 | No*) |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 66 | nolicense=$((nolicense + 1)) |
| 67 | ;; |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 68 | "Binary") |
| garciadeblas | 15199a1 | 2025-05-21 11:23:13 +0200 | [diff] [blame] | 69 | binaries=$((binaries + 1)) |
| Mark Beierl | 02467ed | 2022-08-11 21:59:11 -0400 | [diff] [blame] | 70 | ;; |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 71 | *) |
| 72 | echo "BAD LICENSE ON FILE $file" |
| 73 | other=$((other + 1)) |
| 74 | ;; |
| 75 | esac |
| 76 | done |
| 77 | |
| garciadeblas | 15199a1 | 2025-05-21 11:23:13 +0200 | [diff] [blame] | 78 | echo "Changes in license in this commit: ${total_changes}" |
| 79 | echo " Deleted files: ${deleted}" |
| 80 | echo " Binaries: ${binaries}" |
| 81 | echo " Apache license: ${apache}" |
| 82 | echo " No license: ${nolicense}" |
| 83 | echo " Other license: ${other}" |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 84 | |
| 85 | if [ $nolicense -gt 0 ]; then |
| beierlm | 9da3312 | 2020-12-10 15:22:15 -0500 | [diff] [blame] | 86 | echo "FATAL: Files without apache license found" |
| madavi | 7273dfb | 2019-07-25 11:32:57 +0530 | [diff] [blame] | 87 | exit 2 |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 88 | fi |
| 89 | |
| 90 | exit 0 |