#! /bin/sh 

work_as_net_inst_server(){
    cp -a /usr/lib/net_inst_server/{exports,dhcpd.conf} /etc/
    cp -a /usr/lib/net_inst_server/tftpd-hpa /etc/default/
    ifconfig eth0 145.16.3.254
    /etc/init.d/portmap start
    /etc/init.d/nfsserver start
    /etc/init.d/tftpd-hpa start
    /etc/init.d/dhcp start
}

activate_dmraid(){
    modprobe dm_mod
    /usr/sbin/dmsetup remove_all
    dmraid -p -ay
    for i in $(dmraid -s -c);do
        kpartx -a /dev/mapper/$i
    done
}

dmraid=`cat /proc/cmdline | sed 's/.*dmraid=\([^ ]*\).*/\1/'`
os=`cat /proc/cmdline | sed 's/.*os=\([^ ]*\).*/\1/'`

if [ "$(echo $dmraid |tr '[A-Z]' '[a-z]')" = "true" ];then
    activate_dmraid
fi

#instmode=`cat /proc/cmdline | sed 's/.*instmode=\([^ ]*\).*/\1/'`
source /usr/lib/new_install/text/get_instmode.sh

#检查是否存在硬盘安装的自动安装配置文件，有则根据配置文件自动安装。
if [ -s /hdautoconf/autoinstall.xml ] ; then
    mkdir -vp /var/install/
    cp /hdautoconf/autoinstall.xml /var/install/install.xml
    cd /usr/lib/new_install/text
    /usr/bin/python ../interface/ri_install.py
fi

if [ $instmode = 'Auto' ];then
    mkdir -pv /var/install/
    cp /usr/lib/new_install/xml/install.xml /var/install/install.xml
elif  [ $instmode = 'StateGrid' ];then
    mkdir -pv /var/install/
    if [ $os = '40' ];then
    	cp /usr/lib/new_install/xml/install-40-d5000.xml /var/install/install.xml
    else
    	cp /usr/lib/new_install/xml/install-d5000.xml /var/install/install.xml
    fi
fi

case $instmode in			
	Auto)
		cd /usr/lib/new_install/text
		/usr/bin/python ./auto_install.py ;;
	Text)
		/usr/bin/setup -s ;;
	StateGrid)
		cd /usr/lib/new_install/text
		/usr/bin/python ./state_grid.py
		/usr/bin/python ./auto_install.py ;;
	Gui)	
		/usr/bin/setup -s ;;
	NetInstallServer)	
		work_as_net_inst_server ;;
	Cancel)	
		clear
		exit ;;
	*)	
		echo "unknown select" ;;
esac

