当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 1 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : [问题]shell问题,求助
帖子发表于 : 2008-04-02 23:44 

注册: 2006-09-30 12:20
帖子: 9
送出感谢: 0 次
接收感谢: 0 次
这段脚本什么意思,大概的function就行。


代码:
#!/bin/bash

#input_file: first string started with digitalnum or alpha character
#test_mode: -t/-T is found
#deliver_mode: -d/-D is found
input_file="";
test_mode="-F";
deliver_mode="-F";


############################################################################################
####                         Global parameters definition                               ####
############################################################################################
#The following are casual problems in delivery.
declare delivery_err1="No LABEL on include file";
declare delivery_err2="Wrong label";
declare delivery_err3="please update your version and deliver";
declare delivery_err4="please contact with SWE";
declare delivery_err5="Wrong DMD chosed";
declare delivery_err6="Wrong version of CHILLMX tool is used";
declare delivery_err7="No CHILL source file";
declare delivery_err8="Error during compilation";
declare delivery_err9="No source file";
declare delivery_err10="Error during compilation";
declare delivery_err11="No C source file";
declare delivery_err12="No CHILL CFG file";
declare delivery_err13="No label on include file";
declare delivery_err14="Wrong";

#constant global variables
declare view_root="/view";
declare tools_home="/vobs/Tools/BBS/Linux";
declare module_delivery="$tools_home/module_delivery";
declare output_sum_file_postfix="summary.deli";
declare module_list_file_postfix="module_list.deli";
declare valid_module_list_file_postfix="module_list_valid.deli";
declare delivery_log_file_postfix="complete_log.deli";
declare module_log_file_postfix="module_log.deli";
declare module_conf_file_postfix="module_conf.deli";

#The following global variables will be updated later according the delivery configuration file
#All tmp files related to this delivery are stored in the $HOME/delivery directory
declare delivery_home="/vobs/g2bsc/obj/Linux/delivery";
declare src_dir="/vobs/g2bsc/src/telecom";
declare pkg_name="AZ15B_INV";
declare output_sum_file="$delivery_home/$pkg_name.$output_sum_file_postfix";
declare module_list_file="$delivery_home/$pkg_name.$module_list_file_postfix";
declare valid_module_list_file="$delivery_home/$pkg_name.$valid_module_list_file_postfix";
declare delivery_log_file="$delivery_home/$pkg_name.$delivery_log_file_postfix";
declare module_log_file="$delivery_home/$pkg_name.module_name.$module_log_file_postfix";
declare module_conf_file="$delivery_home/$pkg_name.module_name.$module_conf_file_postfix";

#globally used parameter
declare merge_option_line="Y;N;Y";
declare src_dir_valid=0;
declare parse_one_module_result_valid=0;
declare updated_total_steps=0;
declare change_working_dir_valid=0;
declare error_indication=0;


############################################################################################
####                                Functions definition                                ####
############################################################################################
#transform the merge requirement. If merge is needed, then it is "Y"; Otherwise, it is "N"
#two input parameters are needed for this function
#$1 is the original modules delivery input file
#$2 is the module name to be delivered
merge_option()
{     
     #$1: modules delivery input file
     _input_file=$1;
     #$2: package name
     _pkg_name=$2;
     #$3: module name
     _module_name=$3;
     
     _module_log_file="$delivery_home/$_pkg_name.$_module_name.$module_log_file_postfix";
     if [ "$test_mode" = "-T" ]
     then
         echo "Enter merge_option() to get and transform the merge requirement......."|tee -a "$_module_log_file";
         echo "Input file(1st param) is: $_input_file. The package name(2nd param) is: $_pkg_name. The module name(3rd param) is:$_module_name."|tee -a "$_module_log_file";
     fi
     
     #We need firstly retrieve the delivery requirement from the server
     # Check merged issue
     roadmap=`echo "$tools_home/roadmap.txt"`
     _original_pkg_name=`echo "$_pkg_name"|sed 's/_/\//'`;
     _merge_option_1=`grep -i ^$_original_pkg_name, "$roadmap"| cut -f4 -d,|tr '[abcdefghijklmnopqrstuvwxyz]' '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]'`
     _merge_option_2=`grep -i ^$_original_pkg_name, "$roadmap" | cut -f5 -d,|tr '[abcdefghijklmnopqrstuvwxyz]' '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]'`
     _merge_option_3=`grep -i ^$_original_pkg_name, "$roadmap" | cut -f6 -d,|tr '[abcdefghijklmnopqrstuvwxyz]' '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]'`
     _merge_option_3=`grep -i ^$_original_pkg_name, "$roadmap" | cut -f6 -d,|tr '[abcdefghijklmnopqrstuvwxyz]' '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]'`
     
     if [ "$test_mode" = "-T" ]
     then
         echo "_merge_option_1: $_merge_option_1; _merge_option_2: $_merge_option_2; _merge_option_3: $_merge_option_3"|tee -a "$_module_log_file";
     fi
     
     #check if merge defined in user configuration file is correct or not
     _merge_input=`grep -i '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print $8}' k="$_module_name"|tr '[abcdefghijklmnopqrstuvwxyz]' '[ABCDEFGHIJKLMNOPQRSTUVWXYZ]'`;
     #echo "test point 1";
     _merge_req="$_merge_option_1"";""$_merge_option_2"";""$_merge_option_3";
     _merge_def_wrong=0;
     for _merge_input_pkg in `echo "$_merge_input"|awk -F';' '{print $1," ",$2," ",$3," ",$4," ",$5," " }'`
     do
         #echo "test point 2";
         if [ "$_merge_input_pkg" != "$_merge_option_1" -a "$_merge_input_pkg" != "$_merge_option_2"  -a "$_merge_input_pkg" != "$_merge_option_3" ]
         then
             echo "***ERROR: Package $_pkg_name needn't merge from package $_merge_input_pkg according delivery requirements($_merge_req)."|tee -a "$_module_log_file";
             _merge_def_wrong=1;
         fi
     done
     
     if [ "$_merge_def_wrong" = "1" ]
     then
         echo "***ERROR: Merge definition in the batch delivery configuration file is wrong!!!!"|tee -a "$_module_log_file";
         return 1;
     fi

     #The result of the merge_option_line may be: Y;Y;Y, N;N;N N;Y;N N;N;N Y;N N;Y, etc
     merge_option_line="";
     _COUNTB=0;
     #echo "merge_option_1=$merge_option_1;merge_option_2=$merge_option_2;merge_option_3=$merge_option_3.";
     #In "for" scripts, if merge_option is "", it will directly go to next step. So we needn't judge if it is ""
     for _merge_option in $_merge_option_1 $_merge_option_2 $_merge_option_3
     do
        _COUNTB=`expr $_COUNTB + 1`;

        #Retrieve the merge information from the input file
        #Field 8 of the corresponding line is the merge information
        #The spaces will be removed in the following script line
        #If the merge is needed, it is "Y"
        _merge_option=`grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print $8}' k="$_module_name"|awk   -F',' '{if($1 == k) print "Y"}' k=$_merge_option`;

        if [ -z "$_merge_option" ]
        then
            _merge_option="N";
        fi

        if [ -z "$merge_option_line" ] #merge_option_line is still ""
        then
            merge_option_line=$_merge_option;
        else #append the new merge_option
            merge_option_line=$merge_option_line";"$_merge_option;
        fi
     done
     if [ "$test_mode" = "-T" ]
     then
         echo "The transformed merge_option_line = $merge_option_line."|tee -a "$_module_log_file";
     fi
     return 0;
}


