#!/bin/bash

efimode=`cat /proc/cmdline | sed 's/.*efimode=\([^ ]*\).*/\1/'`
upgrubcmd="/usr/sbin/update-grub"
source ./functions

if [ $efimode == "y" ];then
	
	efi_dir="/Rocky/boot-efi"
	
	mkdir -p $TARGET/boot/efi/efi/boot
	
	cp ${efi_dir}/bootx64.efi $TARGET/boot/efi/efi/boot
	
	cp -r ${efi_dir}/x86_64-efi $TARGET/boot/efi/efi/boot
	
	cp $TARGET/boot/grub/grub.cfg $TARGET/boot/efi/efi/boot/x86_64-efi	

	#echo 'exec grub-mkconfig -o /boot/efi/efi/boot/x86_64-efi/grub.cfg $@ ' >> $TARGET/$upgrubcmd

	sed -i 's/\/boot\/grub\/grub.cfg/\/boot\/efi\/efi\/boot\/x86_64-efi\/grub.cfg/'	$TARGET/$upgrubcmd

	ln -snf /boot/efi/efi/boot/x86_64-efi/grub.cfg $TARGET/boot/grub/grub.cfg
	
	echo -e "Install efi successfully !"
else

	mkdir $TARGET/opt/fbdev
	mv $TARGET/usr/lib64/xorg/modules/drivers/fbdev_drv.la  $TARGET/opt/fbdev
	mv $TARGET/usr/lib64/xorg/modules/drivers/fbdev_drv.so  $TARGET/opt/fbdev
	sed -i "s/fbdev/vesa/g" $TARGET/etc/X11/xorg.conf

	echo -e "not efi mode !"
fi
