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

Last change on this file since 158 was 158, checked in by shunfa, 14 years ago
  1. 修正clinet tar.gz包及路徑
  2. 修正ip及hostname
  3. 新增function: debug_echo
  4. 新增ssh-add
  5. 新增紀錄mac address

註:所有功能目前僅分別測試單一function

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