| 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. |
| 20 | # 2. |
| 21 | |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 22 | echo GERRIT BRANCH is $GERRIT_BRANCH |
| 23 | dpkg -l wget &>/dev/null ||sudo apt-get install -y wget |
| 24 | dpkg -l curl &>/dev/null ||sudo apt-get install -y curl |
| 25 | #Curl can be used instead of wget: |
| 26 | #curl -s -X POST -d @$file https://osm.etsi.org/fossology/?mod=agent_nomos_once |
| 27 | |
| 28 | apache=0 |
| 29 | nolicense=0 |
| 30 | other=0 |
| 31 | |
| 32 | git fetch |
| 33 | |
| 34 | RE="FATAL: your file did not get passed through" |
| 35 | |
| 36 | for file in $(git diff --name-only origin/$GERRIT_BRANCH); do |
| 37 | if [ -f $file ]; then |
| 38 | if [ -s $file ]; then |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame^] | 39 | 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) |
| 40 | result=$(echo $licnse | grep "$RE") |
| garciadeblas | c7f3524 | 2017-09-01 11:43:23 +0200 | [diff] [blame] | 41 | if [ -n "$result" ]; then |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 42 | # possibly we have exceeded the post rate |
| 43 | sleep 10 |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame^] | 44 | 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] | 45 | fi |
| 46 | else |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame^] | 47 | licnse="No_license_found" |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 48 | fi |
| 49 | else |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame^] | 50 | licnse="DELETED" |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 51 | fi |
| madavi | be2ed34 | 2019-07-09 15:00:05 +0530 | [diff] [blame^] | 52 | echo "$file $licnse" |
| 53 | case "$licnse" in |
| Mike Marchetti | 771f06a | 2017-07-28 16:08:31 -0400 | [diff] [blame] | 54 | "Apache-2.0") |
| 55 | apache=$((apache + 1)) |
| 56 | ;; |
| 57 | "No_license_found") |
| 58 | nolicense=$((nolicense + 1)) |
| 59 | ;; |
| 60 | "DELETED") |
| 61 | ;; |
| 62 | "FATAL:*") |
| 63 | ;; |
| 64 | *) |
| 65 | echo "BAD LICENSE ON FILE $file" |
| 66 | other=$((other + 1)) |
| 67 | ;; |
| 68 | esac |
| 69 | done |
| 70 | |
| 71 | if [ $other -gt 0 ]; then |
| 72 | echo "FATAL: Non-apache licenses detected" |
| 73 | exit 2 |
| 74 | fi |
| 75 | |
| 76 | if [ $nolicense -gt 0 ]; then |
| 77 | echo "WARNING: Unlicensed files found" |
| 78 | fi |
| 79 | |
| 80 | exit 0 |