Index: nutchez-0.1/bin/nutchez
===================================================================
--- nutchez-0.1/bin/nutchez	(revision 91)
+++ nutchez-0.1/bin/nutchez	(revision 94)
@@ -12,18 +12,81 @@
   export JAVA_HOME=/usr/lib/jvm/java-6-sun
   export NUTCH_HOME=/opt/nutch
-#  export HADOOP_HOME=/opt/nutch
   export NUTCH_CONF_DIR=~/.nutchez/conf
-#  export HADOOP_CONF_DIR=~/.nutchez/conf
   export NUTCH_LOG_DIR=~/.nutchez/log
 
+. /opt/nutch/bin/nutchez-func.sh
+
+init_nutchez
 
 
+tfile=`tempfile 2>/dev/null` || tfile=/tmp/test$$
+trap "rm -f $tfile" 0 1 2 5 15
 
-. /opt/nutch/bin/nutchez-func.sh
-#. ~/.nutchez/hadoop-env.sh
+$DIALOG --backtitle "Developed By NCHC" --clear --item-help --title "NutchEz 雛型版" \
+        --menu " 你好，歡迎使用NutchEz！ \n\
+這套軟體是用來打造專屬於你的搜尋引擎 \n\
+你有網頁不希望被公開的搜尋引擎找到， \n\
+卻又希望能有個搜尋介面的困擾嗎？ \n\
+用NutchEz就對了！因為他操作簡單， \n\
+除了基本的網頁以外，還支援多種格式（ppt,doc,txt...） \n\
+並且是開源碼軟體，完全免費，安全無虞\n\
+趕快來使用看看吧!\n\n\
+          選擇你要的模式:" 20 60 4 \
+        "1"  "開始建構搜尋內容"    "透過NutchEz來建構專屬於你自己所需的內容的搜尋引擎" \
+        "2"  "開啟或關閉NutchEz的網頁伺服器"  "若您之前已經執行完1之後才需做網頁伺服器的管理" 2> $tfile
 
+rev=$?
 
+MAIN_CHOISE=`cat $tfile`
 
-init_nutchez
+case $rev in
+  0)
+    echo_dialog_v "OK '$MAIN_CHOISE' chosen.";;
+  1)
+    echo_dialog_v "Cancel pressed."
+    exit 0 ;;
+  2)
+    echo_dialog_v "HELP '$MAIN_CHOISE' chosen.";;
+  255)
+    echo_dialog_v "ESC pressed.";;
+  *)
+    echo_dialog_v "Unexpected code $MAIN_CHOISE";;
+esac
+
+if [ $MAIN_CHOISE -eq 2 ];then
+
+  pid_tc=$(ps axw -eo pid,command |\
+  grep "catalina" | grep "java" |\
+  grep "start" | awk '{print $1}')
+  if [ -z "$pid_tc" ]; then
+      echo_dialog_v "0. pid = $pid_tc ! no another toddmcat is running"
+
+      $DIALOG --title "你的NutchEz網頁伺服器沒打開.." --clear \
+        --yesno "\n 要開啟NutchEz的網頁伺服器嗎？ \n" 15 61
+      if [ $? -eq 0 ];then
+          ~/.nutchez/tomcat/bin/startup.sh
+	  PORT=`cat ~/.nutchez/sav/n.tomcat.txt`
+          $DIALOG --msgbox "已經試著開啟瀏覽伺服器，你可以瀏覽這個網址看看: \n  http://localhost:$PORT" 0 0
+      else 
+	  $DIALOG --msgbox "你選擇不要打開瀏覽伺服器！" 0 0
+      fi
+      
+  else
+      echo_dialog_v "0. tomcat had been started and the pid is $pid_tc"
+
+      $DIALOG --title "偵測到NutchEz的網頁伺服器正在運作.." --clear \
+        --yesno "\n 你要關閉他嗎？ \n" 15 61
+      if [ $? -eq 0 ];then
+          ~/.nutchez/tomcat/bin/shutdown.sh
+	  kill -9 $pid_tc
+          $DIALOG --msgbox "已經試著關閉NutchEz網頁伺服器" 0 0
+      else 
+          $DIALOG --msgbox "你選擇不要關閉瀏覽伺服器！" 0 0
+      fi
+
+  fi
+  exit 0
+
+elif [ $MAIN_CHOISE -eq 1 ];then
 
 CHECK=0
@@ -35,5 +98,5 @@
     show_urls
     URL=$?
-    echo_vb "2.2 show_urls return $URL"
+    echo_dialog_v "2.2 show_urls return $URL"
     
 # add or delete url:  ok , exit
@@ -63,8 +126,12 @@
   setup_tomcat
 
+  # continue last search
+  if [ -e ~/.nutchez/search ];then
+    continue_previous
+  fi
   # show the final checklist
   final_confirm
   FC=$?
-  echo_vb "6.3 final confirm return = $FC "
+  echo_dialog_v "6.3 final confirm return = $FC "
   #   START , back, cancel
   # start =0 , back =1 
