1#!/bin/bash 2## This is a helper script invoked by ./generation/diff_files.sh 3## All the inputs to this script are provided by diff_files.sh 4## You do not need to do anything for this script to run. 5## Inputs provided in sequential order are : 6## 1. ${mavenURL} -> The URL for artifact's latest version directory on maven central 7## 2. ${sonatypeURL} -> The URL for artifact's staging directory on google sonatype 8## 3. ${artifactId} -> self-explanatory 9## 4. ${groupId} -> artifact's groupId 10## output for this script are 2 files: 11# 1. diff-files-summary.txt : This will show success for artifacts which have same files on maven-central and sonatype, 12# and if they differ, it will show a diff failure message along with the names of the files that differ. 13# 2. total-diff.txt : For every artifact, this will show 4 things: 14 # a. Sonatype directory URL 15 # b. Files that exist on sonatype (with version omitted, since we only care about the file generated) 16 # c. Maven directory URL 17 # d. Files that exist on Maven (with version omitted, since we only care about the file generated) 18 19mavenCentralURL=$1 20sonatypeURL=$2 21artifactId=$3 22groupId=$4 23 24wget -O sonatypeFile --recursive -nd --no-parent ${sonatypeURL} 25 26##why --header="User-Agent: ? -> Maven central denies CLI requests to browse a directory URL, so imitating a browser's behaviour by using this header. 27wget -O mavenFile --referer --recursive -nd --no-parent \ 28 --header="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36" \ 29 ${mavenCentralURL} 30 31sed -n 's/.*href="\([^"]*\).*/\1/p' mavenFile >mavenContents.txt 32sed -n 's/.*href="\([^"]*\).*/\1/p' sonatypeFile >sonatypeContents.txt 33 34awk "/${groupId}/" sonatypeContents.txt >temp.txt 35 36if [[ "${groupId}" = *api* ]]; then 37 cat temp.txt | while read line; do 38 echo ${line} | awk -F '[/]' '{print $13}' | sed 's/[0-9]*//g' >>finalSonatype.txt 39 done 40else 41 cat temp.txt | while read line; do 42 echo ${line} | awk -F '[/]' '{print $12}' | sed 's/[0-9]*//g' >>finalSonatype.txt 43 done 44fi 45 46cat mavenContents.txt | while read line; do 47 echo ${line} | sed 's/[0-9]*//g' >>finalMaven.txt 48 done 49sed -i '' '1d' finalMaven.txt 50 51echo "###################################################################################################################################" >>total-diff.txt 52echo "----${artifactId} Sonatype files : ${sonatypeURL}" >>total-diff.txt 53cat finalSonatype.txt >>total-diff.txt 54echo "----${artifactId} Maven files : ${mavenCentralURL}" >>total-diff.txt 55cat finalMaven.txt >>total-diff.txt 56 57echo "--------------------------------------------------------------------------------------------" >>diff-files-summary.txt 58if diff finalMaven.txt finalSonatype.txt >/dev/null; then 59 echo -e "${artifactId} File match success" >>diff-files-summary.txt 60else 61 echo "---------------------------------^NEW-DIFF-FOUND^-----------------------------------------" >>diff-files-summary.txt 62 echo "${artifactId} diff:" >>diff-files-summary.txt 63 diff finalMaven.txt finalSonatype.txt >>diff-files-summary.txt 64fi 65 66rm -f mavenFile 67rm -f sonatypeFile 68rm -f mavenContents.txt 69rm -f sonatypeContents.txt 70rm -f finalSonatype.txt 71rm -f finalMaven.txt 72rm -f temp.txt 73