blob: 47106e0e001cd98a2bbb55cf63d2bac09d031394 [file] [log] [blame]
Mike Marchetti771f06a2017-07-28 16:08:31 -04001#
2# Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16#!/bin/sh
17
18echo GERRIT BRANCH is $GERRIT_BRANCH
19dpkg -l wget &>/dev/null ||sudo apt-get install -y wget
20dpkg -l curl &>/dev/null ||sudo apt-get install -y curl
21#Curl can be used instead of wget:
22#curl -s -X POST -d @$file https://osm.etsi.org/fossology/?mod=agent_nomos_once
23
24apache=0
25nolicense=0
26other=0
27
28git fetch
29
30RE="FATAL: your file did not get passed through"
31
32for file in $(git diff --name-only origin/$GERRIT_BRANCH); do
33 if [ -f $file ]; then
34 if [ -s $file ]; then
35 license=$(wget -qO - --post-file $file https://osm.etsi.org/fossology/?mod=agent_nomos_once |sed "s/^[ \t]*//;s/[ \t]*$//")
garciadeblasc7f35242017-09-01 11:43:23 +020036 result=$(echo $license | grep "$RE")
37 if [ -n "$result" ]; then
Mike Marchetti771f06a2017-07-28 16:08:31 -040038 # possibly we have exceeded the post rate
39 sleep 10
40 license=$(wget -qO - --post-file $file https://osm.etsi.org/fossology/?mod=agent_nomos_once |sed "s/^[ \t]*//;s/[ \t]*$//")
41 fi
42 else
43 license="No_license_found"
44 fi
45 else
46 license="DELETED"
47 fi
48 echo "$file $license"
49 case "$license" in
50 "Apache-2.0")
51 apache=$((apache + 1))
52 ;;
53 "No_license_found")
54 nolicense=$((nolicense + 1))
55 ;;
56 "DELETED")
57 ;;
58 "FATAL:*")
59 ;;
60 *)
61 echo "BAD LICENSE ON FILE $file"
62 other=$((other + 1))
63 ;;
64 esac
65done
66
67if [ $other -gt 0 ]; then
68 echo "FATAL: Non-apache licenses detected"
69 exit 2
70fi
71
72if [ $nolicense -gt 0 ]; then
73 echo "WARNING: Unlicensed files found"
74fi
75
76exit 0