#!/bin/bash
# Author: WeiYu Chen <waue _at_ nchc org tw>
# License: GPL
# Description: Eazily use for Nutch
# .
export NUTCH_CONF_DIR=~/.nutchez
NUTCHEZ_SCRIPT_PATH="${NUTCHEZ_SCRIPT_PATH:-/opt/nutch}"

. ./nutchez-func.sh


# root ?
#check_if_root

# show url lists

setup_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
    #go_to_M3
    CHECK=1
    # change temp file as conf file
    promote_tempfile
  else
    #go_to_M1
    LOCK=1
    CHECK=0
    # temp file delete!
    clean_tempfile
    #return_console
  fi
done

start_crawl

start_tomcat

# show result message

show_report

# Done 

