| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 1 | # |
| 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 | |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame] | 18 | # Change log: |
| 19 | # 1. Bug 722 : Jayant Madavi : JM00553988@techmahindra.com : Enhancement to use new fossology server. Had to change the variable name at # couple of places, while scanning the variable name was adding curl as a license. |
| madavi | 7273dfb | 2019-07-25 11:32:57 +0530 | [diff] [blame] | 20 | # 2. Bug 542 : Jayant Madavi, Mrityunjay Yadav : JM00553988@techmahindra.com : 24-jul-2019 : Enhancement to raise exit in case files modified or added does # not contain license. |
| madavi | 7c1f734 | 2019-09-04 11:58:38 +0530 | [diff] [blame] | 21 | # 3. Bug 542 : Jayant Madavi, Mrityunjay Yadav : JM00553988@techmahindra.com :add exception list. for now as inLine. later need to create a variable for exception_list |
| beierlm | b633c70 | 2020-05-05 15:26:54 -0400 | [diff] [blame] | 22 | |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 23 | echo GERRIT BRANCH is $GERRIT_BRANCH |
| 24 | dpkg -l wget &>/dev/null ||sudo apt-get install -y wget |
| 25 | dpkg -l curl &>/dev/null ||sudo apt-get install -y curl |
| 26 | #Curl can be used instead of wget: |
| 27 | #curl -s -X POST -d @$file https://osm.etsi.org/fossology/?mod=agent_nomos_once |
| 28 | |
| 29 | apache=0 |
| 30 | nolicense=0 |
| 31 | other=0 |
| beierlm | bdca472 | 2020-09-03 14:02:30 -0400 | [diff] [blame^] | 32 | 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] | 33 | git fetch |
| 34 | |
| 35 | RE="FATAL: your file did not get passed through" |
| 36 | |
| madavi | b6e0266 | 2019-09-05 14:05:14 +0530 | [diff] [blame] | 37 | for file in $(echo ${exception_list} | xargs git diff --name-only origin/$GERRIT_BRANCH -- . ); do |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 38 | if [ -f $file ]; then |
| 39 | if [ -s $file ]; then |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame] | 40 | licnse=$(curl -s -X POST -H 'Accept: text' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' -H 'Content-Type: multipart/form-data' -H 'cache-control: no-cache' -F "file_input=@\"$file\"" -F 'showheader=1' https://fossology-osm.etsi.org/?mod=agent_nomos_once |grep "A one shot license analysis shows the following license(s) in file"|sed -n 's:.*<strong>\(.*\)</strong>.*:\1:p' |xargs) |
| 41 | result=$(echo $licnse | grep "$RE") |
| garciadeblas | c7f3524 | 2017-09-01 11:43:23 +0200 | [diff] [blame] | 42 | if [ -n "$result" ]; then |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 43 | # possibly we have exceeded the post rate |
| 44 | sleep 10 |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame] | 45 | licnse=$(curl -s -X POST -H 'Accept: text' -H 'Cache-Control: no-cache' -H 'Connection: keep-alive' -H 'Content-Type: multipart/form-data' -H 'cache-control: no-cache' -F "file_input=@\"$file\"" -F 'showheader=1' https://fossology-osm.etsi.org/?mod=agent_nomos_once |grep "A one shot license analysis shows the following license(s) in file"|sed -n 's:.*<strong>\(.*\)</strong>.*:\1:p' |xargs) |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 46 | fi |
| 47 | else |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame] | 48 | licnse="No_license_found" |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 49 | fi |
| 50 | else |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame] | 51 | licnse="DELETED" |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 52 | fi |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame] | 53 | echo "$file $licnse" |
| 54 | case "$licnse" in |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 55 | "Apache-2.0") |
| 56 | apache=$((apache + 1)) |
| 57 | ;; |
| 58 | "No_license_found") |
| 59 | nolicense=$((nolicense + 1)) |
| 60 | ;; |
| 61 | "DELETED") |
| 62 | ;; |
| 63 | "FATAL:*") |
| 64 | ;; |
| 65 | *) |
| 66 | echo "BAD LICENSE ON FILE $file" |
| 67 | other=$((other + 1)) |
| 68 | ;; |
| 69 | esac |
| 70 | done |
| 71 | |
| 72 | if [ $other -gt 0 ]; then |
| 73 | echo "FATAL: Non-apache licenses detected" |
| 74 | exit 2 |
| 75 | fi |
| 76 | |
| 77 | if [ $nolicense -gt 0 ]; then |
| madavi | 7273dfb | 2019-07-25 11:32:57 +0530 | [diff] [blame] | 78 | echo "FATAL: Unlicensed files found" |
| 79 | exit 2 |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 80 | fi |
| 81 | |
| 82 | exit 0 |