

if [ "${g20s_install}" = "" ]
then
    g20s_install="yes"
    g10s_LIBFILE=${g10s_LIBFILE="../globalLib/g10s_pub"}
    if [ -f "${g10s_LIBFILE}" ]
    then
        G10S_CUR_DIR="${g10s_LIBFILE}"
        . "${g10s_LIBFILE}"
    else
        fileFlag="g20s"
    	echo -e "\033[31m[ERROR:15][${fileFlag}][`date +%Y%m%d%H%M%S`][$0,${FUNCNAME[1]},${BASH_LINENO[0]}] not found the lib[${g10s_LIBFILE}]\033[0m"
    	eval "${g10s_exitFun} 1"
    fi
    
    
    g20s_unistallSolution="${g10s_bakPath}/g20s_unistall.solution"
    g20s_installSolution="/UltraPath/install/t70s_install.solution.bak"
    g20s_installServiceLabel="60_mkBootService"
    

    g20s_installConfig=${g20s_installConfig:="${g10s_bakPath}/g20s_install.config"}
    

    g20s_isKernelSupport=""
    

    readonly g20s_installSolutionTmp="${g10s_tmpPath}/t20s_install.solution.tmp.$$"
    
    g20s_installScript=""
    function g20s_getExecuteScript()
    {
        if [ ! -f "${g20s_installSolution}" ]
        then
            print_debug "Install Solution is not exit." "g20s"
            return 1
        fi
        g20s_installScript=`grep "^${g20s_installServiceLabel}" "${g20s_installSolution}" | awk '{print $2}'`
        if [ "${g20s_installScript}" = "" ]
        then
            print_debug "Execute Script is not exit.[${g20s_installServiceLabel}]" "g20s"
            return 1
        fi
        return 0
    }
    
    G20S_SERV_PATH_NAME=""
    function g20s_get_serv_path_name()
    {
        G20S_SERV_PATH_NAME=""
        local solution_str=""
        
        if [ ! -f "${g20s_installSolution}" ]
        then
            print_debug "Install Solution is not exit." "g20s"
            return 1
        fi
        
        solution_str=$(grep "^${g20s_installServiceLabel}" "${g20s_installSolution}" | awk -F "==" '{print $4}')
        if [ $(echo "${solution_str}" | grep -c "[[:blank:]]servPathName=") -eq 0 ]
        then
            return 0
        fi
 
        G20S_SERV_PATH_NAME=${solution_str##*servPathName=}
        G20S_SERV_PATH_NAME=${G20S_SERV_PATH_NAME%% *}
        G20S_SERV_PATH_NAME=$(echo ${G20S_SERV_PATH_NAME})
        return 0       
    }
    
    g20s_repairSolution=""
    function g20s_repairService()
    {
        g20s_getExecuteScript
        if [ $? -ne 0 ]
        then
            return 0
        fi
        
        g20s_get_serv_path_name
        if [ $? -ne 0 ]
        then
            return 0
        fi

        if [ X"${G20S_SERV_PATH_NAME}" != "X" ]
        then
            g20s_repairSolution="999_mkBootService==shell==/UltraPath/install/linuxTools/toolLib/==bash "${g20s_installScript}" \
            servPathName=/UltraPath/install/linuxTools/toolLib/t160s_boot.ultrapath type=normal action=repair"
        else
            g20s_repairSolution="999_mkBootService==shell==/UltraPath/install/linuxTools/toolLib/==bash "${g20s_installScript}" \
            type=normal action=repair"
        fi

        g20s_excuteInstallAction "${g20s_repairSolution}" 
    }


    function g20s_excuteInstallAction()
    {
        local linemsg
        local installType
        local installDir
        local installShell
        local pwdPath

        if [ "$1" = "" ]
        then
            print_error "2" "param error.[g20s_excuteInstallAction]" "g20s"
            eval "${g10s_exitFun} 1"
        fi
        linemsg="$1"
        installType=`echo "${linemsg}"|awk -F "==" '{print $2}'`
        installDir=`echo "${linemsg}"|awk -F "==" '{print $3}'`
        installShell=`echo "${linemsg}"|awk -F "==" '{print $4}'`
        
        print_debug "install action:${actionID}==${installType}==${installDir}==${installShell}" "g20s"
        g10s_debugPoint "install_${actionID}"

        if [ "${installType}" = "shell" ]
        then
            pwdPath=`pwd`
            if [ ! -d "${installDir}" ]
            then
                print_error "1001" "directory is not exist[${installDir}]" "g20s"
                eval "${g10s_exitFun} 1"
            fi
            cd "${installDir}"
            eval "${installShell}"
            if [ $? -ne 0 ]
            then
            	print_error "1002" "action execute failed[${installDir},${installShell}]" "g20s"
            	eval "${g10s_exitFun} 1"
            fi
            cd "${pwdPath}"
        elif [ "${installType}" = "skip" ]
        then
            print_debug "skip install action[${actionID}]" "g20s"
        else
            print_error "1003" "format error for action[${actionID}]" "g20s"
            eval "${g10s_exitFun} 1"
        fi
        return 0
    }
    

    function g20s_appendUninstallAction()
    {
        if [ "$1" = "" ] || [ "$2" = "" ] || [ "$3" = "" ] || [ "$4" = "" ]
        then
            print_error "2" "param error." "g20s"
            eval "${g10s_exitFun} 1"
        fi
        g10s_checkExist -f "${g20s_unistallSolution}" 2
        if [ `grep -c "^[[:blank:]]*${1}==" "${g20s_unistallSolution}"` -eq 0 ]
        then
            if [ "$1" = "40_mkImage" ]
            then
                sed -i "/^30_modifyMkinitrd==/i \
                ${1}==${2}==${3}==${4}" "${g20s_unistallSolution}"
            else
                echo "${1}==${2}==${3}==${4}">>"${g20s_unistallSolution}"
            fi
        fi
        return 0
    }
    

    function g20s_appendUninstallByLine()
    {
        local linemsg=""
        local actionID=""
        local uninstallType=""
        local uninstallDir=""
        local uninstallShell=""
        if [ "$1" = "" ]
        then
            print_error "2" "param error." "g20s"
            eval "${g10s_exitFun} 1"
        fi
        linemsg="$1"
        actionID=`echo "${linemsg}"|awk -F "==" '{print $1}'`
        uninstallType=`echo "${linemsg}"|awk -F "==" '{print $5}'`
        uninstallDir=`echo "${linemsg}"|awk -F "==" '{print $6}'`
        uninstallShell=`echo "${linemsg}"|awk -F "==" '{print $7}'`
        

        if [ "${uninstallType}" != "skip" ] && [ "${uninstallType}" != "shell" ]
        then
            print_error "1004" "unknown uninstallType[${uninstallType}]" "g20s"
            eval "${g10s_exitFun} 1"
        fi
        if [ "${uninstallDir}" != "NULL" ] && [ ! -d "${uninstallDir}" ]
        then
            print_error "1005" "not found directory[${uninstallDir}]" "g20s"
            eval "${g10s_exitFun} 1"
        fi
        g20s_appendUninstallAction "${actionID}" "${uninstallType}" "${uninstallDir}" "${uninstallShell}"
        return 0
    }
   

    function g20s_installBySolution()
    {
        local i
        local lineCount
        local linemsg
        local actionID

        if [ "$1" = "" ]
        then
           print_error "2" "param error." "g20s"
           eval "${g10s_exitFun} 1"
        fi
        g10s_checkExist -f "$1" 2
        g10s_removeBlank "${1}" "${g20s_installSolutionTmp}"
        
        rm -rf "${g20s_unistallSolution}" 2>/dev/null
        touch "${g20s_unistallSolution}"

        lineCount=`cat "${g20s_installSolutionTmp}"|wc -l`
        for ((i=1; i<=${lineCount}; i++))
        do
            linemsg=`cat "${g20s_installSolutionTmp}"|sed -n "${i}p"`
            if [ `echo "${linemsg}"|grep -c "^[[:blank:]]*$"` -ne 0 ]
            then
                continue
            fi
           

            actionID=`echo "${linemsg}"|awk -F "==" '{print $1}'`
            if [ -f "${g20s_installConfig}" ]
            then
                if [ `cat "${g20s_installConfig}"|grep -c "^${actionID}=="` -ne 0 ]
                then
                    linemsg=`cat "${g20s_installConfig}"|grep "^${actionID}=="|tail -n 1`
                    print_event "1006" "used user config[${linemsg}]" "g20s"
                fi
            fi

            g20s_appendUninstallByLine "${linemsg}"
            
            g20s_excuteInstallAction "${linemsg}" 
        done
        rm -rf "${g20s_installSolutionTmp}"
        echo "">>"${g20s_unistallSolution}"
        return 0
    }
    



    g20s_forceUninstall=${g20s_forceUninstall:="0"}
    g20s_doActionIDs=""
    function g20s_uninstallBySolution() 
    {
        local lineCount=0
        local linemsg
        local linenum
        local actionID
        local isNeedDo
        local tmpAction
        local uninstallType
        local uninstallDir
        local uninstallShell
        local pwdPath
        local curdate
        
        if [ ! -f "${g20s_unistallSolution}" ]
        then
            print_warning "1007" "uninstall solution is not exist[${g20s_unistallSolution}]" "g20s"

            g20s_doActionIDs=""
            if [ "${g20s_forceUninstall}" != "1" ]
            then
                eval "${g10s_exitFun} 1"
            else
                return 0
            fi
        fi
        

        lineCount=`cat "${g20s_unistallSolution}"|wc -l`
        for ((i=0; i<${lineCount}; i++))
        do
            let "linenum=${lineCount} - ${i}"
            linemsg=`cat "${g20s_unistallSolution}"|sed -n "${linenum}p"`
            if [ `echo "${linemsg}"|grep -E -c "(^[[:blank:]]*$|^[[:blank:]]*#)"` -eq 1 ]
            then
                continue
            fi
            
            actionID=`echo "${linemsg}"|awk -F "==" '{print $1}'`
            isNeedDo="1"
            if [ ${#g20s_doActionIDs[@]} -ne 0 ]
            then
                for tmpAction in "${g20s_doActionIDs[@]}"
                do
                    if [ "${tmpAction}" = "" ]
                    then
                        continue
                    fi
                    if [ `echo "${actionID}"|grep -c "^[[:blank:]]*${tmpAction}[[:blank:]]*$"` -ne 0 ]
                    then
                        isNeedDo="1" 
                        break
                    fi

                    isNeedDo="0"
                done
            fi
            
            if [ "${isNeedDo}" = "0" ]
            then
                continue
            fi
    		
    	    uninstallType=`echo "${linemsg}"|awk -F "==" '{print $2}'`
    	    uninstallDir=`echo "${linemsg}"|awk -F "==" '{print $3}'`
    	    uninstallShell=`echo "${linemsg}"|awk -F "==" '{print $4}'`
    	    print_debug "uninstall action:${actionID}==${uninstallType}==${uninstallDir}==${uninstallShell}" "g20s"
    	    g10s_debugPoint "uninstall_${actionID}"
    	    if [ "${uninstallType}" = "shell" ]
            then
            	pwdPath=`pwd`
            	if [ ! -d "${uninstallDir}" ]
            	then
            	    print_error "1008" "directory is not exist[${uninstallDir}]" "g20s"
            	    if [ "${g20s_forceUninstall}" != "1" ]
                    then
                        eval "${g10s_exitFun} 1"
                    else
                        continue
                    fi
                fi
            	cd "${uninstallDir}"
            	eval "${uninstallShell}"
            	if [ $? -ne 0 ]
            	then
            	    print_error "1009" "action execute failed[${uninstallDir},${uninstallShell}]" "g20s"
            	    cd "${pwdPath}"
            	    if [ "${g20s_forceUninstall}" != "1" ]
                    then
                        eval "${g10s_exitFun} 1"
                    else
                        continue
                    fi
            	fi
            	cd "${pwdPath}"
            elif [ "${uninstallType}" = "skip" ]
            then
                print_debug "skip uninstall action[${actionID}]" "g20s"
            else
                print_error "1010" "format error for action[${actionID}]" "g20s"
                if [ "${g20s_forceUninstall}" != "1" ]
                then
                    eval "${g10s_exitFun} 1"
                else
                    continue
                fi
            fi

    	    curdate=`date +%Y%m%d%H%M%S`
    	    sed -i "/^[[:blank:]]*${actionID}/s/^\(.*\)$/###${curdate}###\1/g" "${g20s_unistallSolution}"
    	done
    	g20s_doActionIDs=""
    	return 0
    }
    
    readonly  g20s_modulesBaseDir="`cd ../../;pwd`/kernelModules"
    readonly  g20s_installConf="../globalLib/g20c_installConf/g20c_install.conf"    
    

    g20s_actionList=""
    function g20s_getActionListBySystem()
    {
        g20s_actionList=""
        
        g10s_getOSType
        g10s_getSysBit
        if [ "${G10S_CUR_MODE}" != "" ] && [ -f "../globalLib/g20c_installConf/${G10S_CUR_MODE}" ]; then
            g20s_actionList="${G10S_CUR_MODE}"
            print_debug "G10S_CUR_MODE=${G10S_CUR_MODE},g20s_actionList=${g20s_actionList}" "g20s"
        else
            g10s_checkExist -f "${g20s_installConf}" 2
            sed -i 's/\r//' "${g20s_installConf}"
            g20s_actionList=$(cat "${g20s_installConf}" | grep "^[[:blank:]]*${g10s_OSVersion}_${g10s_kernelType}_${g10s_sysbit}[[:blank:]]*=="|awk -F "==" '{print $3}')
            print_debug "g20s_installConf=${g20s_installConf},g20s_actionList=${g20s_actionList}" "g20s"
        fi
        ret=$(echo "${g20s_actionList}" | grep -v "^[[:blank:]]*$" | wc -l)
        if [ ${ret} -eq 0 ]
        then
            print_error "1016" "not found install solution for this kernel.[${g10s_OSVersion}_${g10s_kernelType}_${g10s_sysbit}]" "g20s"
            eval "${g10s_exitFun} 1"
        elif [ ${ret} -eq 1 ]
        then
            g20s_actionList="../globalLib/g20c_installConf/${g20s_actionList}"

        	g10s_checkExist -f "${g20s_actionList}" 2
            return 0
        else
            print_error "1017" "there's repeat config.[${g10s_OSVersion}_${g10s_kernelType}_${g10s_sysbit},map:${g20s_installConf}]" "g20s"
            eval "${g10s_exitFun} 1"
        fi 
        return 0
    }
    
    function g20s_echoAttention()
    {
        echo "******************************Attention******************************
* UltraPath can not support more than one types of HBA conneting to *
* storages, please make sure only one type will be in use.          *
*********************************************************************"
    }
    
else
    print_debug "g20s_install is in this shell." "g20s"
fi

