# Copyright (C) 2002 Ensim Corporation. All Rights Reserved.
#

F_read_disk()
{
     echo ""
    
     $CAT $KSGENDIR/lib/data/disk.dat
     echo "" 
     _q_partition="n"
#     F_read_disksize
     F_read_swap
     echo ""
     F_ckyorn "y" "> Do you want to clear all partitions from the target machine ?"
    if [ $_q_yorn = "n" ]
    then
	_q_clear="n"
    else
        _q_clear="y"
    fi
    
     return
}

F_read_disksize()
{
    local _q_done="n"
    while [ "$_q_done" = "n" ]
    do
        echo ""
        echo -n "> Size of hard disk on the target machine [in GB] : "
	
        read _q_disksize

        _q_disksize=`echo $_q_disksize | $AWK '/^[0-9]+$/ {print}'`

        if [ X"$_q_disksize" = X"" ]
        then
            echo ""
            echo "*** Enter an Integer Value"
            continue
        else
	   if [ $_q_disksize -lt $ENSIM_MINDISKSIZE ]
	   then 
		echo ""
		echo "*** Hard Disk Size needs to be at least $ENSIM_MINDISKSIZE GB"
		echo ""
		continue

	    else
		_q_disksize=`expr $_q_disksize \* 1024 `
		_q_disksize=`expr $_q_disksize - $_q_maxswapsize - $_q_bootsize - $_q_rootsize`
		_q_size=`expr $_q_disksize \/ 2`
		break
	    fi 
	fi
    done	
}	

F_read_varsize()
{

	
    	local _q_done="n"
    	while [ "$_q_done" = "n" ]
    	do
        	echo ""
        	echo -n "> Max Size of [/var] partition you want [in MB] : "

        	read _q_maxvarsize

        	_q_maxvarsize=`echo $_q_maxvarsize | $AWK '/^[0-9]+$/ {print}'`
        	
		if [ X"$_q_maxvarsize" = X"" ]
        	then
			echo ""
            		echo "*** Enter an Integer Value"
            		echo ""
            		continue
		else 
			
        		if [ $_q_maxvarsize -gt $_q_size ] || [ $_q_maxvarsize -lt $_q_varsize ]
			then
				echo ""
            			echo "*** Max Size of [/var] should be less than $_q_size MB and greater than $_q_varsize MB ***" 
				echo ""
            			continue
        		else
            			break
        		fi
		 fi 
    	done
}


F_read_swap()
{

    local _q_done="n"
    while [ "$_q_done" = "n" ]
    do
        echo ""
        echo -n "> Max Size of swap partition you want [in MB] : "

        read _q_maxswapsize

        _q_maxswapsize=`echo $_q_maxswapsize | $AWK '/^[0-9]+$/ {print}'`

        if [ X"$_q_maxswapsize" = X"" ]
        then
			echo ""
            		echo "*** Enter an Integer Value"
            		echo ""
            		continue
        else     		
        	if [ $_q_maxswapsize -lt $_q_swapsize ]
		then		
			echo ""
        		echo "*** Max Value of Swap Size should be greater than $_q_swapsize ***" 
			echo ""
               		continue
        	else
            		break
		fi
        fi
    done
}
F_read_bootloader()
{
	echo ""
	echo "> Please select the bootloader that the computer will use."
	echo "  [1] Use GRUB as the bootloader."
	echo "  [2] Use LILO as the bootloader."
	echo ""

_q_done_boot="n"
while [ $_q_done_boot = "n" ]
do
    echo -n "Please enter the number corresponding to your choice: "
    read _q_whichopt
    _q_whichopt=`echo $_q_whichopt | $AWK '/^[0-9]+$/ {print}'`
    case X"$_q_whichopt" in
    X"1")
        _q_done_boot="y"
		_q_boot="y"
	echo "> Boot Loader Password Configuration:"
	echo ""
	echo "A bootloader password prevents the user from sending arbitrary "	
	echo "options to the kernel .For highest security we recommend setting a password. "
	echo ""
     	F_ckyorn "y" "> Use a GRUB password ?"
    	if [ $_q_yorn = "y" ]
    	then
		stty -echo
		F_grub_passwd
		stty echo
		echo ""
    	fi
	;;
    X"2")
        _q_done_boot="y"
		_q_boot="n"	
	;;
    X*)
	;;
esac
done	

}
F_read_CD()
{
    local _q_finish="n"
	echo "Using CD-ROM mount point /mnt/cdrom/"
	/bin/umount /mnt/cdrom 2>>/dev/null
	echo "Unmounting CDROM"
    echo ""
	echo "Please insert the Ensim WEBppliance Pro CD in the CD-ROM drive"

    	while [ "$_q_finish" = "n" ]
		do
		/usr/bin/eject
		echo -n "Press <ENTER> to continue, or ^C to abort."
		read _q_anykey
		echo "mounting CDROM"
		/bin/mount /mnt/cdrom
		if [ $? != 0 ]
		then
 	 		echo "failed to mount the cdrom "
			echo ""
      		echo "Please insert the correct CD in the CD-ROM drive."
			echo -n "Press <ENTER> to continue, or ^C to abort."
			echo ""
		 	continue
		fi
			
		echo "Identifying whether the CD is correct ..."
		echo ""
			if [ -d /mnt/cdrom/OSI/$OSI_version/$OSI_release ]
			then
				echo "Copying the required data. This may take a few minutes..."
				cp -rf /mnt/cdrom/OSI $KSGENDIR/lib/data
					if [ $? == 0 ]
					then 	
						_q_finish="y"
						echo ""
					else
						echo "error copying files"
						echo ""
						return 1
					fi
			else
      					echo "Please insert the correct CD in the CD-ROM drive."
						echo -n "Press <ENTER> to continue, or ^C to abort."
						echo ""
						continue
			fi	
    	
    done
    return 0	
}
# __END__
