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

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

修改執行順序

  • Property svn:executable set to *
File size: 7.8 KB
Line 
1#!/bin/bash
2source install_lang
3####### garbage here #############
4function mainFunction ( )
5{
6echo "$Good"
7}
8function braBraBra ( )
9{
10echo "$Bra_Bra_Bra"
11}
12####### garbage end ###############
13
14####### fafa code here ###########
15
16
17# shell檔及壓縮檔在同一目錄中
18
19
20####### 環境變數section###########
21User_HOME=/home/nutchuser/nutchez
22NutchEZ_HOME=/opt/nutchez
23Nutch_HOME=$NutchEZ_HOME/nutch
24Tomcat_HOME=$NutchEZ_HOME/tomcat
25Index_DB=$User_HOME/search
26Admin_email=nutchuser@nutch
27Start_PATH=`pwd`
28MasterIP_Address=`/sbin/ifconfig eth0 | grep 'inet addr' |  sed 's/^.*addr://g' | sed 's/Bcast.*$//g' | sed 's/ .*// '` 
29net_MacAddr=`/sbin/ifconfig eth0 | grep 'HW' | sed 's/^.*HWaddr //g'`
30
31######function section section#######
32
33
34function debug_info () {
35  if [ $? -eq 0 ]; then
36    echo -e "\033[1;35;40m info - $1 \033[0m"
37  fi
38}
39
40
41function show_info () {
42  if [ $? -eq 0 ]; then
43    echo -e "\033[1;32;40m $1 \033[0m"
44  fi
45}
46
47
48check_info () {
49  check_root
50  check_systemInfo
51  install_packages
52  check_nez_installed
53  check_sunJava
54  check_ssh
55  check_dialog
56}
57
58function set_install_information () { 
59  set_nutchuser_passwd
60  select_eth
61  MasterIP_Address=$net_address
62}
63
64function set_nutchuser_passwd () {
65  read -sp "Please enter nutchuser's password :  " Nutchuser_Passwd
66  echo -e "\n"
67  read -sp "Please enter nutchuser's password again:  " Nutchuser_Passwd2
68  echo -e "\n"
69  if [ $Nutchuser_Passwd != $Nutchuser_Passwd2 ]; then
70    set_nutchuser_passwd
71  fi
72}
73
74
75function select_eth () {
76  net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
77  net_nu=$(echo $net_interfaces | wc -w)
78
79  # 若只有一個 eth 時
80  if [ "$net_nu" == "1" ]; then
81    #ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
82    net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
83    net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
84    #echo "net_address is $net_address"
85    #echo "net_MacAddr is $net_MacAddr"
86
87  # 若有多個 eth 時
88  else
89    declare -i i=1
90    show_info  "\nSystem have multiple network device, which network use for this machine: "
91
92    for net in $net_interfaces
93      do
94        show_info "($i$net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
95        i=i+1
96      done
97
98      read -p "Please choice(1/2/3...): " net_choice
99    if [ -z $net_choice ]; then
100      net_choice=1
101    fi
102
103    show_info "Your choice is $net_choice"
104    net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
105    #ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
106    net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
107    net_MacAddr=$(ifconfig $net_interface | grep 'HW' | sed 's/^.*HWaddr //g')
108    show_info "net_address is $net_address"
109    show_info "net_MacAddr is $net_MacAddr"
110  fi
111}
112
113
114function show_info () {
115  show_info "The Master IP Address is $MasterIP_Address"
116  show_info "The Master MacAddr is $net_MacAddr"
117}
118
119function confirm_install_information () {
120  read -p "Please confirm your install infomation: 1.Yes 2.No  " confirm
121}
122
123function make_ssh_key () {
124  debug_info "Make ssh key(begin...)"
125  su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""'
126  su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"
127  su nutchuser -c "ssh-add /home/nutchuser/.ssh/id_rsa"
128  debug_info "Make ssh key(done!)"
129}
130
131
132function set_haoop-site () {
133  debug_info "set hadoop-site.xml(begin...)"
134  cd $Nutch_HOME/conf/
135  cat > hadoop-site.xml << EOF
136<configuration>
137  <property>
138    <name>fs.default.name</name>
139    <value>hdfs://$MasterIP_Address:9000</value>
140  </property>
141  <property>
142    <name>mapred.job.tracker</name>
143    <value>$MasterIP_Address:9001</value>
144  </property>
145  <property>
146    <name>hadoop.tmp.dir</name>
147    <value>/var/nutchez/nutch-nutchuser</value>
148  </property>
149</configuration>
150EOF
151  debug_info "set hadoop-site.xml(done!)"
152}
153
154# 修改nutch-site.xml中-http.agent.url, http.agent.email
155function set_nutch-site () {
156  debug_info "set nutch-site.xml(begin...)"
157  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.url' | sed 's/:.*//g'`
158  debug_info "debug...http.agent.url line number = $Line_NO..."
159  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
160  debug_info "debug...edit http.agent.url delete line $((Line_NO+1))..."
161  sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml
162  debug_info "debug...edit http.agent.url done..."
163
164  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.email' | sed 's/:.*//g'`
165  debug_info "debug...http.agent.email line number = $Line_NO..."
166
167  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
168  debug_info "debug...edit http.agent.email delete line $((Line_NO+1))..."
169  sed -i ''$Line_NO'a <value>'$Admin_email'</value>' $Nutch_HOME/conf/nutch-site.xml
170  debug_info "debug...edit http.agent.email done..."
171  debug_info "set nutch-site.xml(done!)"
172}
173
174function format_HDFS () {
175  debug_info "format HDFS..."
176  su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format"
177}
178
179function start_up_NutchEZ (){
180  debug_info "start up NutchEZ..."
181  su nutchuser -c "$Nutch_HOME/bin/start-all.sh"
182}
183
184
185function set_hosts () {
186  Line_NO=`cat /etc/hosts | grep -n $(hostname) | sed 's/:.*//g'`
187  content=$(cat /etc/hosts | awk 'NR=='$Line_NO'{printf "# " ; print}' )
188  sed -i ""$Line_NO"c $content" /etc/hosts
189  sed -i '1i '$MasterIP_Address' '$(hostname)'' /etc/hosts
190}
191
192function Install_Nutch () {
193  debug_info "MasterIP_Address=$MasterIP_Address"
194  debug_info "Master_Hostname=$(hostname)"
195  su nutchuser -c "echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/system/nutch_nodes"
196  set_hosts
197  set_haoop-site
198  set_nutch-site
199}
200
201
202function client_PassMasterIPAddr () {
203  cd $Start_PATH
204  Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'`
205  debug_info "debug...Master IP here line number = $Line_NO..."
206  sed -i ''$((Line_NO+1))'d' client_install
207  debug_info "debug...edit Master IP at line $((Line_NO+1))..."
208  sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install
209  debug_info "edit client_install done..."
210}
211
212
213function client_PassMaster_Hostname () {
214  cd $Start_PATH
215  Line_NO=`cat client_install | grep -n '# Master Hostname here' | sed 's/:.*//g'`
216  debug_info "debug...Master hostname here line number = $Line_NO..."
217  sed -i ''$((Line_NO+1))'d' client_install
218  debug_info "debug...edit Master Hostname at line $((Line_NO+1))..."
219  sed -i ''$Line_NO'a Master_Hostname='$(hostname)'' client_install
220  debug_info "edit client_install done..."
221}
222
223
224function make_client_install () {
225  # 建立資料夾(用來存放client的安奘檔)
226  su nutchuser -c "mkdir $User_HOME/source"
227
228  # 將Master_IP_Address給client
229  # 打包安裝目錄(不含tomcat)
230  debug_info "function make_client_install..."
231  client_PassMasterIPAddr
232  client_PassMaster_Hostname
233  cd /opt/nutchez/
234  su nutchuser -c "tar -cvzf NutchezForClientOf_$MasterIP_Address.tar.gz  nutch"
235 
236  # 複製檔案至$User_HOME/source目錄下
237  mv NutchezForClientOf_$MasterIP_Address.tar.gz /home/nutchuser/nutchez/source
238  cp $Start_PATH/client_install $Start_PATH/client_install_func.sh /home/nutchuser/nutchez/source
239}
240
241function start_up_tomcat () {
242  debug_info "start up tomcat..."
243  i=10
244  until [ $i -lt 1 ]
245    do
246      sleep 1s
247      debug_info "wait $i sec..."
248      i=`expr $i - 1`
249    done
250  su nutchuser -c "$Tomcat_HOME/bin/startup.sh"
251  debug_info "tomcat has been started..."
252}
253
254###最後再整理###
255# client簡易步驟
256function client_install_command () {
257  show_info "Client Install Command as Follows:"
258  show_info "cd ~"
259  show_info "mkdir nutchez_client_install"
260  show_info "cd nutchez_client_install"
261  show_info "scp nutchuser@$MasterIP_Address:/home/nutchuser/nutchez/source/* ."
262  show_info "sudo su"
263  show_info "./client_install"
264}
Note: See TracBrowser for help on using the repository browser.