#!/bin/bash
# Author: WeiYu Chen <waue _at_ nchc org tw>
# License: GPL
# Description: Eazily use for Nutch
# .

# begining ..

#bin=`dirname "$0"`
#bin=`cd "$bin"; pwd`

#. "$bin"/nutchez-func.sh

  export NUTCH_CONF_DIR=~/.nutchez
  export HADOOP_CONF_DIR=~/.nutchez
  export NUTCH_LOG_DIR=~/.nutchez/log

if [ $JAVA_HOME = "" ];then
  export JAVA_HOME=/usr/lib/jvm/java-6-sun
fi

#  export NUTCH_HOME=/opt/nutch

. /opt/nutch/bin/nutchez-func.sh
#. ~/.nutchez/hadoop-env.sh



init_nutchez

CHECK=0
while [ $CHECK -eq 0 ]; do

  LOCK=1
  while [ $LOCK -eq 1 ]; do
    # milestone M1
    show_urls
    URL=$?
    echo_vb "2.2 show_urls return $URL"
    
# add or delete url:  ok , exit
# ok =0 , exit =1 

    if [ $URL -eq 0 ];then
      # go_to_M2
      LOCK=0
    else
      #return_console
      exit
    fi

  done
  # milestone M2

  # setup search engine personality
  #   next, back
  setup_robot

  # setup the crawl paramater
  #   next, back
  setup_crawler

  # setup the tomcat paramater
  #   next, back
  setup_tomcat

  # show the final checklist
  final_confirm
  FC=$?
  echo_vb "6.3 final confirm return = $FC "
  #   START , back, cancel
  # start =0 , back =1 
  #if [ $FC -eq 0 ];then
  case $FC in
    0)
      #go_to_M3
      CHECK=1
      # change temp file as conf file
      promote_tempfile
      ;;
    #else
    1)
      exit
      ;;
    3)
      #go_to_M1
      LOCK=1
      CHECK=0
      # temp file delete!
      clean_tempfile
      #return_console
      ;;
    255)
      echo_vb "ESC pressed !!"
      ;;
  esac
    #fi
done

set_nutchez_p

start_crawl

start_tomcat

# show result message

show_report

# Done 

