source: nutchez-0.2/src/shell/install_func.sh @ 218

Last change on this file since 218 was 218, checked in by waue, 14 years ago

更改 nutchez-0.2pack 的版本

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