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

Last change on this file since 203 was 203, checked in by shunfa, 14 years ago

修改語言檔

  • Property svn:executable set to *
File size: 12.7 KB
Line 
1#!/bin/bash
2source $Work_Path/install_lang
3####### garbage here #############
4function mainFunction ( )
5{
6echo "$Good"
7}
8function braBraBra ( )
9{
10echo "$Bra_Bra_Bra"
11}
12####### garbage end ###############
13
14# shell檔及壓縮檔在同一目錄中
15
16####### 環境變數section###########
17User_HOME=/home/nutchuser/nutchez
18NutchEZ_HOME=/opt/nutchez
19Nutch_HOME=$NutchEZ_HOME/nutch
20Tomcat_HOME=$NutchEZ_HOME/tomcat
21Index_DB=$User_HOME/search
22Admin_email=nutchuser@nutch
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'`
26
27######function section section#######
28
29##########  echo function  ##########
30function debug_info () {
31  if [ $? -eq 0 ]; then
32    echo -e "\033[1;35;40m info - $1 \033[0m"
33  fi
34}
35
36
37function show_info () {
38  if [ $? -eq 0 ]; then
39    echo -e "\033[1;32;40m $1 \033[0m"
40  fi
41}
42##########end echo function ##########
43
44function choose_lang(){
45
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
67    show_info "$check_root_1"
68    exit
69  fi
70  show_info "$check_root_2"
71}
72
73function check_systemInfo(){
74  debug_info "$check_sys_1"
75  show_info "$check_sys_2"
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 系列系統
83  debug_info "$install_pack_1"
84  debug_info "$install_pack_2"
85  if [ "$Linux_Distribution" == "Ubuntu" ] || [ "$Linux_Distribution" == "Debian" ] ;then
86    echo -e "\n$install_pack_if_1\n"
87    aptitude install -y expect ssh dialog
88  # rpm 系列系統
89  elif [ "$Linux_Distribution" == "Fedora" ] || [ "$Linux_Distribution" == "CentOS" ] ;then
90    show_info "$install_pack_if_2"
91  else
92    show_info "$install_pack_if_2"
93  fi
94}
95
96function check_nez_installed(){
97  debug_info "$check_nez_1"
98  if [ -d "opt/nutchez" ]; then
99    show_info "$check_nez_2"
100    exit
101  else
102    show_info "$check_nez_3"
103  fi
104}
105
106function check_sunJava(){
107  debug_info "$check_sunJava_1"
108  debug_info "$check_sunJava_2"
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
120    show_info "$check_sunJava_if_1"
121    show_info "$check_sunJava_if_2"
122    show_info "$check_sunJava_if_3"
123    read -p "$check_sunJava_if_4" choice
124    case $choice  in
125      "1")
126        show_info "$check_sunJava_if_5"
127        exit
128        ;;
129      "2")
130        read -p "$check_sunJava_if_6" javaPath
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
143            show_info "$check_sunJava_if_7"
144            exit
145            fi
146          fi
147        fi
148
149      large16=$(echo "$JAVA_version >= 1.6" | bc)
150      if [ "${large16}" == 0 ]; then
151        show_info "$check_sunJava_if_8"
152        exit
153      fi
154
155      show_info "$check_sunJava_if_9"
156  else
157    show_info "$check_sunJava_if_10"
158    exit
159  fi
160
161  unset JAVA_org
162  unset JAVA_version
163}
164
165# 檢查是否有安裝openssh, openssh-server
166function check_ssh(){
167  debug_info "$check_ssh_1"
168  if [ -e /usr/bin/ssh ]; then
169    show_info "$check_ssh_2"
170  else
171    show_info "$check_ssh_3"
172    exit
173  fi
174
175  if [ -e /usr/sbin/sshd ]; then
176    show_info "$check_ssh_4"
177  else
178    show_info "$check_ssh_5"
179    exit
180  fi
181}
182
183
184# 檢查是否有安裝dialog
185function check_dialog(){
186  debug_info "$check_dialog_1"
187  if [ -e /usr/bin/dialog ]; then
188    show_info "$check_dialog_2"
189  else
190    show_info "$check_dialog_3"
191    exit
192  fi
193}
194
195check_info () {
196  check_root
197  check_systemInfo
198  install_packages
199  check_nez_installed
200  check_sunJava
201  check_ssh
202  check_dialog
203}
204
205function set_install_information () { 
206  set_nutchuser_passwd
207  select_eth
208  MasterIP_Address=$net_address
209}
210
211function set_nutchuser_passwd () {
212  read -sp "$set_nutchuser_passwd_echo_1" Nutchuser_Passwd
213# read -sp "Please enter nutchuser's password :  " Nutchuser_Passwd
214  echo -e "\n"
215  read -sp "$set_nutchuser_passwd_echo_2" Nutchuser_Passwd2
216# read -sp "Please enter nutchuser's password again:  " Nutchuser_Passwd2
217  echo -e "\n"
218  if [ $Nutchuser_Passwd != $Nutchuser_Passwd2 ]; then
219    set_nutchuser_passwd
220  fi
221}
222
223
224function select_eth () {
225  net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
226  net_nu=$(echo $net_interfaces | wc -w)
227
228  # 若只有一個 eth 時
229  if [ "$net_nu" == "1" ]; then
230    net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
231    net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
232
233  # 若有多個 eth 時
234  else
235    declare -i i=1
236    show_info "$select_eth_echo_1"
237#   show_info  "\nSystem have multiple network device, which network use for this machine: "
238
239    for net in $net_interfaces
240      do
241        show_info "($i$net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
242        i=i+1
243      done
244      read -p "$select_eth_echo_2" net_choice
245#     read -p "Please choice(1/2/3...): " net_choice
246    if [ -z $net_choice ]; then
247      net_choice=1
248    fi
249
250    show_info "$select_eth_echo_3"
251#   show_info "Your choice is $net_choice"
252    net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
253    #ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
254    net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
255    net_MacAddr=$(ifconfig $net_interface | grep 'HW' | sed 's/^.*HWaddr //g')
256
257    show_info "$select_eth_echo_4"
258#   show_info "net_address is $net_address"
259    show_info "$select_eth_echo_5"
260#   show_info "net_MacAddr is $net_MacAddr"
261  fi
262}
263
264
265#function show_master_info () {
266#  show_info "The Master IP Address is $MasterIP_Address"
267#  show_info "The Master MacAddr is $net_MacAddr"
268#}
269
270function make_ssh_key () {
271  debug_info "$make_ssh_key_echo_1"
272# debug_info "Make ssh key(begin...)"
273  su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""'
274  su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"
275  su nutchuser -c "ssh-add /home/nutchuser/.ssh/id_rsa"
276  debug_info "$make_ssh_key_echo_2"
277# debug_info "Make ssh key(done!)"
278}
279
280
281function set_haoop-site () {
282  debug_info "$set_haoop_site_echo_1"
283# debug_info "set hadoop-site.xml(begin...)"
284  cd $Nutch_HOME/conf/
285  cat > hadoop-site.xml << EOF
286<configuration>
287  <property>
288    <name>fs.default.name</name>
289    <value>hdfs://$MasterIP_Address:9000</value>
290  </property>
291  <property>
292    <name>mapred.job.tracker</name>
293    <value>$MasterIP_Address:9001</value>
294  </property>
295  <property>
296    <name>hadoop.tmp.dir</name>
297    <value>/var/nutchez/nutch-nutchuser</value>
298  </property>
299</configuration>
300EOF
301  debug_info "$set_haoop_site_echo_2"
302# debug_info "set hadoop-site.xml(done!)"
303}
304
305# 修改nutch-site.xml中-http.agent.url, http.agent.email
306function set_nutch-site () {
307  debug_info "$set_haoop_site_echo_1"
308# debug_info "set nutch-site.xml(begin...)"
309  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.url' | sed 's/:.*//g'`
310  debug_info "$set_haoop_site_echo_2"
311# debug_info "debug...http.agent.url line number = $Line_NO..."
312  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
313  debug_info "$set_haoop_site_echo_3"
314# debug_info "debug...edit http.agent.url delete line $((Line_NO+1))..."
315  sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml
316  debug_info "$set_haoop_site_echo_4"
317# debug_info "debug...edit http.agent.url done..."
318
319  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.email' | sed 's/:.*//g'`
320  debug_info "$set_haoop_site_echo_5"
321# debug_info "debug...http.agent.email line number = $Line_NO..."
322
323  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
324  debug_info "$set_haoop_site_echo_6"
325# debug_info "debug...edit http.agent.email delete line $((Line_NO+1))..."
326  sed -i ''$Line_NO'a <value>'$Admin_email'</value>' $Nutch_HOME/conf/nutch-site.xml
327  debug_info "$set_haoop_site_echo_7"
328# debug_info "debug...edit http.agent.email done..."
329  debug_info "$set_haoop_site_echo_8"
330# debug_info "set nutch-site.xml(done!)"
331}
332
333function format_HDFS () {
334  debug_info "$format_HDFS_echo_1"
335  su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format"
336  debug_info "$format_HDFS_echo_2"
337}
338
339function start_up_NutchEZ (){
340  debug_info "$start_up_NutchEZ_echo_1"
341# debug_info "start up NutchEZ..."
342  su nutchuser -c "$Nutch_HOME/bin/start-all.sh"
343}
344
345
346function set_hosts () {
347  debug_info "$set_hosts_echo_1"
348  Line_NO=`cat /etc/hosts | grep -n $(hostname) | sed 's/:.*//g'`
349  content=$(cat /etc/hosts | awk 'NR=='$Line_NO'{printf "# " ; print}' )
350  sed -i ""$Line_NO"c $content" /etc/hosts
351  sed -i '1i '$MasterIP_Address' '$(hostname)'' /etc/hosts
352}
353
354function Install_Nutch () {
355  debug_info "$install_Nutch_echo_1"
356# debug_info "MasterIP_Address=$MasterIP_Address"
357  debug_info "$install_Nutch_echo_2"
358# debug_info "Master_Hostname=$(hostname)"
359  su nutchuser -c "echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/system/nutch_nodes"
360  set_hosts
361  set_haoop-site
362  set_nutch-site
363}
364
365
366function client_PassMasterIPAddr () {
367  cd $Start_PATH
368  Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'`
369  debug_info "$client_PassMasterIPAddr_echo_1"
370# debug_info "debug...Master IP here line number = $Line_NO..."
371  sed -i ''$((Line_NO+1))'d' client_install
372  debug_info "$client_PassMasterIPAddr_echo_2"
373# debug_info "debug...edit Master IP at line $((Line_NO+1))..."
374  sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install
375  debug_info "$client_PassMasterIPAddr_echo_3"
376# debug_info "edit client_install done..."
377}
378
379
380function client_PassMaster_Hostname () {
381  cd $Start_PATH
382  Line_NO=`cat client_install | grep -n '# Master Hostname here' | sed 's/:.*//g'`
383  debug_info "$client_PassMaster_Hostname_echo_1"
384# debug_info "debug...Master hostname here line number = $Line_NO..."
385  sed -i ''$((Line_NO+1))'d' client_install
386  debug_info "$client_PassMaster_Hostname_echo_2"
387# debug_info "debug...edit Master Hostname at line $((Line_NO+1))..."
388  sed -i ''$Line_NO'a Master_Hostname='$(hostname)'' client_install
389  debug_info "$client_PassMaster_Hostname_echo_3"
390# debug_info "edit client_install done..."
391}
392
393
394function make_client_install () {
395  # 建立資料夾(用來存放client的安奘檔)
396  su nutchuser -c "mkdir $User_HOME/source"
397
398  # 將Master_IP_Address給client
399  # 打包安裝目錄(不含tomcat)
400 
401  debug_info "$make_client_install_echo_1"
402# debug_info "function make_client_install..."
403
404  client_PassMasterIPAddr
405  client_PassMaster_Hostname
406  cd /opt/nutchez/
407  su nutchuser -c "tar -cvzf NutchezForClientOf_$MasterIP_Address.tar.gz  nutch"
408 
409  # 複製檔案至$User_HOME/source目錄下
410  mv NutchezForClientOf_$MasterIP_Address.tar.gz /home/nutchuser/nutchez/source
411  cp $Start_PATH/client_install $Start_PATH/client_install_func.sh /home/nutchuser/nutchez/source
412}
413
414function start_up_tomcat () {
415  debug_info "$start_up_tomcat_echo_1"
416# debug_info "start up tomcat..."
417
418  i=10
419  until [ $i -lt 1 ]
420    do
421      sleep 1s
422      debug_info "$start_up_tomcat_echo_2"
423#     debug_info "wait $i sec..."
424      i=`expr $i - 1`
425    done
426  su nutchuser -c "$Tomcat_HOME/bin/startup.sh"
427  debug_info "$start_up_tomcat_echo_3"
428# debug_info "tomcat has been started..."
429}
430
431###最後再整理###
432# client簡易步驟
433function client_install_commands () {
434  show_info "$client_install_commands_echo_1"
435  show_info "$client_install_commands_echo_2"
436  show_info "$client_install_commands_echo_3"
437  show_info "$client_install_commands_echo_4"
438  show_info "$client_install_commands_echo_5"
439  show_info "$client_install_commands_echo_6"
440  show_info "$client_install_commands_echo_7"
441
442
443#  show_info "Client Install Command as Follows:"
444#  show_info "cd ~"
445#  show_info "mkdir nutchez_client_install"
446#  show_info "cd nutchez_client_install"
447#  show_info "scp nutchuser@$MasterIP_Address:/home/nutchuser/nutchez/source/* ."
448#  show_info "sudo su"
449#  show_info "./client_install"
450}
Note: See TracBrowser for help on using the repository browser.