@@ -90,5 +157,5 @@
       ;;
     255)
-      echo_vb "ESC pressed !!"
+      echo_dialog_v "ESC pressed !!"
       ;;
   esac
@@ -108,2 +175,10 @@
 # Done 
 
+
+
+
+else
+
+  echo_dialog_v "Main Choise is $MAIN_CHOISE ! Error !!"
+
+fi
Index: nutchez-0.1/bin/nutchez-func.sh
===================================================================
--- nutchez-0.1/bin/nutchez-func.sh	(revision 91)
+++ nutchez-0.1/bin/nutchez-func.sh	(revision 94)
@@ -6,5 +6,6 @@
 
 
-: ${DIALOG=dialog}
+#DIALOG='dialog --backtitle "     NutchEz Setup Menu           -- powered by NCHC "'
+DIALOG=dialog
 
 # set 1 to display more for debug, 
@@ -39,5 +40,5 @@
 
 check_if_root() {
-   if [ ! "$UID" = "0" ]; then
+   if [ ! "$UID" -eq "0" ]; then
      echo_dialog_v "Hi [$LOGNAME] !! "
      echo_dialog_v "You need to run this script \"`basename $0`\" as root."
@@ -71,4 +72,13 @@
 
   cp ~/.nutchez/sav/n.urls.txt ~/.nutchez/urls/urls.txt
+
+  if [ $NOCONTINUE -eq 1 ]; then
+    echo_dialog_v " delete the ~/.nutchez/search/*"
+    DATE=`date +%y%m%d%H%M%S`
+    mv ~/.nutchez/search ~/.nutchez/search-$DATE
+    $DIALOG --msgbox "上次搜尋的結果改放到 ~/.nutchez/search-$DATE " 0 0
+    rm -f /tmp/search
+#    rm -rf ~/.nutchez/search/*
+  fi
 
   if [ -e ~/.nutchez/conf/nutch-site.xml ] ; then
@@ -100,5 +110,5 @@
   echo_dialog_v "2.1 test_file ~/.nutchez/sav return : $?"
   # dialog begin
-  dialog --title "The URLS that you want" --editbox ~/.nutchez/sav/n.urls.txt 16 51 2>/tmp/n.urls.tmp
+  dialog --title "請輸入你要抓取的網址（一行一個網址）" --editbox ~/.nutchez/sav/n.urls.txt 16 51 2>/tmp/n.urls.tmp
   RET=$?
   echo_dialog_v "2.1 cat url: `cat /tmp/n.urls.tmp`"
@@ -110,5 +120,5 @@
   echo_dialog_v "3. setup_robot"
   # dialog
-  dialog --nocancel --inputbox " This agent name \n" 16 51 "`cat ~/.nutchez/sav/n.robot.txt`" 2>/tmp/n.robot.tmp
+  dialog --title "設定機器人名稱" --nocancel --inputbox " 這個爬網機器人，你要將他取名為：\n\n (ps: 這個設定只是禮貌性宣告，並不會對結果造成影響) \n" 16 55 "`cat ~/.nutchez/sav/n.robot.txt`" 2>/tmp/n.robot.tmp
   echo_dialog_v "3.1 cat robot : `cat /tmp/n.robot.tmp`"
 }
@@ -117,5 +127,5 @@
   echo_dialog_v "4. setup_crawler"
   test_file ~/.nutchez/sav/n.crawler.txt
-  dialog --nocancel --inputbox " Depth  \n " 16 51 "`cat ~/.nutchez/sav/n.crawler.txt`" 2>/tmp/n.crawler.tmp
+  dialog --title "設定抓取深度" --nocancel --inputbox " 對於每個網址，你需要NutchEz爬多深呢？\n\n (ps: 初次體驗建議將深度設為1來感受需要多久)  \n " 16 51 "`cat ~/.nutchez/sav/n.crawler.txt`" 2>/tmp/n.crawler.tmp
   echo_dialog_v "4.1 cat robot : `cat /tmp/n.robot.tmp`"
 }
@@ -124,25 +134,51 @@
   echo_dialog_v "5. setup_tomcat"
   test_file ~/.nutchez/sav/n.tomcat.txt
-  dialog --nocancel --inputbox " explorer port \n " 16 51 "`cat ~/.nutchez/sav/n.tomcat.txt`" 2>/tmp/n.tomcat.tmp
+  dialog --title "設定網頁伺服器" --nocancel --inputbox " 你希望NutchEz將網頁伺服器開在哪個port \n\n (ps: 請選擇一個沒用到的port以免造成衝突 \n 也請盡量不要設成80以免造成你誤以為是apache的混淆) \n " 16 51 "`cat ~/.nutchez/sav/n.tomcat.txt`" 2>/tmp/n.tomcat.tmp
   echo_dialog_v "5.1 cat tomcat : `cat /tmp/n.tomcat.tmp`"
 }
 
