source: nutchez-0.2/src/test/install_func.sh @ 213

Last change on this file since 213 was 213, checked in by shunfa, 14 years ago
  1. 修改master_install source 語言鏈結
  2. 修改移除時, 還原/etc/hosts至安裝NutchEZ前的版本
  3. 修改中文語言檔對應的變數
  • Property svn:executable set to *
File size: 14.9 KB
RevLine 
[116]1#!/bin/bash
[213]2source $Work_Path/lang_link
[117]3####### garbage here #############
[116]4function mainFunction ( )
5{
6echo "$Good"
7}
8function braBraBra ( )
9{
10echo "$Bra_Bra_Bra"
11}
[117]12####### garbage end ###############
13
[158]14# shell檔及壓縮檔在同一目錄中
15
16####### 環境變數section###########
[137]17User_HOME=/home/nutchuser/nutchez
18NutchEZ_HOME=/opt/nutchez
19Nutch_HOME=$NutchEZ_HOME/nutch
20Tomcat_HOME=$NutchEZ_HOME/tomcat
21Index_DB=$User_HOME/search
[158]22Admin_email=nutchuser@nutch
[163]23Start_PATH=`pwd`
24MasterIP_Address=`/sbin/ifconfig eth0 | grep 'inet addr' |  sed 's/^.*addr://g' | sed 's/Bcast.*$//g' | sed 's/ .*// '` 
25net_MacAddr=`/sbin/ifconfig eth0 | grep 'HW' | sed 's/^.*HWaddr //g'`
[125]26
[158]27######function section section#######
28
[195]29##########  echo function  ##########
[164]30function debug_info () {
[158]31  if [ $? -eq 0 ]; then
[164]32    echo -e "\033[1;35;40m info - $1 \033[0m"
33  fi
34}
35
36
37function show_info () {
38  if [ $? -eq 0 ]; then
[158]39    echo -e "\033[1;32;40m $1 \033[0m"
40  fi
41}
[195]42##########end echo function ##########
[158]43
[195]44function choose_lang(){
[158]45
[195]46lang=$(locale | grep 'LANG=' | cut -d "=" -f2)
47
48# Default: source english
49. $Work_Path/install_lang.en
50# if locale is zh then source chinese
51echo $lang | grep 'zh' >> /dev/null && source $Work_Path/install_lang.zh
52
53# Ask language
54echo -e "\n$choose_lang_1"
55read -p "$choose_lang_2 " langChoice
56
57if [ $langChoice == "2" ]; then
58    source $Work_Path/install_lang.zh
59else
60    source $Work_Path/install_lang.en
61fi
62}
63
64function check_root(){
65  debug_info "check_root"
66  if [ $USER != "root" ]; then
[213]67    show_info "$MI_check_root_1"
[195]68    exit
69  fi
[213]70  show_info "$MI_check_root_2"
[195]71}
72
73function check_systemInfo(){
[213]74  debug_info "$MI_check_sys_1"
75  show_info "$MI_check_sys_2"
[195]76  Linux_Distribution=$(lsb_release -a 2> /dev/null | grep "Distributor ID:" | awk '{print $3}')
77  Linux_Version=$(lsb_release -a 2> /dev/null | grep "Release" | awk '{print $2}')
78  show_info "$Linux_Distribution , $Linux_Version"
79}
80
81function install_packages(){
82  # deb 系列系統
[213]83  debug_info "$MI_install_pack_1"
84  debug_info "$MI_install_pack_2"
[195]85  if [ "$Linux_Distribution" == "Ubuntu" ] || [ "$Linux_Distribution" == "Debian" ] ;then
[213]86    echo -e "\n$MI_install_pack_if_1\n"
[195]87    aptitude install -y expect ssh dialog
88  # rpm 系列系統
89  elif [ "$Linux_Distribution" == "Fedora" ] || [ "$Linux_Distribution" == "CentOS" ] ;then
[213]90    show_info "$MI_install_pack_if_2"
[195]91  else
[213]92    show_info "$MI_install_pack_if_2"
[195]93  fi
94}
95
96function check_nez_installed(){
[213]97  debug_info "$MI_check_nez_1"
[206]98  if [ -d "/opt/nutchez" ]; then
[213]99    show_info "$MI_check_nez_2"
[195]100    exit
101  else
[213]102    show_info "$MI_check_nez_3"
[195]103  fi
104}
105
106function check_sunJava(){
[213]107  debug_info "$MI_check_sunJava_1"
108  debug_info "$MI_check_sunJava_2"
[195]109
110  javaPath="/usr"
111  yesno="no"
112  choice="3"
113
114  if [ -e $javaPath/bin/java ]; then
115    JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
116    JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
117    awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
118
119  if [ "$JAVA_org" == "" ]; then
[213]120    show_info "$MI_check_sunJava_if_1"
121    show_info "$MI_check_sunJava_if_2"
122    show_info "$MI_check_sunJava_if_3"
123    read -p "$MI_check_sunJava_if_4" choice
[195]124    case $choice  in
125      "1")
[213]126        show_info "$MI_check_sunJava_if_5"
[195]127        exit
128        ;;
129      "2")
[213]130        read -p "$MI_check_sunJava_if_6" javaPath
[195]131        ;;
132        "*")
133        exit
134        ;;
135        esac
136
137        if [ $choice == "2" ]; then
138          JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
139          JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
140          awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
141
142          if [ "$JAVA_org" == "" ]; then
[213]143            show_info "$MI_check_sunJava_if_7"
[195]144            exit
145            fi
146          fi
147        fi
148
149      large16=$(echo "$JAVA_version >= 1.6" | bc)
150      if [ "${large16}" == 0 ]; then
[213]151        show_info "$MI_check_sunJava_if_8"
[195]152        exit
153      fi
154
[213]155      show_info "$MI_check_sunJava_if_9"
[195]156  else
[213]157    show_info "$MI_check_sunJava_if_10"
[195]158    exit
159  fi
160
161  unset JAVA_org
162  unset JAVA_version
163}
164
165# 檢查是否有安裝openssh, openssh-server
166function check_ssh(){
[213]167  debug_info "$MI_check_ssh_1"
[195]168  if [ -e /usr/bin/ssh ]; then
[213]169    show_info "$MI_check_ssh_2"
[195]170  else
[213]171    show_info "$MI_check_ssh_3"
[195]172    exit
173  fi
174
175  if [ -e /usr/sbin/sshd ]; then
[213]176    show_info "$MI_check_ssh_4"
[195]177  else
[213]178    show_info "$MI_check_ssh_5"
[195]179    exit
180  fi
181}
182
183
184# 檢查是否有安裝dialog
185function check_dialog(){
[213]186  debug_info "$MI_check_dialog_1"
[195]187  if [ -e /usr/bin/dialog ]; then
[213]188    show_info "$MI_check_dialog_2"
[195]189  else
[213]190    show_info "$MI_check_dialog_3"
[195]191    exit
192  fi
193}
194
[158]195check_info () {
196  check_root
197  check_systemInfo
[173]198  install_packages
[158]199  check_nez_installed
200  check_sunJava
201  check_ssh
202  check_dialog
203}
204
[137]205function set_install_information () { 
[139]206  set_nutchuser_passwd
[150]207  select_eth
208  MasterIP_Address=$net_address
[139]209}
210
211function set_nutchuser_passwd () {
[213]212  read -sp "$MI_set_nutchuser_passwd_echo_1" Nutchuser_Passwd
[195]213# read -sp "Please enter nutchuser's password :  " Nutchuser_Passwd
[173]214  echo -e "\n"
[213]215  read -sp "$MI_set_nutchuser_passwd_echo_2" Nutchuser_Passwd2
[195]216# read -sp "Please enter nutchuser's password again:  " Nutchuser_Passwd2
[173]217  echo -e "\n"
[161]218  if [ $Nutchuser_Passwd != $Nutchuser_Passwd2 ]; then
[139]219    set_nutchuser_passwd
[137]220  fi
[117]221}
222
[206]223# 新增nutchuser 帳號時用 Nutchuser_Passwd 當密碼
224function creat_nutchuser_account(){
225  debug_info "$create_nutchuser_d1"
226  while [ "$Nutchuser_Passwd" != "$Nutchuser_Passwd2" ]
227  do
228      echo -e "\n"
229      read -sp "$create_nutchuser_1" Nutchuser_Passwd
230      echo 
231      read -sp "$create_nutchuser_2" Nutchuser_Passwd2
232      echo 
233        if [ "$Nutchuser_Passwd" == "$Nutchuser_Passwd2" ]; then
234          show_info "$create_nutchuser_3"
235        else
236          show_info "$create_nutchuser_4"
237        fi
238  done                                                                                                                         
239  unset Nutchuser_Passwd2
[150]240
[206]241  if [ $(cat /etc/passwd | grep nutchuser) ]; then
242    show_info "$create_nutchuser_s1"
243    expect -c "spawn passwd nutchuser
244    set timeout 1
245    expect \"*: \"
246    send \"$Nutchuser_Passwd\r\"
247    expect \"*: \"
248    send \"$Nutchuser_Passwd\r\"
249    expect eof"
250    else
251      show_info "$create_nutchuser_s2"
252      useradd -m nutchuser -s /bin/bash
253      expect -c "spawn passwd nutchuser
254      set timeout 1
255      expect \"*: \"
256      send \"$Nutchuser_Passwd\r\"
257      expect \"*: \"
258      send \"$Nutchuser_Passwd\r\"
259      expect eof"
260  fi
261}
262
[150]263function select_eth () {
264  net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
265  net_nu=$(echo $net_interfaces | wc -w)
266
267  # 若只有一個 eth 時
268  if [ "$net_nu" == "1" ]; then
269    net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
[158]270    net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
[150]271
272  # 若有多個 eth 時
273  else
274    declare -i i=1
[213]275    show_info "$MI_select_eth_echo_1"
[195]276#   show_info  "\nSystem have multiple network device, which network use for this machine: "
[150]277
278    for net in $net_interfaces
279      do
[164]280        show_info "($i$net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
[150]281        i=i+1
282      done
[213]283      read -p "$MI_select_eth_echo_2" net_choice
[195]284#     read -p "Please choice(1/2/3...): " net_choice
[150]285    if [ -z $net_choice ]; then
286      net_choice=1
287    fi
288
[213]289    show_info "$MI_select_eth_echo_3 $net_choice"
[195]290#   show_info "Your choice is $net_choice"
[150]291    net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
[163]292    #ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
[150]293    net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
[164]294    net_MacAddr=$(ifconfig $net_interface | grep 'HW' | sed 's/^.*HWaddr //g')
[195]295
[213]296    show_info "$MI_select_eth_echo_4 $net_address"
[195]297#   show_info "net_address is $net_address"
[213]298    show_info "$MI_select_eth_echo_5 $net_MacAddr"
[195]299#   show_info "net_MacAddr is $net_MacAddr"
[150]300  fi
301}
302
303
[206]304function show_master_info () {
[213]305  show_info "$MI_show_master_info_echo_1 $MasterIP_Address"
306  show_info "$MI_show_master_info_echo_2 $net_MacAddr"
[206]307
[195]308#  show_info "The Master IP Address is $MasterIP_Address"
309#  show_info "The Master MacAddr is $net_MacAddr"
[206]310}
[117]311
[139]312function make_ssh_key () {
[213]313  debug_info "$MI_make_ssh_key_echo_1"
[195]314# debug_info "Make ssh key(begin...)"
[139]315  su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""'
316  su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"
[158]317  su nutchuser -c "ssh-add /home/nutchuser/.ssh/id_rsa"
[213]318  debug_info "$MI_make_ssh_key_echo_2"
[195]319# debug_info "Make ssh key(done!)"
[139]320}
321
322
[137]323function set_haoop-site () {
[213]324  debug_info "$MI_set_haoop_site_echo_1"
[195]325# debug_info "set hadoop-site.xml(begin...)"
[137]326  cd $Nutch_HOME/conf/
[130]327  cat > hadoop-site.xml << EOF
[125]328<configuration>
[137]329  <property>
[125]330    <name>fs.default.name</name>
[137]331    <value>hdfs://$MasterIP_Address:9000</value>
332  </property>
333  <property>
[125]334    <name>mapred.job.tracker</name>
[137]335    <value>$MasterIP_Address:9001</value>
336  </property>
337  <property>
338    <name>hadoop.tmp.dir</name>
339    <value>/var/nutchez/nutch-nutchuser</value>
340  </property>
[125]341</configuration>
342EOF
[213]343  debug_info "$MI_set_haoop_site_echo_2"
[195]344# debug_info "set hadoop-site.xml(done!)"
[117]345}
346
[137]347# 修改nutch-site.xml中-http.agent.url, http.agent.email
348function set_nutch-site () {
[213]349  debug_info "$MI_set_nutch_site_echo_1"
[195]350# debug_info "set nutch-site.xml(begin...)"
[137]351  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.url' | sed 's/:.*//g'`
[213]352  debug_info "$MI_set_nutch_site_echo_2"
[195]353# debug_info "debug...http.agent.url line number = $Line_NO..."
[137]354  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
[213]355  debug_info "$MI_set_nutch_site_echo_3"
[195]356# debug_info "debug...edit http.agent.url delete line $((Line_NO+1))..."
[137]357  sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml
[213]358  debug_info "$MI_set_nutch_site_echo_4"
[195]359# debug_info "debug...edit http.agent.url done..."
[117]360
[137]361  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.email' | sed 's/:.*//g'`
[213]362  debug_info "$MI_set_nutch_site_echo_5"
[195]363# debug_info "debug...http.agent.email line number = $Line_NO..."
[126]364
[137]365  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
[213]366  debug_info "$MI_set_nutch_site_echo_6"
[195]367# debug_info "debug...edit http.agent.email delete line $((Line_NO+1))..."
[137]368  sed -i ''$Line_NO'a <value>'$Admin_email'</value>' $Nutch_HOME/conf/nutch-site.xml
[213]369  debug_info "$MI_set_nutch_site_echo_7"
[195]370# debug_info "debug...edit http.agent.email done..."
[213]371  debug_info "$MI_set_nutch_site_echo_8"
[195]372# debug_info "set nutch-site.xml(done!)"
[117]373}
374
[137]375function format_HDFS () {
[213]376  debug_info "$MI_format_HDFS_echo_1"
[139]377  su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format"
[213]378  debug_info "$MI_format_HDFS_echo_2"
[117]379}
380
[137]381function start_up_NutchEZ (){
[213]382  debug_info "$MI_start_up_NutchEZ_echo_1"
[195]383# debug_info "start up NutchEZ..."
[139]384  su nutchuser -c "$Nutch_HOME/bin/start-all.sh"
[117]385}
386
[164]387
388function set_hosts () {
[213]389  debug_info "$MI_set_hosts_echo_1"
390  cp /etc/hosts /home/nutchuser/nutchez/system/hosts.bak
[164]391  Line_NO=`cat /etc/hosts | grep -n $(hostname) | sed 's/:.*//g'`
392  content=$(cat /etc/hosts | awk 'NR=='$Line_NO'{printf "# " ; print}' )
393  sed -i ""$Line_NO"c $content" /etc/hosts
394  sed -i '1i '$MasterIP_Address' '$(hostname)'' /etc/hosts
395}
396
[137]397function Install_Nutch () {
[213]398  debug_info "$MI_install_Nutch_echo_1 $MasterIP_Address "
[195]399# debug_info "MasterIP_Address=$MasterIP_Address"
[213]400  debug_info "$MI_install_Nutch_echo_2 $(hostname)"
[195]401# debug_info "Master_Hostname=$(hostname)"
[171]402  su nutchuser -c "echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/system/nutch_nodes"
[164]403  set_hosts
[136]404  set_haoop-site
405  set_nutch-site
406}
407
[139]408
[140]409function client_PassMasterIPAddr () {
[163]410  cd $Start_PATH
[140]411  Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'`
[213]412  debug_info "$MI_client_PassMasterIPAddr_echo_1"
[195]413# debug_info "debug...Master IP here line number = $Line_NO..."
[140]414  sed -i ''$((Line_NO+1))'d' client_install
[213]415  debug_info "$MI_client_PassMasterIPAddr_echo_2"
[195]416# debug_info "debug...edit Master IP at line $((Line_NO+1))..."
[140]417  sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install
[213]418  debug_info "$MI_client_PassMasterIPAddr_echo_3"
[195]419# debug_info "edit client_install done..."
[140]420}
421
[163]422
[152]423function client_PassMaster_Hostname () {
[163]424  cd $Start_PATH
[152]425  Line_NO=`cat client_install | grep -n '# Master Hostname here' | sed 's/:.*//g'`
[213]426  debug_info "$MI_client_PassMaster_Hostname_echo_1"
[195]427# debug_info "debug...Master hostname here line number = $Line_NO..."
[152]428  sed -i ''$((Line_NO+1))'d' client_install
[213]429  debug_info "$MI_client_PassMaster_Hostname_echo_2"
[195]430# debug_info "debug...edit Master Hostname at line $((Line_NO+1))..."
[152]431  sed -i ''$Line_NO'a Master_Hostname='$(hostname)'' client_install
[213]432  debug_info "$MI_client_PassMaster_Hostname_echo_3"
[195]433# debug_info "edit client_install done..."
[152]434}
435
[204]436function client_PassMasterIPAddr_for_Remove () {
437  cd $Start_PATH
[206]438  Line_NO=`cat client_remove.sh | grep -n "# Master IP here" | sed 's/:.*//g'`
[204]439  sed -i ''$((Line_NO+1))'d' client_remove.sh
440  sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_remove.sh
441}
[163]442
[204]443
[139]444function make_client_install () {
[158]445  # 建立資料夾(用來存放client的安奘檔)
446  su nutchuser -c "mkdir $User_HOME/source"
447
[139]448  # 將Master_IP_Address給client
449  # 打包安裝目錄(不含tomcat)
[195]450 
[213]451  debug_info "$MI_make_client_install_echo_1"
[195]452# debug_info "function make_client_install..."
453
[140]454  client_PassMasterIPAddr
[152]455  client_PassMaster_Hostname
[204]456  client_PassMasterIPAddr_for_Remove
[158]457  cd /opt/nutchez/
[166]458  su nutchuser -c "tar -cvzf NutchezForClientOf_$MasterIP_Address.tar.gz  nutch"
[158]459 
460  # 複製檔案至$User_HOME/source目錄下
[166]461  mv NutchezForClientOf_$MasterIP_Address.tar.gz /home/nutchuser/nutchez/source
[163]462  cp $Start_PATH/client_install $Start_PATH/client_install_func.sh /home/nutchuser/nutchez/source
[213]463#  cp $Start_PATH/client_install $Start_PATH/client_install /home/nutchuser/nutchez/source
464#  cp $Start_PATH/client_install $Start_PATH/client_remove.sh /home/nutchuser/nutchez/source
465#  cp $Start_PATH/client_install $Start_PATH/lang* /home/nutchuser/nutchez/source
[131]466}
467
[137]468function start_up_tomcat () {
[213]469  debug_info "$MI_start_up_tomcat_echo_1"
[195]470# debug_info "start up tomcat..."
471
[164]472  i=10
[213]473  debug_info "$MI_start_up_tomcat_echo_2"
[164]474  until [ $i -lt 1 ]
475    do
476      sleep 1s
477      i=`expr $i - 1`
478    done
[139]479  su nutchuser -c "$Tomcat_HOME/bin/startup.sh"
[213]480  debug_info "$MI_start_up_tomcat_echo_3"
[195]481# debug_info "tomcat has been started..."
[117]482}
[144]483
[158]484###最後再整理###
[150]485# client簡易步驟
[195]486function client_install_commands () {
[213]487  show_info "$MI_client_install_commands_echo_1"
488  show_info "$MI_client_install_commands_echo_2"
489  show_info "$MI_client_install_commands_echo_3"
490  show_info "$MI_client_install_commands_echo_4"
491  show_info "$MI_client_install_commands_echo_5"
492  show_info "$MI_client_install_commands_echo_6"
493  show_info "$MI_client_install_commands_echo_7"
[195]494
495#  show_info "Client Install Command as Follows:"
496#  show_info "cd ~"
497#  show_info "mkdir nutchez_client_install"
498#  show_info "cd nutchez_client_install"
499#  show_info "scp nutchuser@$MasterIP_Address:/home/nutchuser/nutchez/source/* ."
500#  show_info "sudo su"
501#  show_info "./client_install"
[144]502}
Note: See TracBrowser for help on using the repository browser.