#!/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) check for LOCAL_BOOT
#--------------------------------------
if [ $LOCAL_BOOT = "yes" ];then
	exit 0
fi

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

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

#======================================
# 4) create initrd on diskful
#--------------------------------------
if [ -z "$UNIONFS_CONFIG" ]; then
	#======================================
	# use distro initrd via mkinitrd
	#--------------------------------------
	setupSUSEInitrd
else
	#======================================
	# use kiwi initrd from boot partition
	#--------------------------------------
	if mount $deviceBoot /kiwiboot;then
		rm -rf /boot && ln -s /kiwiboot/boot /boot
		pushd /boot &>/dev/null
		rm -f vmlinuz && ln -s linux.vmx  vmlinuz
		rm -f initrd  && ln -s initrd.vmx initrd
		popd &>/dev/null
		setupBootLoaderGrub / / 0 ${deviceDisk}1 OEM
	else
		Echo "Failed to mount boot partition"
		Echo "Can't create grub configuration"
		grubOK=0
	fi
fi

#======================================
# 5) Install boot loader if ok
#--------------------------------------
if [ $grubOK = 1 ];then
	installBootLoaderGrub
fi