#parse one module's delivery configuration
parse_one_module_delivery_configuration_file()
{
     #$1: modules delivery input file
     _input_file=$1;
     #$2: package name
     _pkg_name=$2;
     #$3: module name
     _module_name=$3;
     
     _module_log_file="$delivery_home/$_pkg_name.$_module_name.$module_log_file_postfix"; 
     #create an empty log file
     echo "" > "$_module_log_file";   
     _is_valid=1;

     _src_dir_id=`echo "$_module_name"|grep -i 'SRC_DIR'|awk -F',' '{print $1}'`;
     if [ "$test_mode" = "-T" ]
     then
         echo "_src_dir_id: $_src_dir_id";
     fi
     
     if [ ! -z "$_src_dir_id" ]
     then
         #This one is folder
         if [ "$test_mode" = "-T" ]
         then
             echo "Enter parse_one_module_delivery_configuration_file() to parse the src_dir information for dir $3........" |tee -a "$_module_log_file";
             echo "Input file(1st param) is: $_input_file. The package name(2nd param) is: $_pkg_name. The src_dir name(3rd param) is: $_module_name."|tee -a "$_module_log_file";
         fi
         _src_dir=`grep -i '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyz]' "$_input_file" | sed "s, *,,g" |grep -i '^[0123456789abcdefghijklmnopqrstuvwxyz]'|awk -F',' '{if($1 == k) print $2}' k="$_module_name"`;
         if [ -d "$_src_dir" ]
         then
             _is_valid=1;
             parse_one_module_result_valid=1;
             src_dir_valid=1;
             _input_tmp_file="$delivery_home/$_pkg_name.$_module_name.$module_conf_file_postfix";
             echo "$_src_dir" > "$_input_tmp_file";
             return 0;
         else
             _is_valid=0;
             parse_one_module_result_valid=0;
             src_dir_valid=0;
             echo "***ERROR: Can't access folder: $_src_dir. All modules under this folder won't be delivered!";
             return 1;
         fi
     else
         if [ "$test_mode" = "-T" ]
         then
             echo "Enter parse_one_module_delivery_configuration_file() to parse the delivery information for module $3........" |tee "$_module_log_file";
             echo "Input file(1st param) is: $_input_file. The package name(2nd param) is: $_pkg_name. The module name(3rd param) is: $_module_name."|tee -a "$_module_log_file";
         fi
     fi


     #The following is to parse one real module other than a folder
     
     #c file has different read scenario
     _is_c_file=0;
     if [ -f "$src_dir/$_module_name.c" ]
     then
         #it is a c file
         _is_c_file=1;
     fi

     if [ "$test_mode" = "-T" ]
     then
         #Just to display the information,normally this is used for debug purpose
         echo "The original delivery configuration for module $_module_name is:"|tee -a "$_module_log_file";
         if [ "$_is_c_file" = "0" ]
         then
             #chill file
             grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print "Module name: ",$1,"\n","Label name:",$2,"\n","Package name: ",$3,"\n","Output object format: ",$4,"\n","Compile flag: ",$5,"\n","External CR/FR list:",$6,"\n","Internal CR/ER list: ",$7,"\n","Merge list: ",$8,"\n","Codereview report: ",$9}' k="$_module_name"|tee -a "$_module_log_file";
         else
             #c file
             grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print "Module name: ",$1,"\n","Label name:",$2,"\n","Package name: ",$3,"\n","Compile flag: ",$5,"Output object format: ",$4,"\n","\n","External CR/FR list:",$6,"\n","Internal CR/ER list: ",$7,"\n","Merge list: ",$8,"\n","Codereview report: ",$9}' k="$_module_name"|tee -a "$_module_log_file";
         fi
     fi
     
     #check package name
     _original_pkg_name=`grep -i '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyz]' "$_input_file" | sed "s, *,,g" |grep -i '^[0123456789abcdefghijklmnopqrstuvwxyz]'|awk -F',' '{if($1 == k) print $3}' k="$_module_name"`;
     #check if the package name is the same with definition required by data team
     roadmap=`echo "$tools_home/roadmap.txt"`;
     if [ `grep -i "^$_original_pkg_name" "$roadmap" | wc -l` -eq 0 ]
     then
         _correct_original_pkg_name=`echo "$_pkg_name"|sed 's/_/\//g'`;
         echo "***WARNING: Wrong package name($_original_pkg_name) for module $_module_name! The package should be $_correct_original_pkg_name"|tee -a "$_module_log_file";
    echo "The batch delivery will automatically use $_correct_original_pkg_name as the package name during the delivering."|tee -a "$_module_log_file";
     fi


     #check label name
     _original_label_name=`grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print $2}' k="$_module_name"`;
     
     _label_name_1=`echo "$_original_label_name"|grep -i '^SH_[ABCDEFGHIJKLMNOPQRSTUVWXYZ]\{2\}[0123456789][0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ]'`;
     if [ ! -z "$_label_name_1" ]
     then
         if [ "$_label_name_1" != "$_original_label_name" ]
         then
             echo "***ERROR: The SH label name in the configuration file is invalid: $_original_label_name."|tee -a "$_module_log_file";
             _is_valid=0;
    else
        _label_name=$_label_name_1;
         fi
     else
         _label_name_2=`echo "$_original_label_name"|grep -i '^WI_[ABCDEFGHIJKLMNOPQRSTUVWXYZ]\{2\}[0123456789][0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ]'`;
         if [ ! -z "$_label_name_2" ]
         then
             if [ "$_label_name_2" != "$_original_label_name" ]
             then
                 echo "***ERROR: The wipro label name in the configuration file is invalid: $_original_label_name."|tee -a "$_module_log_file";
                 _is_valid=0;
             else
            _label_name=$_label_name_2;
             fi
         fi
         echo "***ERROR: The label name in the configuration file is invalid: $_original_label_name."|tee -a "$_module_log_file";
         _is_valid=0;
     fi

     #echo "Before checking object format _is_valid: $_is_valid.";
     #check object format
     _original_object_format=`grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print $4}' k="$_module_name"`;
     _object_format=`echo "$_original_object_format"|grep -i '[LSOP]'`;
     if [ "$_object_format" != "$_original_object_format" ]
     then
         echo "***ERROR: The object format in the configuration file is invalid."|tee -a "$_module_log_file";
         _is_valid=0;
     fi
     
     #check compile flag list
     _original_compile_flag_list=`grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print $5}' k="$_module_name"`;
     #no check on compile flag list, it may be empty or some flags separated by ";"

     
 
     #echo "Before checking external cr/fr list _is_valid: $_is_valid.";
     _at_least_one_cr_er_fr_merge=0;
     #check external CR/FR list
     _valid_cr_fr_list="";
     _original_cr_fr_list=`grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print $6}' k="$_module_name"`;
     #echo "_original_cr_fr_list: $_original_cr_fr_list";
     for _original_cr_fr_1 in `echo "$_original_cr_fr_list"|awk -F';' '{print $1," ",$2," ",$3," ",$4," ",$5," ",$6," ",$7," ",$8," ",$9," ",$10," ",$11," ",$12," ",$13," ",$14," "}'`
     do
         _cr_fr_1=`echo "$_original_cr_fr_1"|grep -i '^CR[23][06]\/[0123456789]\{6\}'`;
         if [ ! -z "$_cr_fr_1" ]
         then
             #echo "_original_cr_fr_1: $_original_cr_fr_1; _cr_fr_1: $_cr_fr_1";
             if [ "$_cr_fr_1" != "$_original_cr_fr_1" ]
             then
                 echo "***ERROR: The external CR(CR20\/123456, or CR36\/123456, for example) format in the configuration file is invalid. CR: $_cr_fr_1."|tee -a "$_module_log_file";
                 _is_valid=0;
             else
                 if [ -z "$_valid_cr_fr_list" ]
                 then
                     _valid_cr_fr_list="$_cr_fr_1";
                 else
                      _valid_cr_fr_list="$_valid_cr_fr_list"";""$_cr_fr_1";
                 fi
                 _at_least_one_cr_er_fr_merge=1;
                 continue;#valid
             fi
         else
             #echo "_original_cr_fr_1: $_original_cr_fr_1; _cr_fr_2: $_cr_fr_2";
             _cr_fr_2=`echo "$_original_cr_fr_1"|grep -i '^FR[23][06]\/[0123456789]\{6\}'`;
             if [ ! -z "$_cr_fr_2" ]
             then
                 if [ "$_cr_fr_2" != "$_original_cr_fr_1" ]
                 then
                     echo "***ERROR: The external FR(FR20\/123456, or FR36\/123456, for example) format in the configuration file is invalid. FR: $_cr_fr_1."|tee -a "$_module_log_file";
                     _is_valid=0;
                 else
                     if [ -z "$_valid_cr_fr_list" ]
                     then
                         _valid_cr_fr_list="$_cr_fr_2";
                     else
                         _valid_cr_fr_list="$_valid_cr_fr_list"";""$_cr_fr_2";
                     fi
                     _at_least_one_cr_er_fr_merge=1;
                     continue;#valid
                 fi
             fi
             echo "***ERROR: The external CR/FR format in the configuration file is invalid.CR/FR: $_cr_fr_1."|tee -a "$_module_log_file";
             _is_valid=0;
         fi
     done

     #echo "Before checking cr/er list _is_valid: $_is_valid.";
     #check internal CR/ER list
     _valid_cr_er_list="";
     _original_cr_er_list=`grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print $7}' k="$_module_name"`;
     #echo "_original_cr_er_list: $_original_cr_er_list";
     for _original_cr_er_1 in `echo "$_original_cr_er_list"|awk -F';' '{print $1," ",$2," ",$3," ",$4," ",$5," ",$6," ",$7," ",$8," ",$9," ",$10," ",$11," ",$12," ",$13," ",$14," "}'`
     do
         _cr_er_1=`echo "$_original_cr_er_1"|grep -i '^CR[0123456789]\{4\}'`;
         if [ ! -z "$_cr_er_1" ]
         then
             #echo "_original_cr_er_1: $_original_cr_er_1; _cr_er_1: $_cr_er_1";
             if [ "$_cr_er_1" != "$_original_cr_er_1" ]
             then
                 echo "***ERROR: The internal CR(CR1234, for example) format in the configuration file is invalid. CR: $_cr_er_1."|tee -a "$_module_log_file";
                 _is_valid=0;
             else
                if [ -z "$_valid_cr_er_list" ]
                then
                    _valid_cr_er_list="$_cr_er_1";
                else
                    _valid_cr_er_list="$_valid_cr_er_list"";""$_cr_er_1";
                fi
                _at_least_one_cr_er_fr_merge=1;
                 continue;#valid
             fi
         else
             _cr_er_2=`echo "$_original_cr_er_1"|grep -i '^ER[0123456789]\{4\}'`
             if [ ! -z "$_cr_er_2" ]
             then
                 #echo "_original_cr_er_1: $_original_cr_er_1; _cr_er_2: $_cr_er_2";
                 if [ "$_cr_er_2" != "$_original_cr_er_1" ]
                 then
                     echo "***ERROR: The internal ER(ER1234, for example) format in the configuration file is invalid. ER: $_cr_er_2."|tee -a "$_module_log_file";
                     _is_valid=0;
                 else
           if [ -z "$_valid_cr_er_list" ]
           then
               _valid_cr_er_list="$_cr_er_2";
           else
                    _valid_cr_er_list="$_valid_cr_er_list"";""$_cr_er_2";
           fi
           _at_least_one_cr_er_fr_merge=1;
                     continue;#valid
                 fi
             fi
             echo "***ERROR: The internal CR/ER format in the configuration file is invalid. CR/ER: $_cr_er_1"|tee -a "$_module_log_file";
             _is_valid=0;
         fi
     done


     #echo "Before merge_option() _is_valid: $_is_valid.";
     #merge list will be checked in merge_option()
     merge_option $_input_file $_pkg_name $_module_name;
     merge_option_result=$?;
     #echo "merge_option_result: $merge_option_result";
     if [ $merge_option_result -ne 0 ]
     then
         _is_valid=0;
     fi
     #echo "After merge_option() _is_valid: $_is_valid.";
     _any_merge=`echo "$merge_option_line" | grep -i 'Y'`;
     if [ ! -z "$_any_merge" ]
     then
         _at_least_one_cr_er_fr_merge=1;
     fi

     if [ $_at_least_one_cr_er_fr_merge -eq 0 ]
     then
         echo "***ERROR: There must be at least one CR or ER or FR or merge for one module\'s delivery. Module: $_module_name"|tee -a "$_module_log_file";
         _is_valid=0;
     fi

     #check codereview report
     _original_codereview=`grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$_input_file" |sed 's/ *//g'| awk -F',' '{if($1 == k) print $9}' k="$_module_name"`;
     _codereview=`echo "$_original_codereview"|awk -F';' '{print $1}'|grep -i '^[ABC]'`;
     if [ ! -z "$_codereview" ]
     then
         if [ "$_code_review" = "c" -o "$_code_review" = "C" ]
         then
             _codereview_num=`echo "$_original_codereview"|awk -F';' '{print $2}'`;
             if [ -z "$_codereview_num" ]
             then
                 echo "***ERROR: The codereview format($_code_review) in the configuration file is invalid. Please clarify the codereview number."|tee -a "$_module_log_file";
                 _is_valid=0;
             fi
         fi
     else
         echo "***ERROR: The codereview format($_original_codereview) in the configuration file is invalid. Codereview type may be a/b/c."|tee -a "$_module_log_file";
         _is_valid=0;
     fi

     #echo "At the end _is_valid: $_is_valid.";
     if [ $_is_valid -eq 0 ]
     then
         echo "***ERROR: Delivery configuration for module $_module_name is wrong. Please check and update it before delivery."|tee -a "$_module_log_file";
         parse_one_module_result_valid=0;#wrong
         return 1;
     else
         #print the delivery information to the configuratoin file.
         #The module delivery infomration will be stored in the following file
         _input_tmp_file="$delivery_home/$_pkg_name.$_module_name.$module_conf_file_postfix";
     
         #print module name
         echo "$_module_name" > "$_input_tmp_file";
         
         #print label name
         echo "$_label_name" >> "$_input_tmp_file";
         
         #print package name
         echo "$_pkg_name"|sed 's/_/\//g'>>"$_input_tmp_file";
         
         if [ "$test_mode" = "-T" ]
         then
             echo "_is_c_file: $_is_c_file;"
         fi
         
         if [ "$_is_c_file" = "0" ]
         then
             #not c file
             #print output object format
             echo "$_object_format" >> "$_input_tmp_file";
   
             #print compile flag list
             if [ ! -z "$_original_compile_flag_list" ]
             then
                 echo "$_original_compile_flag_list"|tr ';' '\n'>>"$_input_tmp_file";
            #echo "_original_compile_flag_list:$_original_compile_flag_list";
             fi
             echo "">>"$_input_tmp_file";
         else
             #c file
             #print compile flag list
             if [ ! -z "$_original_compile_flag_list" ]
             then
                 echo "$_original_compile_flag_list"|tr ';' '\n'>>"$_input_tmp_file";
                 #echo "_original_compile_flag_list:$_original_compile_flag_list";
             fi
             echo "">>"$_input_tmp_file";   
             
             #print output object format
             echo "$_object_format" >> "$_input_tmp_file";
         fi
   
         #print external CR/FR list
         if [ ! -z "$_valid_cr_fr_list" ]
         then
             echo "$_valid_cr_fr_list"|tr ';' '\n'>>"$_input_tmp_file";
            #echo "_valid_cr_fr_list:$_valid_cr_fr_list";
         fi
         echo "">>"$_input_tmp_file";
 
         #print internal CR/ER list         
         if [ ! -z "$_valid_cr_er_list" ]
         then
             echo "$_valid_cr_er_list"|tr ';' '\n'>>"$_input_tmp_file";
             #echo "_valid_cr_er_list:$_valid_cr_er_list";
         fi
         echo "">>"$_input_tmp_file";
   
         #print merge options
         if [ ! -z "$merge_option_line" ]
         then
             #Only when merge_option_line is not empty, we need print the merge option
             echo "$merge_option_line"|tr ';' '\n'>>"$_input_tmp_file";
         fi
         
         #print codereview report
         if [ "$test_mode" = "-T" ]
         then
             echo "_original_codereview: $_original_codereview; _codereview: $_codereview.";
         fi
         
         if [ "$_codereview" = "c" -o "$_codereview" = "C" ]
         then
             echo "$_original_codereview"|tr ';' '\n'>>"$_input_tmp_file";
         else
             echo "$_codereview">>"$_input_tmp_file";
         fi 
         parse_one_module_result_valid=1;
         return 0;
     fi
     
     #wrong
     parse_one_module_result_valid=0;
     return 1;
}