+continue_previous () {
+  echo_dialog_v "6. setup_tomcat"
+$DIALOG --title "清除上次搜尋" --clear \
+        --yesno "你是否要清除上一次爬網所得的結果，\n否則將加入到URL列裡增加搜尋負擔 \n\n ps: 選no的話，會跑相當相當久，\n 請慎重考慮之\n" 16 51
+
+case $? in
+  0)
+    NOCONTINUE=1;;
+  1)
+    NOCONTINUE=0;;
+  255)
+    echo "ESC pressed.";;
+esac
+echo_dialog_v " 6continue = $CONTINUE"
+}
+
 final_confirm () {
-  echo_dialog_v "6. final_confirm : start =0 , back =1 "
+  echo_dialog_v "7. final_confirm : start =0 , back =1 "
   tempfile=/tmp/n.finalcheck.tmp
 
-  echo " \n 1. The url list is : \n " > $tempfile
+  echo " \n 1. 你所選擇要爬取的網址為 : \n " > $tempfile
   cat /tmp/n.urls.tmp >> $tempfile
-  echo " \n 2. The robot name is : \n" >> $tempfile
+  echo " \n\n 2. 對於這個爬網機器人，你取名為 : \n" >> $tempfile
   cat /tmp/n.robot.tmp >> $tempfile
-  echo " \n 3. The crawled depth is : \n " >> $tempfile
+  echo " \n\n 3. 爬網的深度，你設定為 : \n " >> $tempfile
   cat /tmp/n.crawler.tmp >> $tempfile
-  echo " \n 4. The explorer port is : \n " >> $tempfile
+  echo " \n\n 4. NutchEz將會把你的搜尋結果呈現在這個Port : \n " >> $tempfile
   cat /tmp/n.tomcat.tmp >> $tempfile
-
+  if [ $NOCONTINUE -eq 0 ];then
+    echo " \n\n 5. 是否要清除上一次的收尋結果 : \n " >> $tempfile
+    echo_dialog_v " 7continue = $CONTINUE"
+    echo "NO" >> $tempfile
+  elif [ $NOCONTINUE -eq 1 ];then
+    echo " \n\n 5. 是否要清除上一次的收尋結果繼續搜尋 : \n " >> $tempfile
+    echo_dialog_v " 7continue = $CONTINUE"
+    echo "YES" >> $tempfile
+  else
+    echo_dialog_v " 無資料可匯入 "
+  fi
   MSG=`cat $tempfile`
-  echo_dialog_v "6.1 final message :\n $MSG"
+  echo_dialog_v "7.1 final message :\n $MSG"
   #read READ
-  $DIALOG --title "Check It !!" --clear \
+  $DIALOG --title "請檢查你的選擇 ! \n\n 若所有的設定都是正確的，你可以按 \"ok\",\n 若你按了 \"reset\" 則會重頭開始設定, \n 若你選擇 \"exit\" 則會跳出NutchEz的設定選單 \n ps: reset 與 exit都不會把資料記成預設值，請放心使用 " --clear \
         --extra-button --extra-label "reset" --ok-label "ok" --cancel-label "exit" \
         --yesno "$MSG" 26 51
@@ -179,18 +215,19 @@
 
   pid_tc=$(ps axw -eo pid,command |\
- grep "catalina.startup.Bootstrap" |\
- grep "start" | awk '{print $1}')
+  grep "catalina" | grep "java" |\
+  grep "start" | awk '{print $1}')
   if [ -z "$pid_tc" ]; then
-      echo "starting tomcat"
+      echo_dialog_v "no another tomcat is running"
   else
-      echo "tomcat had been started and the pid is $pid_tc"
-      echo "stop it first"
+      echo_dialog_v "tomcat had been started and the pid is $pid_tc"
+      echo_dialog_v "stop it first"
       kill -9 $pid_tc
       if [ -z $? ];then
-	  echo " tomcat ($pid_tc) is  killed ..."
+	  echo_dialog_v " tomcat ($pid_tc) is  killed ..."
       else
-	  echo "kill error ..." 
+	  echo_dialog_v "kill error ..." 
       fi
   fi
+  echo "Starting Tomcat ...."
   ~/.nutchez/tomcat/bin/startup.sh
   sleep 3
@@ -201,10 +238,10 @@
   FIREFOX=`which firefox`
   RET=$?
-  if [ $RET == 0 ];then 
+  if [ $RET -eq 0 ];then 
     $FIREFOX -D 0.0 http://localhost:$PORT
     RET=$?
   fi
-  if ! [ $RET == 0 ];then
-    $DIALOG --msgbox "Congratulations! \n you can explore the url: \n  http://localhost:$PORT" 0 0 
-  fi
-}
+  if ! [ $RET -eq 0 ];then
+    $DIALOG --msgbox "恭喜你已經完成了! \n 你可以用瀏覽器瀏覽: \n  http://host_ip:$PORT" 0 0 
+  fi
+}
