2010-09-17 16:08:12 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
IMG=$1
|
|
|
|
|
2012-01-03 21:33:20 +00:00
|
|
|
set -e
|
|
|
|
|
2010-09-17 16:08:12 +00:00
|
|
|
if ! [ $# -eq 1 ]; then
|
|
|
|
echo "usage $0 <img_file_name>"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
if ! [ -f $IMG ]; then
|
|
|
|
echo $IMG does not exist
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
ls -als $IMG
|
2011-03-19 02:30:23 +00:00
|
|
|
mount -o loop $IMG mnt || exit 1
|
2010-09-17 16:08:12 +00:00
|
|
|
INSTALLDIR=`pwd`/mnt/
|
2012-06-06 00:54:10 +00:00
|
|
|
rm -f $INSTALLDIR/var/lib/rpm/__db.00* $INSTALLDIR/var/lib/rpm/.rpm.lock
|
2011-11-09 16:14:09 +00:00
|
|
|
yum -c $PWD/yum.conf clean packages --installroot=$INSTALLDIR
|
2012-01-03 21:33:20 +00:00
|
|
|
|
|
|
|
# Make sure that rpm database has right format (for rpm version in template, not host)
|
|
|
|
echo "--> Rebuilding rpm database..."
|
2012-06-26 01:38:10 +00:00
|
|
|
chroot `pwd`/mnt /bin/rpm --rebuilddb 2> /dev/null
|
2012-01-03 21:33:20 +00:00
|
|
|
|
2012-06-06 00:54:10 +00:00
|
|
|
echo "--> Compacting image file..."
|
|
|
|
dd if=/dev/zero of=mnt/fillme bs=1M 2> /dev/null || true
|
2010-09-17 16:08:12 +00:00
|
|
|
sync
|
|
|
|
rm mnt/fillme
|
|
|
|
umount mnt
|
|
|
|
cp --sparse=always $IMG $IMG.new
|
|
|
|
mv $IMG.new $IMG
|
|
|
|
ls -als $IMG
|
|
|
|
|