#Parse the modules delivery input file
#Create the delivery temporary input files for every modules to be delivered
#modify global variable _parse_result_valid
parse_input_create_tmp()
{
     echo "Enter parse_input_create_tmp() to create the delivery temporary input files for every modules to be delivered.......";

     #$1: module delivery input file
     _input_file=$1;
     #$2: package name
     _pkg_name=$2;
     if [ "$test_mode" = "-T" ]
     then
         echo "Input file(1st param) is: $_input_file. The package name(2nd param) is: $_pkg_name.";
     fi
     
     module_list_file="$delivery_home/$_pkg_name.$module_list_file_postfix";
     #read the module delivery input file
     echo "The following modules will be parsed this time:";
     grep -i '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyz]' "$_input_file" | sed "s, *,,g" |grep -i '^[0123456789abcdefghijklmnopqrstuvwxyz]'|awk -F',' '{print $1}'|tee "$module_list_file";
     echo "Modules list file is: $module_list_file";

     valid_module_list_file="$delivery_home/$_pkg_name.$valid_module_list_file_postfix";
     #create an empty file to store the valid modules
     echo"" > "$valid_module_list_file";     
     echo "Valid modules list file is: $valid_module_list_file";

     
     _parse_valid=1;
     src_dir_valid=0;
     _src_dir="";
     _COUNTA=0;
     #Create one temporary file for each module for delivery
     while read _module_name
     do
        #check module name
        _module_name_1=`echo "$_module_name"|grep -i '[abcdefghijklmnopqrstuvwxyz0123456789_]*'`;
        if [ "$_module_name_1" != "$_module_name" ]
        then
            echo "***ERROR: The module name in the configuration file is invalid!ERROR***";
            echo "Skip this module and go to next module.";
            _parse_valid=0;
            continue;
        fi
       
        _COUNTA=`expr $_COUNTA + 1`;
        _src_dir_id=`echo "$_module_name"|grep -i 'SRC_DIR'|awk -F',' '{print $1}'`;
        if [ ! -z "$_src_dir_id" ]
        then
            #The next one is folder
            _src_dir="$_module_name";
            if [ "$test_mode" = "-T" ]
            then
                echo "The $_COUNTA one(folder) to be parsed is: $_module_name------------------"
            fi
        else
            if [ "$test_mode" = "-T" ]
            then
                echo "The $_COUNTA module to be parsed is:$_module_name------------------";
            fi
        fi
               
        #parse one module
        parse_one_module_result_valid=0;
        parse_one_module_delivery_configuration_file $_input_file $_pkg_name $_module_name;#|tee "$_module_log_file";
        if [ ! -z "$_src_dir_id" ]
        then
           if [ $parse_one_module_result_valid -eq 0 ]
           then
               src_dir_valid=0;
           else
               src_dir_valid=1;
           fi
        fi
       
        if [ $parse_one_module_result_valid -eq 0 ]
        then
            if [ ! -z "$_src_dir_id" ]
            then
                echo "***ERROR: The src_dir $_src_dir is invalid! All its modules won't be delivered!";
            else
                echo "***ERROR: The delivery configuration file for module $_module_name is invalid!ERROR***";
                echo "***ERROR: Skip this module and go to next module.";
            fi
            _parse_valid=0;
        else
            if [ "$src_dir_valid" = "0" ]
            then
                echo "The delivery configuration file for module $_module_name is valid! But its folder is wrong, and so it won't be delivered.";
            else
                if [ "$test_mode" = "-T" ]
                then
                    echo "The delivery configuration file for module $_module_name is valid! It is saved in file $valid_module_list_file";
                fi
               
                echo "$_module_name_1" >> "$valid_module_list_file";
            fi
         fi           
     done < "$module_list_file"
     
     grep -i '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyz]' "$valid_module_list_file" | sed "s, *,,g"> "valid_module_list.tmp";
     cat "valid_module_list.tmp" > "$valid_module_list_file";
     rm "valid_module_list.tmp";
     echo "Valid modules that can be delivered is stored in file $valid_module_list_file:";
     cat "$valid_module_list_file";
     wati;
     
     #update the total steps according to valid modules
     updated_total_steps=`cat "$valid_module_list_file"|grep -i '^[^#]'|wc -l`;
     _total_folders=`cat "$valid_module_list_file"|grep -i '^[^#]'|grep -i 'SRC_DIR'|wc -l`;
     updated_total_steps=`expr $updated_total_steps + 2 - $_total_folders`
     
     if [ $_parse_valid -eq 0 ]
     then
         echo "***ERROR: Batch delivery failed because there are errors during parsing the configuration file!";
         _parse_result_valid=0;#not valid
         return 1;
     fi
     _parse_result_valid=1;#valid   
     return 0;
}

