Skip to content

Instantly share code, notes, and snippets.

@HokieGeek
Last active August 31, 2018 17:01
Show Gist options
  • Save HokieGeek/9cf1b340df0472a402e39a65a0837090 to your computer and use it in GitHub Desktop.
Save HokieGeek/9cf1b340df0472a402e39a65a0837090 to your computer and use it in GitHub Desktop.
#!/bin/bash
## ./compare-boms.sh ./AnotherCompetitorBOM.xlsx ./dvi-edge-dnp3-Build-20180828-195954.pdf
(( $# < 2 )) && {
echo "ERROR: Not enough arguments" >&2
echo "USAGE: ${0##*/} COMPETITOR_BOM_XLS SONATYPE_REPORT"
exit 1
}
dir="bom"
theirs="${dir}/their-components"
ours="${dir}/sonatype-components"
mkdir -p ${dir}
# trap 'rm -rf $theirs $ours' EXIT
# Convert excel sheet to csv and retrieve list of components
ssconvert $1 --export-type=Gnumeric_stf:stf_csv fd://1 \
| sed '1d;
/^[[:space:]]/d;
/^$/d;
/web pages,/,/600 StringTemplate/d;
/implements Stax/d;
s/^\([^,]*\),.*/\1/;
' | sort -u > ${theirs}
# Retrieve list of components from Sonatype app report PDF
gs -sDEVICE=txtwrite -sOutputFile=- -q -dNOPAUSE $2 2>/dev/null | tr -d '\r' \
| sed -E \
-e '
1,/^[[:space:]]+Components/d;
/Match State/d;
s/^[[:space:]]*//;
s/[[:space:]]+(exact|unknown) .*$//;
/(:|-)[[:space:]]*$/{
N;
s/:\n[[:space:]]*/: /;
s/-\n[[:space:]]*/-/;
};
' \
-e '
/(( : *)+|(.jar|.dll|.zip|.war$))/!d;
' | awk -F" : " '
/^ *\t*\n*$/ { next }
NF > 1 { printf("%s-%s.jar\n", $2, $3) }
NF == 1 { print }
' | sort -u > ${ours}
theirs_only="${dir}/theirs-only"
ours_only="${dir}/sonatype-only"
both="${dir}/both-only"
comm -2 -3 ${theirs} ${ours} > ${theirs_only}
comm -1 -3 ${theirs} ${ours} > ${ours_only}
comm -1 -2 ${theirs} ${ours} > ${both}
vim ${theirs_only} ${ours_only} ${both} ${theirs} ${ours} +'tab all'
# vim <(comm -2 -3 ${theirs} ${ours}) <(comm -1 -3 ${theirs} ${ours}) <(comm -1 -2 ${theirs} ${ours}) ${theirs} ${ours} +'tab all'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment