X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=tools%2Flicense_scan.sh;h=dfcda7e4b5b507453da85e7c225249fa5cb734dd;hb=6248fe6005403005832d6e770e83322d5f679e0f;hp=329560034435d1e0b0f1ac00c347dd568b69030e;hpb=771f06aae780e07eb9b2929374989b641aae851c;p=osm%2Fdevops.git diff --git a/tools/license_scan.sh b/tools/license_scan.sh index 32956003..dfcda7e4 100755 --- a/tools/license_scan.sh +++ b/tools/license_scan.sh @@ -15,6 +15,11 @@ # #!/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 @@ -24,28 +29,29 @@ dpkg -l curl &>/dev/null ||sudo apt-get install -y curl apache=0 nolicense=0 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 $(git diff --name-only origin/$GERRIT_BRANCH); do +for file in $(echo ${exception_list} | xargs git diff --name-only origin/$GERRIT_BRANCH -- . ); do if [ -f $file ]; then if [ -s $file ]; then - license=$(wget -qO - --post-file $file https://osm.etsi.org/fossology/?mod=agent_nomos_once |sed "s/^[ \t]*//;s/[ \t]*$//") - if [[ $license =~ $RE ]]; 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 - license=$(wget -qO - --post-file $file https://osm.etsi.org/fossology/?mod=agent_nomos_once |sed "s/^[ \t]*//;s/[ \t]*$//") + 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) fi else - license="No_license_found" + licnse="No_license_found" fi else - license="DELETED" + licnse="DELETED" fi - echo "$file $license" - case "$license" in + echo "$file $licnse" + case "$licnse" in "Apache-2.0") apache=$((apache + 1)) ;; @@ -69,7 +75,8 @@ if [ $other -gt 0 ]; then fi if [ $nolicense -gt 0 ]; then - echo "WARNING: Unlicensed files found" + echo "FATAL: Unlicensed files found" + exit 2 fi exit 0