rm_module_delivery()
{
     _module_delivery="$src_dir/module_delivery";
     if [ -e "$_module_delivery" ]
     then
         rm -f "$_module_delivery";
     fi
}

#deliver one module
deliver_one_module()
{
     #$1: module delivery input file
     _input_file=$1;
     #$2: package name
     _pkg_name=$2;
     #$3: module name
     _module_name=$3;
     
     _src_dir_id=`echo "$_module_name"|grep -i 'SRC_DIR'|awk -F',' '{print $1}'`;
     if [ ! -z "$_src_dir_id" ]
     then
         #The next one is folder
         _src_dir_id="$_module_name";
         if [ "$test_mode" = "-T" ]
         then
             echo "Enter deliver_one_module() to change src_dir: $_module_name.......";
             echo "Input file(1st param) is: $_input_file. The package name(2nd param) is: $_pkg_name. The module name(3rd param) is: $_module_name.";
         fi
         _input_tmp_file="$delivery_home/$_pkg_name.$_module_name.$module_conf_file_postfix";
         _src_dir=`cat "$_input_tmp_file"|sed -n '1p'`;
         cd "$_src_dir";
         if [ $? -eq 0 ]
         then
             #remove the module_delivery script in the original src_dir
             rm_module_delivery;
             
             #update the src_dir
             src_dir="$_src_dir";
             change_working_dir_valid=1;
             pwd;
             return 0;
         else
             change_working_dir_valid=0;
             echo "***ERROR: Can't access folder: $_src_dir. All modules under this folder won't be delivered!";
             return 1;
         fi
     else
         echo "Enter deliver_one_module() to deliver module: $_module_name.......";
         if [ "$test_mode" = "-T" ]
         then
             echo "Input file(1st param) is: $_input_file. The package name(2nd param) is: $_pkg_name. The module name(3rd param) is: $_module_name.";
         fi
         echo "The $_COUNTA module to be delivered is:$_module_name------------------";
     fi
     
     _tmp_input_file="$delivery_home/$_pkg_name.$_module_name.$module_conf_file_postfix";
     _module_log_file="$delivery_home/$_pkg_name.$_module_name.$module_log_file_postfix";
     echo "Delivery log for module $_module_name will be saved in $_module_log_file";
     _module_full_path="$src_dir/$_module_name.mpch";
     if [ ! -r "$_module_full_path" ]
     then
         _module_full_path="$src_dir/$_module_name.c";
         if [ ! -r "$_module_full_path" ]
         then
             echo "***ERROR: Can't access module $_module_name at:$src_dir/$_module_name.mpch or $_module_name.c. This module can't be delivered!"| tee -a "$_module_log_file";
             return 1;
         fi         
     fi
     ls -l "$_module_full_path";
         
     my_module_delivery="$tools_home/module_delivery";
     #redirect the stdin to the module delivery tmp file     
     wait;
     
     echo "The stdin will be redirected to(replaced by) the file $_tmp_input_file";
     exec 6>&0;        #file descriptor $fd_stdin is linked with stdin
     exec < $_tmp_input_file;  #stdin is replaced by the module delivery tmp file
     
     wait;
     
     echo "Module delivery is started for module $_module_name.";
     $my_module_delivery|tee -a "$_module_log_file";         #do the delivery for this module
     echo "Module delivery is finished for module $_module_name. Wait for all tasks to be finished.";
     wait;                     #wait for all tasks to be finished
     
     echo "The stdin will be recovered now.";
     exec 0<&6 6<&-; #recover the stdin
     wait;                     #wait for all tasks to be finished
}

