Skip to content

Instantly share code, notes, and snippets.

@rompetroll
Last active December 16, 2015 17:09
Show Gist options
  • Save rompetroll/5468004 to your computer and use it in GitHub Desktop.
Save rompetroll/5468004 to your computer and use it in GitHub Desktop.
script for comparing two directories containing java packages (jar,war,ear,zip etc). The script basically builds input for http://pkgdiff.github.io/pkgdiff/ if you give it two "versions" of a distribution dir. The script only handles up to one level of nesting, so structures like these work: copy1 |_ enterprise.sar |_sub |_ some.jar |_ a.war cop…
#!/bin/bash
dir1=$1
dir2=$2
die() {
echo >&2 "$@"
exit 1
}
[ -d "$dir1" ] || die "first parameter not a directory: $dir1"
[ -d "$dir2" ] || die "second parameter not a directory: $dir2"
i() {
echo -e "[INFO] " $@
}
mkdir -p /tmp/diffreport
DCMD="/tmp/diffreport/pkgdiff-1.5/pkgdiff.pl"
if [ ! -f $DCMD ];
then
cd /tmp/diffreport
i "downloading pkgdiff"
curl "https://codeload.github.com/pkgdiff/pkgdiff/tar.gz/1.5" | tar xz
cd -
fi
declare -a PACKAGES=()
addToList() {
i "...adding \E[32m$1\E[00m to list of changed packages"
PACKAGES+=" $1"
}
d() {
if [ -d "$dir1/$1" ]; then
d=$(diff $dir1/$1 $dir2/$1 | grep -v "Common subdirectories" | sed ':a;N;$!ba;s|\n| |g')
if [[ "$d" == *"Only in"* ]]; then
i "\E[33m$d\E[00m"
else
d=$(echo $d | sed -e "s|Binary\ files\ ||gi")
d=$(echo $d | sed -e "s|and\ .*"$dir1"|"$dir1"|gi")
d=$(echo $d | sed -e "s|and\ .*$||")
#echo "D3: $d"
if [ -z "$d" ]
then
i "\E[34mno change\E[00m"
else
for change in $d
do
addToList "$change"
done
fi
fi
fi
}
i "checking toplevel directories for changes"
d "."
DIRS=$(find $dir1 -type d -printf '%f\n' | grep -v $dir1)
for dir in $DIRS; do
i "checking $dir"
d "$dir"
done
i "checking following packages:\n"
for p in $PACKAGES; do echo $p; done
xml() {
name=$1
echo "<version>$name</version><group>pp</group><packages>" > /tmp/diffreport/$name.xml
for p in $PACKAGES; do
if [ -z $2 ]; then
echo "$p" >> /tmp/diffreport/$name.xml
else
echo "$p" | sed -e "s|"$dir1"|"$dir2"|" >> /tmp/diffreport/$name.xml
fi
done;
echo "</packages>" >> /tmp/diffreport/$name.xml
}
xml "OLD"
xml "NEW" "replacepath"
$DCMD -report-path /tmp/diffreport/report/index.html /tmp/diffreport/OLD.xml /tmp/diffreport/NEW.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment