Index: nutchez-0.2/src/test/client_install_func.sh
===================================================================
--- nutchez-0.2/src/test/client_install_func.sh	(revision 159)
+++ nutchez-0.2/src/test/client_install_func.sh	(revision 167)
@@ -8,4 +8,15 @@
 
 # 正式版之後，記的將不必要的 echo 拿掉
+function debug_info () {
+  if [ $? -eq 0 ]; then
+    echo -e "\033[1;35;40m info - $1 \033[0m"
+  fi
+}
+
+function show_info () {
+  if [ $? -eq 0 ]; then
+    echo -e "\033[1;32;40m $1 \033[0m"
+  fi
+}
 
 
@@ -13,11 +24,11 @@
 function check_root(){
 # 正式版後可拿掉此 echo
-echo -e "\n\033[31m= check_root (debug) =\033[0m"
-if [ $USER != "root" ]; then
-    echo -e "\nPlz Change root to execute it!!!"
-    exit
-fi
+  debug_info "check_root"
+  if [ $USER != "root" ]; then
+    show_info "Please Change root to execute it!!!"
+    exit
+  fi
 # 正式版後可拿掉此 echo
-echo -e "Identify is root."
+  show_info "Identify is root."
 }
 
@@ -25,9 +36,9 @@
 # 查出此主機的作業系統,以及版本
 function check_systemInfo(){
-echo -e "\n\033[31m= check_systemInfo (debug) =\033[0m"
-echo -e "\nYour system information are:"
+  debug_info "check systemInfo"
+  show_info "Your system information are:"
 Linux_Distribution=$(lsb_release -a 2> /dev/null | grep "Distributor ID:" | awk '{print $3}')
 Linux_Version=$(lsb_release -a 2> /dev/null | grep "Release" | awk '{print $2}')
-echo $Linux_Distribution , $Linux_Version
+  show_info "$Linux_Distribution , $Linux_Version"
 }
 
@@ -35,18 +46,18 @@
 # 安裝需要的相依套件 (目前只支援 deb 套件的系統自動安裝，yum或其他套件系統的則需手動安裝)
 function install_packages(){
-# deb 系列系統
-echo -e "\n\033[31m= install_packages (debug) =\033[0m"
-echo -e "\nCheck dependent packages"
-if [ "$Linux_Distribution" == "Ubuntu" ] || [ "$Linux_Distribution" == "Debian" ] ;then
+  # deb 系列系統
+  debug_info "install_packages"
+  debug_info "Check dependent packages"
+  if [ "$Linux_Distribution" == "Ubuntu" ] || [ "$Linux_Distribution" == "Debian" ] ;then
     echo -e "\nIt will install sime packages (expect, ssh, and dialog).\n"
     aptitude install -y expect ssh dialog
-# rpm 系列系統
-elif [ "$Linux_Distribution" == "Fedora" ] || [ "$Linux_Distribution" == "CentOS" ] ;then
-    echo -e "Plz install expect, ssh, and dialog."
-    exit
-else
-    echo -e "Plz install expect, ssh, and dialog."
-    exit
-fi 
+  # rpm 系列系統
+  elif [ "$Linux_Distribution" == "Fedora" ] || [ "$Linux_Distribution" == "CentOS" ] ;then
+    show_info "Please install expect, ssh, and dialog."
+    exit
+  else
+    show_info "Please install expect, ssh, and dialog."
+    exit
+  fi 
 }
 
@@ -55,11 +66,11 @@
 # 目前先檢查是否有/opt/nutchez 這個資料夾即可
 function check_nez_installed(){
-echo -e "\n\033[31m= chcheck_nez_installed (debug) =\033[0m"
-if [ -d /opt/nutchez ]; then
-    echo -e "\nSystem already had NutchEz."
-    exit
-else
-    echo -e "\nSystem does not has NutchEz."
-fi
+  debug_info "chcheck_nez_installed"
+  if [ -d /opt/nutchez ]; then
+    show_info "System already had NutchEz."
+    exit
+  else
+    show_info "System does not has NutchEz."
+  fi
 }
 
@@ -69,60 +80,60 @@
 # (3)系統有安裝但Sun Java 在非預設路徑下 (4)以正確安裝 Sun JAVA 預設路徑下
 function check_sunJava(){
-echo -e "\n\033[31m= check_sunJava (debug) =\033[0m"
-echo -e "\nNutchEz need Sun Java JDK 1.6.x or above version"
-
-javaPath="/usr"
-yesno="no"
-choice="3"
-
-    if [ -e $javaPath/bin/java ]; then
-      JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
-      JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
-      awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
+  debug_info "check_sunJava"
+  debug_info "NutchEz need Sun Java JDK 1.6.x or above version"
+
+  javaPath="/usr"
+  yesno="no"
+  choice="3"
+
+  if [ -e $javaPath/bin/java ]; then
+    JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
+    JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
+    awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
    
-        if [ "$JAVA_org" == "" ]; then 
-            echo "Java is not Sun version, plz install sun Java 1.6.X"
-            echo -e "\nPlz input your choice: "
-            echo "(1)System don't have Sun Java (2)Sun Java is in other path (3)Exit"
-            read -p "plz input (1/2/3): " choice
-            case $choice  in
-                "1")
-                echo -e "Plz install Sun Java manually!"
-                exit 
-                ;;
-                "2")
-                    read -p "Input Sun Java home path(ex. '/usr/lib/jvm/java-6-sun-1.6.0.12' or using default '/usr' ): " javaPath
-                ;;
-                "*")
-                exit
-                ;;
-            esac
-
-            if [ $choice == "2" ]; then
-                JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
-                JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
-                awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
-                
-                if [ "$JAVA_org" == "" ]; then
-                echo -e "It is not Sun Java! Plz install Sun Java manually!"
-                exit
-                fi
+  if [ "$JAVA_org" == "" ]; then 
+    show_info "Java is not Sun version, plz install sun Java 1.6.X"
+    show_info "Please input your choice: "
+    show_info "(1)System don't have Sun Java (2)Sun Java is in other path (3)Exit"
+    read -p "plz input (1/2/3): " choice
+    case $choice  in
+      "1")
+        show_info "Please install Sun Java manually!"
+        exit 
+        ;;
+      "2")
+        read -p "Input Sun Java home path(ex. '/usr/lib/jvm/java-6-sun-1.6.0.12' or using default '/usr' ): " javaPath
+        ;;
+        "*")
+        exit
+        ;;
+        esac
+
+        if [ $choice == "2" ]; then
+          JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
+          JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
+          awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
+              
+          if [ "$JAVA_org" == "" ]; then
+            show_info "It is not Sun Java! Plz install Sun Java manually!"
+            exit
             fi
+          fi
         fi  
 
       large16=$(echo "$JAVA_version >= 1.6" | bc)
       if [ "${large16}" == 0 ]; then
-          echo "Java version is too old (it need 1.6.X above)"
-          exit
+        show_info "Java version is too old (it need 1.6.X above)"
+        exit
       fi  
       
-      echo "System has Sun Java 1.6 above version."
-  else
-      echo "Plz install Sun JAVA 1.6.X or above version"
-      exit
-  fi
-
-unset JAVA_org
-unset JAVA_version
+      show_info "System has Sun Java 1.6 above version."
+  else
+    show_info "Please install Sun JAVA 1.6.X or above version"
+    exit
+  fi
+
+  unset JAVA_org
+  unset JAVA_version
 }
 
@@ -130,18 +141,18 @@
 # 檢查是否有安裝openssh, openssh-server
 function check_ssh(){
-echo -e "\n\033[31m= check_ssh (debug) =\033[0m"
-if [ -e /usr/bin/ssh ]; then
-    echo -e "\nSystem has ssh."
-else
-    echo "Plz install ssh."
-    exit
-fi
-
-if [ -e /usr/sbin/sshd ]; then
-    echo "System has ssh Server (sshd)."
-else
-    echo "Plz install ssh Server (sshd)."
-    exit
-fi
+  debug_info "check_ssh"
+  if [ -e /usr/bin/ssh ]; then
+    show_info "System has ssh."
+  else
+    show_info "Please install ssh."
+    exit
+  fi
+
+  if [ -e /usr/sbin/sshd ]; then
+    show_info "System has ssh Server (sshd)."
+  else
+    show_info "Please install ssh Server (sshd)."
+    exit
+  fi
 }
 
@@ -149,11 +160,11 @@
 # 檢查是否有安裝dialog
 function check_dialog(){
-echo -e "\n\033[31m= check_dialog (debug) =\033[0m"
-if [ -e /usr/bin/dialog ]; then
-    echo -e "\nSystem has dialog."
-else
-    echo "Plz install dialog."
-    exit
-fi
+  debug_info "check_dialog"
+  if [ -e /usr/bin/dialog ]; then
+    show_info "System has dialog."
+  else
+    show_info "Please install dialog."
+    exit
+  fi
 }
 
@@ -163,12 +174,11 @@
 # 此步驟若無法連到 master 則跳出
 function scp_master_nutchuser_sshkey(){
-  echo -e "\n\033[31m= scp_master_nutchuser_sshkey (debug) =\033[0m"
-  echo -e "mkdir -p /home/nutchuser/"
+  debug_info "scp_master_nutchuser_sshkey"
+  debug_info "mkdir -p /home/nutchuser/"
   mkdir -p /home/nutchuser/.ssh/
   rm -fr /home/nutchuser/.ssh/*
-
   unset Nutchuser_Passwd2
 
-  echo -e "scp nutchuser@$1:~/.ssh /home/nutchuser/"
+  debug_info "scp nutchuser@$1:~/.ssh /home/nutchuser/"
 expect -c "spawn scp -r -o StrictHostKeyChecking=no nutchuser@$1:~/.ssh /home/nutchuser/
 expect \"*: \" { send \"$Nutchuser_Passwd\r\" }
@@ -177,37 +187,34 @@
 
   if [ -e "/home/nutchuser/.ssh/authorized_keys" ]; then
-        echo -e "\nscp correct."    
+    show_info "scp correct."    
     else
-      echo -e "\nscp is error,\n(1)plz check nutchuser password in server\n(2)nutchuser's authorized_keys in server\n(3)server's network status"
-      exit
-    fi
+      show_info "scp error,\n(1)plese check nutchuser password in server\n(2)nutchuser's authorized_keys in server\n(3)server's network status"
+    exit
+  fi
   ssh-add /home/nutchuser/.ssh/id_rsa
-  echo "chown -R nutchuser:nutchuser /home/nutchuser/.ssh"
+  debug_info "chown -R nutchuser:nutchuser /home/nutchuser/.ssh"
   chown -R nutchuser:nutchuser /home/nutchuser/.ssh
 }
-
 
 # 新增nutchuser 帳號時用 Nutchuser_Passwd 當密碼
 function creat_nutchuser_account(){
-echo -e "\n\033[31m= creat_nutchuser_account (debug) =\033[0m"
-
-while [ "$Nutchuser_Passwd" != "$Nutchuser_Passwd2" ]
-do
-    echo -e "\n"
-    read -sp "Plz input nutchuser password of master node: " Nutchuser_Passwd
-    echo 
-    read -sp "plz input nutchuser password, again: " Nutchuser_Passwd2
-    echo 
+  debug_info "creat_nutchuser_account"
+  while [ "$Nutchuser_Passwd" != "$Nutchuser_Passwd2" ]
+  do
+      echo -e "\n"
+      read -sp "Plz input nutchuser password of master node: " Nutchuser_Passwd
+      echo 
+      read -sp "plz input nutchuser password, again: " Nutchuser_Passwd2
+      echo 
         if [ "$Nutchuser_Passwd" == "$Nutchuser_Passwd2" ]; then
-            echo "Two Passwords match."
+          show_info "Two Passwords match."
         else
-            echo "Two passwords don't match, plz re-input nutchuser's password."
+          show_info "Two passwords don't match, please re-input nutchuser's password."
         fi
-done                                                                                                                                    
-   
-unset Nutchuser_Passwd2
-
-if [ $(cat /etc/passwd | grep nutchuser) ]; then
-    echo "System already has nutchuser, change nutchuser password."
+  done                                                                                                                                    
+  unset Nutchuser_Passwd2
+
+  if [ $(cat /etc/passwd | grep nutchuser) ]; then
+    show_info "System already has nutchuser, change nutchuser password."
     expect -c "spawn passwd nutchuser
     set timeout 1
@@ -217,15 +224,15 @@
     send \"$Nutchuser_Passwd\r\"
     expect eof"
-else
-    echo "Create nutchuser and change password."
-    useradd -m nutchuser -s /bin/bash
-    expect -c "spawn passwd nutchuser
-    set timeout 1
-    expect \"*: \"
-    send \"$Nutchuser_Passwd\r\"
-    expect \"*: \"
-    send \"$Nutchuser_Passwd\r\"
-    expect eof"
-fi
+    else
+      echo "Create nutchuser and change password."
+      useradd -m nutchuser -s /bin/bash
+      expect -c "spawn passwd nutchuser
+      set timeout 1
+      expect \"*: \"
+      send \"$Nutchuser_Passwd\r\"
+      expect \"*: \"
+      send \"$Nutchuser_Passwd\r\"
+      expect eof"
+  fi
 }
 
@@ -233,5 +240,5 @@
 # 目前僅需做到能無礙的複製遠端的/opt/nutchez/到local的/opt/
 function scp_packages(){
-  echo -e "\n\033[31m= scp_packages (debug) =\033[0m"
+  debug_info "scp_packages"
   mkdir /opt/nutchez
   mkdir /var/nutchez
@@ -240,8 +247,8 @@
   chmod 777 /opt/nutchez
   #su nutchuser -c "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez /opt/"
-  echo "scp -r nutchuser@$1:/opt/nutchez/NutchezForClientOf_$Master_IP_Address.tar.gz /opt/nutchez/"
+  debug_info "scp -r nutchuser@$1:/opt/nutchez/NutchezForClientOf_$Master_IP_Address.tar.gz /opt/nutchez/"
   su nutchuser -c "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/home/nutchuser/nutchez/source/NutchezForClientOf_$Master_IP_Address.tar.gz /home/nutchuser/nutchez/source"
 
-  echo -e "\nchown -R nutchuser:nutchuser /opt/nutchez"
+  debug_info "chown -R nutchuser:nutchuser /opt/nutchez"
   chown -R nutchuser:nutchuser /opt/nutchez
   chown -R nutchuser:nutchuser /var/nutchez
@@ -252,5 +259,5 @@
 
 function install_nutch_package(){
-  echo -e "\n\033[31m= install_nutch_package (debug) =\033[0m"
+  debug_info "install_nutch_package"
   tar -zxvf /home/nutchuser/nutchez/source/NutchezForClientOf_$Master_IP_Address.tar.gz -C /opt/nutchez
   sed -i '1a '$Master_IP_Address' '$Master_Hostname'' /etc/hosts
@@ -260,45 +267,42 @@
 
 function recall_hostname_ip(){
-echo -e "\n\033[31m= recall_hostname_ip (debug) =\033[0m"
-
-net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
-net_nu=$(echo $net_interfaces | wc -w)
-
-# 若只有一個 eth　時
-if [ "$net_nu" == "1" ]; then
-
-# ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
-net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
-net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
-echo "net_address is $net_address"
-echo "net_MacAddr is $net_MacAddr"
-
-# 若有多個 eth 時
-else
-    declare -i i=1
-    echo -e "\nSystem have multiple network device, which network use for this machine: "
+  debug_info "recall_hostname_ip"
+  net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
+  net_nu=$(echo $net_interfaces | wc -w)
+  # 若只有一個 eth　時
+  if [ "$net_nu" == "1" ]; then
+  # ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
+  net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
+  net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
+  show_info "net_address is $net_address"
+  show_info "net_MacAddr is $net_MacAddr"
+
+  # 若有多個 eth 時
+    else
+      declare -i i=1
+      show_info "System have multiple network device, which network use for this machine: "
        
-    for net in $net_interfaces
-        do  
-            echo "($i)  $net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
-            i=i+1
-        done
+      for net in $net_interfaces
+      do  
+        echo "($i)  $net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
+        i=i+1
+      done
        
-        read -p "Plz choice(1/2/3...): " net_choice
-    if [ -z $net_choice ]; then
-        net_choice=1
-    fi   
-
-    echo "choice is $net_choice"
-    net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
-    # config $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
-    net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
-    net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g') 
-    echo "net_address is $net_address"
-    echo "net_MacAddr is $net_MacAddr"
-fi
-
-echo "ssh nutchuser@$1 echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/nutch_nodes"
-su nutchuser -c "ssh nutchuser@$1 echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/nutch_nodes"
+      read -p "Please choice(1/2/3...): " net_choice
+  if [ -z $net_choice ]; then
+    net_choice=1
+  fi   
+
+  show_info "choice is $net_choice"
+  net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
+  # config $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
+  net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
+  net_MacAddr=$(ifconfig $net_interface | grep 'HW' | sed 's/^.*HWaddr //g') 
+  show_info "net_address is $net_address"
+  show_info "net_MacAddr is $net_MacAddr"
+  fi
+
+  debug_info "ssh nutchuser@$1 echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/nutch_nodes"
+  su nutchuser -c "ssh nutchuser@$1 echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/nutch_nodes"
 
 #su nutchuser -c expect -c "spawn ssh nutchuser@$1