#parse the module delivery log file to find out the problems during the module_delivery
#if any problem found, it means the delivery fails
analyze_module_delivery_result()
{
     #$1: module delivery input file
     _input_file=$1;
     #$2: package name
     _pkg_name=$2;
     #$3: module name
     _module_name=$3;
     if [ "$test_mode" = "-T" ]
     then
         echo "Enter analyze_module_delivery_result() to analyze the delivery result for module: $_module_name.......";
         echo "Input file(1st param) is: $_input_file. The package name(2nd param) is: $_pkg_name. The module name(3rd param) is: $_module_name."
     fi
     
     _module_log_file="$delivery_home/$_pkg_name.$_module_name.$module_log_file_postfix";
     output_sum_file="$delivery_home/$_pkg_name.$output_sum_file_postfix";
     echo "**********The following are the delivery result for module $_module_name***************"|tee -a "$output_sum_file";
     _delivery_result=`egrep -i "$delivery_err1|$delivery_err2|$delivery_err3|$delivery_err4|$delivery_err5|$delivery_err6|$delivery_err7|$delivery_err8|$delivery_err9|$delivery_err10|$delivery_err11|$delivery_err12|$delivery_err13|$_delivery_err14" "$_module_log_file"`;
     _delivery_errors=`egrep -i "\*\*\*ERROR" "$_module_log_file"`;
     _delivery_warnings=`egrep -i "\*\*\*WARNING" "$_module_log_file"`;

     echo|tee -a "$output_sum_file";
     if [ -z "$_delivery_result" -a -z "$_delivery_errors" ]
     then
         if [ -z "$_delivery_warnings" ]
         then
             echo "----------Module delivery for $_module_name has successfully finished---------"|tee -a "$output_sum_file";
         else
             echo "----------Module delivery for $_module_name has successfully finished with warnings---------"|tee -a "$output_sum_file";
             echo "***ERROR: auto_module_delivery warnings:"|tee -a "$output_sum_file";
             echo "$_delivery_warnings"|tee -a "$output_sum_file";
         fi
     else
         if [ -z "$_delivery_result" ]
         then
             _delivery_result="<<<<<<<<<<None>>>>>>>>>>";
         fi
         if [ -z "$_delivery_errors" ]
         then
             _delivery_errors="<<<<<<<<<<None>>>>>>>>>>";
         fi
         
         echo "----------Module delivery for $_module_name has failed with following reason----"|tee -a "$output_sum_file";
         echo "***ERROR: module_delivery errors:"|tee -a "$output_sum_file";
         echo "$_delivery_result"|tee -a "$output_sum_file";
         echo "***ERROR: auto_module_delivery errors:"|tee -a "$output_sum_file";
         echo "$_delivery_errors"|tee -a "$output_sum_file";
     fi
     echo|tee -a "$output_sum_file"; echo|tee -a "$output_sum_file";
}


