makedist/obsoleted/isodiff.sh

111 lines
2.9 KiB
Bash
Raw Normal View History

#!/bin/sh
#
# openmamba ISO RPM differences report creator
# Copyright (c) 2010 by Silvan Calarco <silvan.calarco@mambasoft.it>
#
TMPDIR=/tmp/isodiff
function create_count_files() {
local F=$1
SIZE=0
rpm -r $TMPDIR/$F -qa --queryformat "%{NAME} %{SIZE}\n" | sort > $TMPDIR/$F-rpm.txt
> $TMPDIR/$F-rpm-size.txt
while read line; do
set -- $line
SIZE=`expr $SIZE + $2`
echo "$1 $SIZE" >> $TMPDIR/$F-rpm-size.txt
done < $TMPDIR/$F-rpm.txt
echo "Total size: $SIZE"
}
ISOFROM=$1
ISOTO=$2
[ "$ISOFROM" -a "$ISOTO" ] || {
echo "Usage: $0 from.iso to.iso"
exit 1
}
[ -e "$ISOFROM" ] || {
echo "Error: file $ISOFROM does not exist; aborting."
exit 1
}
[ -e "$ISOTO" ] || {
echo "Error: file $ISOTO does not exist; aborting."
exit 1
}
umount $TMPDIR/from 2>/dev/null
umount $TMPDIR/to 2>/dev/null
umount $TMPDIR/isofrom 2>/dev/null
umount $TMPDIR/isoto 2>/dev/null
mkdir -p $TMPDIR/{isofrom,isoto,from,to}
mount -o loop $ISOFROM $TMPDIR/isofrom || {
echo "Error: cannot mount $ISOFROM; aborting."
exit 1
}
mount -o loop $ISOTO $TMPDIR/isoto || {
echo "Error: cannot mount $ISOTO; aborting."
umount $TMPDIR/isofrom
exit 1
}
mount -o loop $TMPDIR/isofrom/rootfs.compressed $TMPDIR/from || {
echo "Error: cannot mount compressed fs inside $ISOFROM; aborting."
umount $TMPDIR/isofrom
umount $TMPDIR/isoto
exit 1
}
mount -o loop $TMPDIR/isoto/rootfs.compressed $TMPDIR/to || {
echo "Error: cannot mount compressed fs inside $ISOTO; aborting."
umount $TMPDIR/from
umount $TMPDIR/isofrom
umount $TMPDIR/isoto
exit 1
}
create_count_files from
create_count_files to
> $TMPDIR/diff.txt
while read line; do
set -- $line
pkgname=$1
fromsize=$2
lineto=`grep "^$pkgname " $TMPDIR/to-rpm.txt 2>/dev/null`
[ "$lineto" ] && {
set -- $lineto
tosize=$2
} || tosize=0
diffsize=`expr $tosize - $fromsize`
[ $diffsize -ne 0 ] && {
percsize=`echo "scale=2; $diffsize * 100 / $fromsize" | bc` || percsize=0
echo -e "$pkgname ${tosize} ${fromsize} ${diffsize} ${percsize}" >> $TMPDIR/diff.txt
}
done < $TMPDIR/from-rpm.txt
while read line; do
set -- $line
pkgname=$1
tosize=$2
linefrom=`grep "^$pkgname " $TMPDIR/from-rpm.txt 2>/dev/null`
[ "$linefrom" ] && continue
echo -e "$pkgname $tosize 0 $tosize 100" >> $TMPDIR/diff.txt
done < $TMPDIR/to-rpm.txt
echo -e "Package\r\t\t\t\t\t N Diff (bytes)" > $TMPDIR/diff-growth.txt
echo "------------------------------------------------------------------------------------" >> $TMPDIR/diff-growth.txt
incr=0
cat $TMPDIR/diff.txt | sort -n -k 4 -r | while read line; do
set -- $line
[ ${3} -eq 0 ] && new="*" || new=" "
incr=`expr $incr + ${4}`
echo -e "$1\r\t\t\t\t\t ${new} ${4}\r\t\t\t\t\t\t\t (${5}%)\r\t\t\t\t\t\t\t\t\t $incr" >> $TMPDIR/diff-growth.txt
done
umount $TMPDIR/from
umount $TMPDIR/to
umount $TMPDIR/isofrom
umount $TMPDIR/isoto
exit 0