blob: b20bb0afb9002c8c8e5706a70ebf520f742de5f4 [file] [log] [blame]
beierlm9da33122020-12-10 15:22:15 -05001#!/bin/sh
Mike Marchetti771f06a2017-07-28 16:08:31 -04002#
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 Marchetti771f06a2017-07-28 16:08:31 -040017
18apache=0
19nolicense=0
20other=0
beierlmbdca4722020-09-03 14:02:30 -040021exception_list="':(exclude)*.pdf' ':(exclude)*.png' ':(exclude)*.jpeg' ':(exclude)*.jpg' ':(exclude)*.gif' ':(exclude)*.json' ':(exclude)*.ico' ':(exclude)*.svg' ':(exclude)*.tiff'"
Mike Marchetti771f06a2017-07-28 16:08:31 -040022git fetch
23
madavib6e02662019-09-05 14:05:14 +053024for file in $(echo ${exception_list} | xargs git diff --name-only origin/$GERRIT_BRANCH -- . ); do
beierlm9da33122020-12-10 15:22:15 -050025 license="No Apache license found"
Mike Marchetti771f06a2017-07-28 16:08:31 -040026 if [ -f $file ]; then
27 if [ -s $file ]; then
beierlm9da33122020-12-10 15:22:15 -050028 if [ $(grep -c "http://www.apache.org/licenses/LICENSE-2.0" $file) -ge 1 ] ; then
29 license="Apache-2.0"
Mike Marchetti771f06a2017-07-28 16:08:31 -040030 fi
Mike Marchetti771f06a2017-07-28 16:08:31 -040031 fi
32 else
beierlm9da33122020-12-10 15:22:15 -050033 license="DELETED"
Mike Marchetti771f06a2017-07-28 16:08:31 -040034 fi
beierlm9da33122020-12-10 15:22:15 -050035 echo "$file $license"
36 case "$license" in
Mike Marchetti771f06a2017-07-28 16:08:31 -040037 "Apache-2.0")
38 apache=$((apache + 1))
39 ;;
beierlm9da33122020-12-10 15:22:15 -050040 No*)
Mike Marchetti771f06a2017-07-28 16:08:31 -040041 nolicense=$((nolicense + 1))
42 ;;
43 "DELETED")
44 ;;
Mike Marchetti771f06a2017-07-28 16:08:31 -040045 *)
46 echo "BAD LICENSE ON FILE $file"
47 other=$((other + 1))
48 ;;
49 esac
50done
51
Mike Marchetti771f06a2017-07-28 16:08:31 -040052
53if [ $nolicense -gt 0 ]; then
beierlm9da33122020-12-10 15:22:15 -050054 echo "FATAL: Files without apache license found"
madavi7273dfb2019-07-25 11:32:57 +053055 exit 2
Mike Marchetti771f06a2017-07-28 16:08:31 -040056fi
57
58exit 0