#main flow to control the batch delivery
main()
{
     echo "Enter main() procedure----------------------------------------------";
     #$1: module delivery input file
     _input_file=$1;
     #$2: pkg name
     _pkg_name=$2;
     
     if [ "$test_mode" = "-T" ]
     then
         echo "Input file(1st param) is: $_input_file. Package name(2nd param) is: $_pkg_name.";
     fi
     
     _total_modules_tbp=`grep -i '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyz]' "$_input_file" | sed "s, *,,g" |grep -i '^[0123456789abcdefghijklmnopqrstuvwxyz]'|wc -l|awk '{print $1}'`;
     _total_folders=`grep -i '^[^#]' "$_input_file" |grep -i 'SRC_DIR'| wc -l|awk '{print $1}'`;
     #_total_modules_tbp=`expr $_total_modules_tbp - $_total_folders`;
     echo "Totally $_total_modules_tbp modules including $_total_folders folders will be parsed this time.";

     _total_steps=`expr $_total_modules_tbp + 2 - $_total_folders`;
     updated_total_steps=$_total_steps;
     echo "Totally we have $updated_total_steps steps to finish the batch delivery.";
     _current_step=1;
     echo "Step: $_current_step/$updated_total_steps----------------------------------------------";
     current_time=`date   +%Y-%m-%d-%H:%M:%S`;
     echo "Current Time: $current_time";
     
     #it means if all modules are valid in the configuration file, it will be modified in following function
     _parse_result_valid=0;
     #updated_total_steps will also be updated in following function according to valid modules
     parse_input_create_tmp "$_input_file" "$_pkg_name";
     
     if [ "$updated_total_steps" != "$_total_steps" ]
     then
         if [ "$deliver_mode" = "-T" ]
         then
             echo "updated_total_steps: $updated_total_steps; _total_steps: $_total_steps"
             _skipped_steps=`expr $_total_steps - $updated_total_steps`;
             echo "Step: $_skipped_steps\/$_total_steps steps will be skipped----------------------------------------------";
             _total_steps=$updated_total_steps;
         elif [ $_parse_result_valid -eq 0 ]
         then
             _num_valid_module=`expr $updated_total_steps - 2`;
             echo "$_num_valid_module modules configurations are valid but all deliveries will be skipped----------------------------------------------";
             #no modules will be delivered
             updated_total_steps=2;
             _total_steps=2;
         fi
     fi
     
     output_sum_file="$delivery_home/$_pkg_name.$output_sum_file_postfix";
     echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Batch delivery summary-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"> "$output_sum_file";
     echo  >> "$output_sum_file";echo  >> "$output_sum_file";

     #no error during parsing the configuration file or TryBest delivery mode is selected
     if [ $_parse_result_valid -eq 1 -o "$deliver_mode" = "-T" ]
     then
         #loop to deliver all modules
         #read from the output summarize file for every module
         ls -l "$module_delivery";
         ls -l $_input_file;
     
         #changing_working_directory valid or not
         change_working_dir_valid=0;
         
         #at least one valid module     
         at_least_one_valid_module=`grep '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' "$valid_module_list_file"|sed 's/ *//g'`   
         if [ ! -z "$at_least_one_valid_module" ]
         then
             while read _module_name
             do
                 _src_dir_id=`echo "$_module_name"|grep -i 'SRC_DIR'|awk -F',' '{print $1}'`;
                 if [ -z "$_src_dir_id" ]
                 then
                     #this is a module
                     _current_step=`expr $_current_step + 1`;
                     echo "Step: $_current_step/$updated_total_steps----------------------------------------------";
                 else
                     #this is a folder
                     echo "Step: change working directory----------------------------------------------";
                 fi
                 current_time=`date   +%Y-%m-%d-%H:%M:%S`;
                 echo "Current Time: $current_time";
                 
                 
                 if [ -z "$_src_dir_id" -a "$change_working_dir_valid" = "0" ]
                 then
                     echo "***ERROR: Module $_module_name won't be delivered because preparing working directory failed previously!";
                     continue;
                 fi
                 
                 #start to deliver one module
                 deliver_one_module "$_input_file" "$_pkg_name" "$_module_name";
                 
                 #analyze the module delivery result
                 if [ -z "$_src_dir_id" ]
                 then
                     #this is a module
                     analyze_module_delivery_result "$_input_file" "$_pkg_name" "$_module_name";
                 fi   
             done < $valid_module_list_file
             
             #remove the module_delivery script from the src_dir
             rm_module_delivery;
         else
             echo "***ERROR: There is no one valid modules in file: $valid_module_list_file";
         fi
     else
         echo "***ERROR: Batch delivery failed because delivery configuration file is invalid. Aborted!" |tee -a "$output_sum_file";
         echo "***ERROR: Please check the errors and update the configuration file accordingly.Aborted!"|tee -a "$output_sum_file";
         echo  >> "$output_sum_file"; echo  >> "$output_sum_file";
     fi

     #display the summary of this batch delivery
     _current_step=`expr $_current_step + 1`;
     echo "Step: $_current_step/$updated_total_steps----------------------------------------------";
     echo "Display the summary of this batch delivery";
     current_time=`date   +%Y-%m-%d-%H:%M:%S`;
     echo "Current Time: $current_time";

     cat "$output_sum_file";
     echo "-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*Batch delivery summary-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"|tee -a "$output_sum_file";

     echo "--------------------------------------Batch delivery is finished----------------------------------";
}



