7ed720ee82
If version mismatch, rpm --rebuilddb will complain about some files, but is isn't critical, so just hide those messages. We still take care of exit code.
36 lines
728 B
Bash
Executable File
36 lines
728 B
Bash
Executable File
#!/bin/sh
|
|
|
|
IMG=$1
|
|
|
|
set -e
|
|
|
|
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
|
|
mount -o loop $IMG mnt || exit 1
|
|
INSTALLDIR=`pwd`/mnt/
|
|
rm -f $INSTALLDIR/var/lib/rpm/__db.00* $INSTALLDIR/var/lib/rpm/.rpm.lock
|
|
yum -c $PWD/yum.conf clean packages --installroot=$INSTALLDIR
|
|
|
|
# Make sure that rpm database has right format (for rpm version in template, not host)
|
|
echo "--> Rebuilding rpm database..."
|
|
chroot `pwd`/mnt /bin/rpm --rebuilddb 2> /dev/null
|
|
|
|
echo "--> Compacting image file..."
|
|
dd if=/dev/zero of=mnt/fillme bs=1M 2> /dev/null || true
|
|
sync
|
|
rm mnt/fillme
|
|
umount mnt
|
|
cp --sparse=always $IMG $IMG.new
|
|
mv $IMG.new $IMG
|
|
ls -als $IMG
|
|
|