Use log_action, log_status in build-baseimage script

This commit is contained in:
Reto Buerki
2013-01-17 15:22:09 +01:00
committed by Tobias Brunner
parent c120f25e60
commit 9574bf7a5e
2 changed files with 21 additions and 10 deletions
-1
View File
@@ -35,7 +35,6 @@ fi
# #
if [ $ENABLE_BUILD_BASEIMAGE = "yes" ] if [ $ENABLE_BUILD_BASEIMAGE = "yes" ]
then then
cecho "Building base image"
$DIR/scripts/build-baseimage $DIR/scripts/build-baseimage
fi fi
+21 -9
View File
@@ -13,12 +13,17 @@ DIR=`dirname $0`
[ -f $DIR/../testing.conf ] || die "!! Configuration file 'testing.conf' not found" [ -f $DIR/../testing.conf ] || die "!! Configuration file 'testing.conf' not found"
. $DIR/../testing.conf . $DIR/../testing.conf
# execute command
# $1 - command to execute
# $2 - whether or not to log command exit status
# (0 -> disable exit status logging)
execute() execute()
{ {
cmd=${1} cmd=${1}
echo $cmd >>$LOGFILE echo $cmd >>$LOGFILE
$cmd >>$LOGFILE 2>&1 $cmd >>$LOGFILE 2>&1
status=$? status=$?
[ "$2" != 0 ] && log_status $status
if [ $status != 0 ]; then if [ $status != 0 ]; then
echo "! command $cmd failed, exiting (status $status)" echo "! command $cmd failed, exiting (status $status)"
echo "! check why here $LOGFILE" echo "! check why here $LOGFILE"
@@ -26,6 +31,8 @@ execute()
fi fi
} }
# execute command in chroot
# $1 - command to execute
execute_chroot() execute_chroot()
{ {
execute "chroot $LOOPDIR $@" execute "chroot $LOOPDIR $@"
@@ -44,28 +51,33 @@ mkdir -p $CACHEDIR
rm -f $ROOTFS rm -f $ROOTFS
echo "`date`, building $ROOTFS" >>$LOGFILE echo "`date`, building $ROOTFS" >>$LOGFILE
echo " * Creating sparse image $ROOTFS ..." echo "Building base image"
log_action "Creating image $ROOTFS"
execute "dd if=/dev/null of=$ROOTFS bs=1M seek=$ROOTFSSIZE count=1" execute "dd if=/dev/null of=$ROOTFS bs=1M seek=$ROOTFSSIZE count=1"
echo " * Creating ext3 filesystem ..."
log_action "Creating ext3 filesystem"
execute "mkfs.ext3 -F $ROOTFS" execute "mkfs.ext3 -F $ROOTFS"
log_action "Mounting image to $LOOPDIR"
execute "mount -o loop $ROOTFS $LOOPDIR" execute "mount -o loop $ROOTFS $LOOPDIR"
log_action "Mounting cache to $CACHEDIR"
mkdir -p $APTCACHE mkdir -p $APTCACHE
execute "mount -o bind $CACHEDIR $APTCACHE" execute "mount -o bind $CACHEDIR $APTCACHE"
echo " * Running debootstrap ..." log_action "Running debootstrap ($ROOTFSSUITE, $ROOTFSARCH)"
execute "debootstrap --arch=$ROOTFSARCH --include=$PACKAGES $ROOTFSSUITE $LOOPDIR $ROOTFSMIRROR" execute "debootstrap --arch=$ROOTFSARCH --include=$PACKAGES $ROOTFSSUITE $LOOPDIR $ROOTFSMIRROR"
echo " * Disabling root password ..." log_action "Disabling root password"
execute_chroot "passwd -d root" execute_chroot "passwd -d root"
echo " * Disabling services ..."
for service in $SERVICES for service in $SERVICES
do do
echo -n " - $service ... " log_action "Stopping service $service"
execute_chroot "/etc/init.d/$service stop" execute_chroot "/etc/init.d/$service stop"
log_action "Disabling service $service"
execute_chroot "update-rc.d -f $service remove" execute_chroot "update-rc.d -f $service remove"
echo "done"
done done
execute "umount -l $APTCACHE" execute "umount -l $APTCACHE" 0
execute "umount -l $LOOPDIR" execute "umount -l $LOOPDIR" 0