#Parse input parameters, at most 4 input parameters are supported now
#global parameters: test_mode, input_file, deliver_mode will updated accordingly
#input_file will be saved to input_file_tmp. All later operation will be based on input_file_tmp
parse_input_parameter_update_global_parameters()
{
     #$1,$2,$3,$4,$5(log file)     
     _log_file=$5;
     if [ -z "$_log_file" ]
     then
         _log_file="tmp.log";
     fi

     if [ "$test_mode" = "-T" ]
     then
         echo "Enter parse_input_parameter_update_global_parameters() to parse the input parameters......."|tee -a "$_log_file";
         echo "\$1=$1;\$2=$2;\$3=$3;\$4=$4;\$5(Log file)=$5"|tee -a "$_log_file";
     fi
     
     #four input parameters for the scripts
     tmp_1=`echo "$1"|grep -i '^-[abcdefghijklmnopqrstuvwxyz]\{0,\}t'`;
     tmp_2=`echo "$2"|grep -i '^-[abcdefghijklmnopqrstuvwxyz]\{0,\}t'`;
     tmp_3=`echo "$3"|grep -i '^-[abcdefghijklmnopqrstuvwxyz]\{0,\}t'`;
     tmp_4=`echo "$4"|grep -i '^-[abcdefghijklmnopqrstuvwxyz]\{0,\}t'`;
     if [ ! -z "$tmp_1" -o ! -z "$tmp_2" -o ! -z "$tmp_3" -o ! -z "$tmp_4" ]
     then
         test_mode="-T";
         echo "Batch delivery will run in test mode."|tee -a "$_log_file";
     fi

     tmp_1=`echo "$1"|grep -i '^-[abcdefghijklmnopqrstuvwxyz]\{0,\}d'`;
     tmp_2=`echo "$2"|grep -i '^-[abcdefghijklmnopqrstuvwxyz]\{0,\}d'`;
     tmp_3=`echo "$3"|grep -i '^-[abcdefghijklmnopqrstuvwxyz]\{0,\}d'`;
     tmp_4=`echo "$4"|grep -i '^-[abcdefghijklmnopqrstuvwxyz]\{0,\}d'`;
     if [ ! -z "$tmp_1" -o ! -z "$tmp_2" -o ! -z "$tmp_3" -o ! -z "$tmp_4" ]
     then
         deliver_mode="-T";
         echo "Batch delivery will deliver the modules with valid delivery configuration even if there are invalid modules."|tee -a "$_log_file";
     else
         echo "Batch delivery will abort if there is at least one module with invalid delivery configuration."|tee -a "$_log_file";     
     fi

     tmp_1=`echo "$1"|grep -i '^[^-][0123456789abcdefghijklmnopqrstuvwxyz]'`;
     tmp_2=`echo "$2"|grep -i '^[^-][0123456789abcdefghijklmnopqrstuvwxyz]'`;
     tmp_3=`echo "$3"|grep -i '^[^-][0123456789abcdefghijklmnopqrstuvwxyz]'`;
     tmp_4=`echo "$4"|grep -i '^[^-][0123456789abcdefghijklmnopqrstuvwxyz]'`;
     if [ ! -z "$tmp_1" ]
     then
         input_file=$1;
     elif [ ! -z "$tmp_2" ]
     then
         input_file=$2;
     elif [ ! -z "$tmp_3" ]
     then
         input_file=$3;
     elif [ ! -z "$tmp_4" ]
     then
         input_file=$4;
     else
         echo "Please enter the batch delivery configuration file: ";
         read _input_file;
         _is_exist_input_file=1;
         while [ ! -e $_input_file ]
         do
             _is_exist_input_file=0;
             echo "The file doesn\'t exist. Please re-enter:";
             read _input_file;
             if [ -r $_input_file ]
             then
                 input_file=$_input_file;
                 break;
             fi
         done
     fi
     
     echo "The configuration file for batch delivery is $input_file"|tee -a "$_log_file";     
     return 0;
}


