From 9da33128bfa6c4cfdf01f053ea96621c8bd7b4f6 Mon Sep 17 00:00:00 2001 From: beierlm Date: Thu, 10 Dec 2020 15:22:15 -0500 Subject: [PATCH] Simpler license scan Removes the post to Fossology to simply check for the Apache 2 license text Change-Id: I455149474d86c85cbd3dbb0af6dbe660b599ffee Signed-off-by: beierlm --- tools/license_scan.sh | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-) diff --git a/tools/license_scan.sh b/tools/license_scan.sh index dfcda7e4..b20bb0af 100755 --- a/tools/license_scan.sh +++ b/tools/license_scan.sh @@ -1,3 +1,4 @@ +#!/bin/sh # # Copyright 2016 Telefónica Investigación y Desarrollo, S.A.U. # @@ -13,18 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -#!/bin/sh - -# Change log: -# 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. -# 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. -# 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 - -echo GERRIT BRANCH is $GERRIT_BRANCH -dpkg -l wget &>/dev/null ||sudo apt-get install -y wget -dpkg -l curl &>/dev/null ||sudo apt-get install -y curl -#Curl can be used instead of wget: -#curl -s -X POST -d @$file https://osm.etsi.org/fossology/?mod=agent_nomos_once apache=0 nolicense=0 @@ -32,36 +21,27 @@ other=0 exception_list="':(exclude)*.pdf' ':(exclude)*.png' ':(exclude)*.jpeg' ':(exclude)*.jpg' ':(exclude)*.gif' ':(exclude)*.json' ':(exclude)*.ico' ':(exclude)*.svg' ':(exclude)*.tiff'" git fetch -RE="FATAL: your file did not get passed through" - for file in $(echo ${exception_list} | xargs git diff --name-only origin/$GERRIT_BRANCH -- . ); do + license="No Apache license found" if [ -f $file ]; then if [ -s $file ]; then - 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:.*\(.*\).*:\1:p' |xargs) - result=$(echo $licnse | grep "$RE") - if [ -n "$result" ]; then - # possibly we have exceeded the post rate - sleep 10 - 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:.*\(.*\).*:\1:p' |xargs) + if [ $(grep -c "http://www.apache.org/licenses/LICENSE-2.0" $file) -ge 1 ] ; then + license="Apache-2.0" fi - else - licnse="No_license_found" fi else - licnse="DELETED" + license="DELETED" fi - echo "$file $licnse" - case "$licnse" in + echo "$file $license" + case "$license" in "Apache-2.0") apache=$((apache + 1)) ;; - "No_license_found") + No*) nolicense=$((nolicense + 1)) ;; "DELETED") ;; - "FATAL:*") - ;; *) echo "BAD LICENSE ON FILE $file" other=$((other + 1)) @@ -69,13 +49,9 @@ for file in $(echo ${exception_list} | xargs git diff --name-only origin/$GERRIT esac done -if [ $other -gt 0 ]; then - echo "FATAL: Non-apache licenses detected" - exit 2 -fi if [ $nolicense -gt 0 ]; then - echo "FATAL: Unlicensed files found" + echo "FATAL: Files without apache license found" exit 2 fi -- 2.25.1