#!/bin/bash
#================
# FILE          : preinit
#----------------
# PROJECT       : OpenSuSE KIWI Image System
# COPYRIGHT     : (c) 2006 SUSE LINUX Products GmbH. All rights reserved
#               :
# AUTHOR        : Marcus Schaefer <ms@suse.de>
#               :
# BELONGS TO    : Operating System images
#               :
# DESCRIPTION   : This file is called after the image root
#               : has changed by the linuxrc script
#               :
# STATUS        : BETA
#----------------
#======================================
# Functions...
#--------------------------------------
. /include

#======================================
# 1) start error log
#--------------------------------------
Echo "Calling pre-init stage in system image"
errorLogStart

#======================================
# 2) check for LOCAL_BOOT
#--------------------------------------
if [ $LOCAL_BOOT = "yes" ];then
	exit 0
fi

#======================================
# 3) update mount table
#--------------------------------------
updateMTAB

#======================================
# 4) create framebuffer devices
#--------------------------------------
createFramebufferDevices

#======================================
# 5) check for union filesystem
#--------------------------------------
if [ ! -z "$UNIONFS_CONFIG" ]; then
	# /.../
	# we are using a special root setup with aufs. In this case
	# we can't use the SuSE Linux initrd but must stick to the
	# kiwi boot system.
	# ----
	updateMTAB
	rm -f /boot/initrd  && ln -s /boot/initrd.vmx /boot/initrd
	rm -f /boot/vmlinuz && ln -s /boot/linux.vmx  /boot/vmlinuz
	exit 0
fi

#======================================
# 6) create initrd on diskful
#--------------------------------------
setupSUSEInitrd

#======================================
# 7) Install boot loader on diskful
#--------------------------------------
if [ $bootLoaderOK = 1 ];then
	installBootLoader
fi

#======================================
# 8) create /etc/ImagePackages
#--------------------------------------
if [ -x /bin/rpm ];then
	Echo "Creating initial image package info file"
	rpm -qa --last > /etc/ImagePackages
fi
