#!/bin/bash
#
#	DESCRIPTION:	copying kernel and modules to system
#
#	SCRIPT NAME:	copy_kernel.sh
#
#	Input:	stdin
#			NULL
#
#	Output:	
#			NULL
#	Return value:
#			1 kernel directory/modules directory/initrd.gz/makeinitrd doesn't exist
#
#	AUTHOR:		Qin Bo
#
#	EMAIL:		bqin@linx-info.com
#
#	DATE:		2010-08-23
#
#	HISTORY:
#	REVISOR		DATE			MODIFICATION
#	Qin Bo		2010-08-23		create
#
#
#

source ./functions

set -x

main ()
{
	
	info "copy $MODULES/* to $TARGET/lib/modules/"
	if [ -d "$MODULES" ];then
		cp -r "$MODULES"/* "$TARGET/lib/modules/"  2>>$DEV_LOG
	else
		err "$MODULES directory doesn't exist "
		exit 1
	fi

	case `uname -m` in 
	    x86_64 | i686)
        info "copy $KERNELS/* to $TARGET/boot/"

        if [ -d "$KERNELS" ];then
            #cp -r "$KERNELS"/*	"$TARGET/boot/" 2>>$DEV_LOG
			cp -r "$KERNELS"/System*   "$TARGET/boot/" 2>>$DEV_LOG
			cp $KERNELS/vmlinuz-root  $TARGET/boot/vmlinuz-2.6.32.41-Rocky4.2-x86_64-root
			cp $KERNELS/vmlinuz-root-n  $TARGET/boot/vmlinuz-2.6.32.41-Rocky4.2-x86_64-nroot
			cp $KERNELS/vmlinuz-root-n-nocgroup $TARGET/boot/vmlinuz-2.6.32.41-Rocky4.2-x86_64-nocgroup-root
			cp $KERNELS/vmlinuz-root-nocgroup $TARGET/boot/vmlinuz-2.6.32.41-Rocky4.2-x86_64-nocgroup-nroot
        else
            err "$KERNELS directory doesn't exist "
            exit 1
        fi

		#info "copy $INITRD/initrd-full-cgroup.gz to $TARGET/boot/initrd-full-cgroup.gz and copy $INITRD/initrd-full-nocgroup.gz to $TARGET/boot/initrd-full-nocgroup.gz"
		#if [ -e "$INITRD/initrd-full-cgroup.gz" -a -e "$INITRD/initrd-full-nocgroup.gz" ];then
		#	cp "$INITRD/initrd-full-cgroup.gz" "$TARGET/boot/initrd-full-cgroup.gz" 2>>$DEV_LOG
 		#        cp "$INITRD/initrd-full-nocgroup.gz" "$TARGET/boot/initrd-full-nocgroup.gz" 2>>$DEV_LOG
		#else
		#	err "$INITRD/initrd-full-cgroup.gz or $INITRD/initrd-full-nocgroup.gz doesn't exist "
		#	exit 1
		#fi

	info "copy $INITRD/initrd-full.gz to $TARGET/boot/initrd.gz"
	if [ -e "$INITRD/initrd-full-cgroup.gz" -a -e "$INITRD/initrd-full-cgroup.gz" ];then
		cp "$INITRD/initrd-full-cgroup.gz" "$TARGET/boot/initrd.img-2.6.32.41-Rocky4.2-x86_64-root" 2>>$DEV_LOG
		cp "$INITRD/initrd-full-cgroup.gz" "$TARGET/boot/initrd.img-2.6.32.41-Rocky4.2-x86_64-nroot" 2>>$DEV_LOG
		cp "$INITRD/initrd-full-nocgroup.gz" "$TARGET/boot/initrd.img-2.6.32.41-Rocky4.2-x86_64-nocgroup-root" 2>>$DEV_LOG
		cp "$INITRD/initrd-full-nocgroup.gz" "$TARGET/boot/initrd.img-2.6.32.41-Rocky4.2-x86_64-nocgroup-nroot" 2>>$DEV_LOG
	else
		err "$INITRD/initrd-full-cgroup.gz doesn't exist "
		exit 1
	fi
        
        info "copy $FIRMWARE to $TARGET/lib/"
        if [ -d $FIRMWARE ];then
            cp -r "$FIRMWARE" $TARGET/lib/
        fi

		;;
	    ia64)
        info "copy $KERNELS/* to /tmp/tmppoint"
        if [ -d "$KERNELS" ];then
            cp -r "$KERNELS"/*	"/tmp/tmppoint/" 2>>$DEV_LOG
        else
            err "$KERNELS directory doesn't exist "
            exit 1
        fi

        info "copy $FIRMWARE to $TARGET/lib/"
        if [ -d $FIRMWARE ];then
            cp -r "$FIRMWARE" $TARGET/lib/
        fi
	   	;;
	   *)
	   	err "architecture is not allowing"
		exit 1
		;;
	esac
}

KERNELS="/Rocky/kernels"
MODULES="/Rocky/modules"
FIRMWARE="/Rocky/firmware"
INITRD="/Rocky/initrd"

main "$@"

