[66] | 1 | #!/bin/bash |
---|
| 2 | # Author: WeiYu Chen <waue _at_ nchc org tw> |
---|
| 3 | # License: GPL |
---|
| 4 | # Description: Eazily use for Nutch |
---|
| 5 | # . |
---|
| 6 | |
---|
| 7 | . $NUTCHEZ_SCRIPT_PATH/conf/hadoop-env.sh |
---|
| 8 | |
---|
| 9 | VERB=1 |
---|
| 10 | |
---|
| 11 | : ${DIALOG=dialog} |
---|
| 12 | |
---|
| 13 | #NEZ_DIR=/home/waue/.nutchez |
---|
| 14 | #NEZ_DIR_URL |
---|
| 15 | #NEZ_DIR_OTHER |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | echo_vb () { |
---|
| 19 | if [ $VERB -eq 1 ]; then |
---|
| 20 | $DIALOG --msgbox "$1" 16 51 |
---|
| 21 | fi |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | test_file () { |
---|
| 25 | if ! test -e "$1" ; then |
---|
| 26 | echo_vb "test_file: \n can not find $1" |
---|
| 27 | echo "" > $1 |
---|
| 28 | else |
---|
| 29 | echo_vb "test_file: \n Touch $1 ! \n Its content is \n `cat $1`" |
---|
| 30 | fi |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | check_if_root() { |
---|
| 34 | if [ ! "$UID" = "0" ]; then |
---|
| 35 | echo_vb "Hi [$LOGNAME] !! " |
---|
| 36 | echo_vb "You need to run this script \"`basename $0`\" as root." |
---|
| 37 | exit 1 |
---|
| 38 | fi |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | promote_tempfile () { |
---|
| 42 | echo_vb "7. chang tmp as txt" |
---|
| 43 | rm /tmp/n.*.txt |
---|
| 44 | mv /tmp/n.url.tmp /tmp/n.url.txt |
---|
| 45 | mv /tmp/n.robot.tmp /tmp/n.robot.txt |
---|
| 46 | mv /tmp/n.crawler.tmp /tmp/n.crawler.txt |
---|
| 47 | mv /tmp/n.tomcat.tmp /tmp/n.tomcat.txt |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | clean_tempfile () { |
---|
| 51 | echo_vb "7. delete tmp" |
---|
| 52 | rm /tmp/n.*.tmp |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | show_urls (){ |
---|
| 58 | # show urls : ok =0 ,cancel = 1 |
---|
| 59 | echo_vb "2. show_urls !" |
---|
| 60 | test_file /tmp/n.url.txt |
---|
| 61 | echo_vb "2.1 test_file /tmp/n.url.txt return : $?" |
---|
| 62 | # dialog begin |
---|
| 63 | dialog --editbox /tmp/n.url.txt 16 51 2>/tmp/n.url.tmp |
---|
| 64 | RET=$? |
---|
| 65 | echo_vb "2.1 cat url: `cat /tmp/n.url.tmp`" |
---|
| 66 | return $RET |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | setup_robot () { |
---|
| 70 | test_file /tmp/n.robot.txt |
---|
| 71 | echo_vb "3. setup_robot" |
---|
| 72 | # dialog |
---|
| 73 | dialog --nocancel --inputbox " This agent name \n" 16 51 "`cat /tmp/n.robot.txt`" 2>/tmp/n.robot.tmp |
---|
| 74 | echo_vb "3.1 cat robot : `cat /tmp/n.robot.tmp`" |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | setup_crawler () { |
---|
| 78 | echo_vb "4. setup_crawler" |
---|
| 79 | test_file /tmp/n.crawler.txt |
---|
| 80 | dialog --nocancel --inputbox " Depth \n " 16 51 "`cat /tmp/n.crawler.txt`" 2>/tmp/n.crawler.tmp |
---|
| 81 | echo_vb "4.1 cat robot : `cat /tmp/n.robot.tmp`" |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | setup_tomcat () { |
---|
| 85 | echo_vb "5. setup_tomcat" |
---|
| 86 | test_file /tmp/n.tomcat.txt |
---|
| 87 | dialog --nocancel --inputbox " explorer port \n " 16 51 "`cat /tmp/n.tomcat.txt`" 2>/tmp/n.tomcat.tmp |
---|
| 88 | echo_vb "5.1 cat tomcat : `cat /tmp/n.tomcat.tmp`" |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | final_confirm () { |
---|
| 92 | echo_vb "6. final_confirm : start =0 , back =1 " |
---|
| 93 | tempfile=`tempfile 2>/dev/null` || tempfile=/tmp/n.finalcheck.tmp |
---|
| 94 | #trap "rm -f $tempfile" 0 1 2 5 15 |
---|
| 95 | |
---|
| 96 | echo " \n 1. The url list is : \n " > $tempfile |
---|
| 97 | cat /tmp/n.url.tmp >> $tempfile |
---|
| 98 | echo " \n 2. The robot name is : \n" >> $tempfile |
---|
| 99 | cat /tmp/n.robot.tmp >> $tempfile |
---|
| 100 | echo " \n 3. The crawled dipth is : \n " >> $tempfile |
---|
| 101 | cat /tmp/n.crawler.tmp >> $tempfile |
---|
| 102 | echo " \n 4. The explorer port is : \n " >> $tempfile |
---|
| 103 | cat /tmp/n.tomcat.tmp >> $tempfile |
---|
| 104 | |
---|
| 105 | MSG=`cat $tempfile` |
---|
| 106 | echo_vb "6.1 final message :\n $MSG" |
---|
| 107 | #read READ |
---|
| 108 | $DIALOG --title "Check It !!" --clear \ |
---|
| 109 | --yesno "$MSG" 16 51 |
---|
| 110 | RET=$? |
---|
| 111 | echo_vb "final return = $RET" |
---|
| 112 | return $RET |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | start_crawl () { |
---|
| 116 | echo_vb "7. start_crawl" |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | start_tomcat () { |
---|
| 120 | echo_vb "8. start_tomcat " |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | show_report () { |
---|
| 124 | echo_vb "9. show_report " |
---|
| 125 | } |
---|