#parse the input file to:
#(1) check log directory, and create log file
#(2) copy the input file to delivery log home directory
#(3) following global parameters will be updated and available for use after this function
#view_name, pkg_name, delivery_home, delivery_log_file, src_dir
parse_input_file_prepare_environment()
{
     #$1: input_file
     _input_file=$1;
     #$2: log file
     _log_file=$2;
     if [ "$test_mode" = "-T" ]
     then
         echo "Enter parse_input_file_prepare_environment() to parse input_file $_input_file and prepare the working environment......."|tee -a "$_log_file";
         echo "Input file(1st param) is: $_input_file. Log file(2nd param) is $_log_file"|tee -a "$_log_file";
     fi
     
     #check module_delivery script
     if [ ! -x "$module_delivery" ]
     then
         echo "***ERROR: Module_delivery script file is not executable: $module_delivery. Aborted!"|tee -a "$_log_file";
         return 1;
     fi

     #get pkg_name from input_file
     #the 1st valid line is "SRC_DIR", so the 2nd valid line is the a real module
     pkg_name=`grep -i '^[^#] *[0123456789abcdefghijklmnopqrstuvwxyz]' "$_input_file" | sed "s, *,,g" |grep -i '^[0123456789abcdefghijklmnopqrstuvwxyz]'|awk -F',' '{print $3}'|sed -n '2p'|sed 's/ *//g'`;
     #check if the package name is the same with definition required by data team
     roadmap=`echo "$tools_home/roadmap.txt"`;
     if [ `grep -i "^$pkg_name" "$roadmap" | wc -l` -eq 0 ]
     then
         echo "***ERROR: Wrong package name($pkg_name), please check the roadmap and re-fill! Aborted!"|tee -a "$_log_file";
         return 1;
     fi

     #Delivery log directory
     delivery_home=`egrep "^[^#]*[\[ *DELIVERY_LOG_DIR *\]]" "$_input_file"|sed 's/ *//g'|awk -F',' '{print $1}'|awk -F']' '{if($1=="[DELIVERY_LOG_DIR") print $2}'|sed 's/\[//g'`;
     #If this directory doesn't exist, create it
     if [ ! -d "$delivery_home" ]
     then
         mkdir "$delivery_home";
         _error_code=$?;
         if [ $_error_code -ne 0 ]
         then
             echo "***ERROR: [Code: $_error_code]Cannot create delivery log directory: $delivery_home. Aborted!"|tee -a "$_log_file";
             return 1;
         fi
     fi

     #transform pkg_name: "/" is replaced by "_"
     pkg_name=`echo "$pkg_name"|sed 's/\//_/'`;
     delivery_log_file="$delivery_home/$pkg_name.$delivery_log_file_postfix";
     echo "All batch delivery related log files will be stored in folder: $delivery_home"|tee -a "$_log_file";
     
     
     _input_file_name=`basename "$_input_file"`;
     _input_file_tmp="$delivery_home/$pkg_name.$_input_file_name.tmp";
     _input_file_bak="$delivery_home/$pkg_name.$_input_file_name.bak.tmp";
     #Create the input conf bak file. Afterwards, the operations on the conf file will be based on it
     awk '{print $0,"\n"}' "$_input_file" > "$_input_file_tmp";
     if [ $? -ne 0 ]
     then
         echo "***ERROR: Can't create bak file for the input configuration file: from \"$input_file\" to \"$_input_file_bak\"!"|tee -a "$_log_file";
         return 1;
     fi
     wait;
     
     echo '#Transformed batch delivery configuration file' > "$_input_file_bak";
     _COUNT_SRC_DIR=0;
     while read _line_conf
     do
         _src_dir_id=`echo "$_line_conf"|grep -i 'SRC_DIR'|awk -F',' '{print $1}'`;
         if [ ! -z "$_src_dir_id" ]
         then
             #echo "_line_conf:$_line_conf";
             _COUNT_SRC_DIR=`expr $_COUNT_SRC_DIR + 1`;
             _src_dir_id_new="$_src_dir_id""_""$_COUNT_SRC_DIR";
             #echo "_src_dir_id_new: $_src_dir_id_new";
             _line_conf_new=`echo "$_line_conf"|sed "s,$_src_dir_id,$_src_dir_id_new,g"`;
             #echo "\$_line_conf_new: $_line_conf_new."
             echo "$_line_conf_new" >> "$_input_file_bak";
         else
             echo "$_line_conf" >> "$_input_file_bak";
         fi
     done < "$_input_file_tmp"
     rm -f "$_input_file_tmp";
     wait;
     
     _input_file="$_input_file_bak";
     
     #The input file should be writable
     chmod +rw "$_input_file";
     cmd_result=$?;
     if [ $cmd_result -ne 0 ]
     then
         echo "***ERROR: [Code: $cmd_result]Cannot add r/w attributes for the batch delivery configuration file: $_input_file. Aborted!"|tee -a "$_log_file";
         return 1;
     fi
     
     input_file=$_input_file;
     return 0;
}

############################################################################################
####                 The following are the script main body                             ####
############################################################################################

tmp_log="tmp.log"
echo "A new batch delivery is to be launched."|tee "$tmp_log";
current_time=`date   +%Y-%m-%d-%H:%M:%S`;
echo "Current Time: $current_time"|tee -a "$tmp_log";
echo "Input paramters: \$1=$1, \$2=$2, \$3=$3, \$4=$4"|tee -a "$tmp_log";

#step 1: check the input parameters and update the global variables accordingly
parse_input_parameter_update_global_parameters "$1" "$2" "$3" "$4" "$tmp_log";

#step 2: parse the input conf file and prepare the working environment
parse_input_file_prepare_environment "$input_file" "$tmp_log";
if [ $? -ne 0 ]
then
    echo "Batch module delivery aborted! Detailed log can be found in: $tmp_log";
    exit 1;
fi

#step3: copy the log from tmp_log to formal package delivery log
#Afterwards, all package delivery log is stored in the formal log instead of the tmp_log
cat "$tmp_log" > "$delivery_log_file";
wait;
rm "$tmp_log";
wait;
     
#save current dir
bak_dir=`pwd`;

#step4: start the main procedure to parse input configuration file and to deliver modules
main "$input_file" "$pkg_name" | tee -a "$delivery_log_file";

#step5: Last step to finish the batch module delivery
#Back to the original directory
echo "Change working directory to original directory: $bak_dir"|tee -a "$delivery_log_file";
cd "$bak_dir";
pwd;

current_time=`date   +%Y-%m-%d-%H:%M:%S`;
echo "Current Time: $current_time"|tee -a "$delivery_log_file";

exit 0;


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 1 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 2 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译