source: nutchez-0.2/src/test/client_install_func.sh @ 140

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

單機安裝測試ok

  • Property svn:executable set to *
File size: 6.0 KB
Line 
1#!/bin/bash
2# Program:
3#   Functions for client_install.sh
4# Author:
5#   Waue, Shunfa, Rock {waue, shunfa, rock}@nchc.org.tw
6# History:
7#   2010/05/20  Rock    First release(0.1)
8
9# 正式版之後,記的將不必要的 echo 拿掉
10
11
12# 檢查執行這個程式的是否為root權限
13function check_root(){
14# 正式版後可拿掉此 echo
15echo -e "\n= check_root (debug) ="
16if [ $USER != "root" ]; then
17    echo -e "\nPlz Change root to execute it!!!"
18    exit
19fi
20# 正式版後可拿掉此 echo
21echo -e "Identify is root."
22}
23
24
25# 查出此主機的作業系統,以及版本
26function check_systemInfo(){
27echo -e "\n= check_systemInfo (debug) ="
28echo -e "\nYour system information are:"
29Linux_Distribution=$(lsb_release -a 2> /dev/null | grep "Distributor ID:" | awk '{print $3}')
30Linux_Version=$(lsb_release -a 2> /dev/null | grep "Release" | awk '{print $2}')
31echo $Linux_Distribution , $Linux_Version
32}
33
34
35# 安裝需要的相依套件 (目前只支援 deb 套件的系統自動安裝,yum或其他套件系統的則需手動安裝)
36function install_packages(){
37# deb 系列系統
38echo -e "\n= install_packages (debug) ="
39echo -e "\nCheck dependent packages"
40if [ "$Linux_Distribution" == "Ubuntu" ] || [ "$Linux_Distribution" == "Debian" ] ;then
41    aptitude install -y expect ssh dialog
42# rpm 系列系統
43elif [ "$Linux_Distribution" == "Fedora" ] || [ "$Linux_Distribution" == "CentOS" ] ;then
44    echo -e "Plz install expect, ssh, and dialog."
45fi 
46}
47
48
49# 檢查之前是否有安裝NutchEz
50# 目前先檢查是否有/opt/nutchez 這個資料夾即可
51function check_nez_installed(){
52echo -e "\n= chcheck_nez_installed (debug) ="
53if [ -d /opt/nutchez ]; then
54    echo -e "\nSystem already had NutchEz."
55    exit
56else
57    echo -e "\nSystem does not has NutchEz."
58fi
59}
60
61
62# 檢查是否有安裝sun java ,並檢查是否為jdk 1.6 以上版本
63# 4種判斷可能性 (1)系統沒安裝 JAVA (2)系統有安裝JAVA,但非sun版本
64# (3)系統有安裝但Sun Java 在非預設路徑下 (4)以正確安裝 Sun JAVA 預設路徑下
65function check_sunJava(){
66echo -e "\n= check_sunJava (debug) ="
67echo -e "\nNutchEz need Sun Java JDK 1.6.x or above version"
68javaPath="/usr/"
69
70test -e $javaPath/bin/java || read -p "Plz input specific Java path\
71(ex./opt/jvm/java-6-sun-1.6.0.20/): " javaPath
72
73if [ -e $javaPath/bin/java ]; then
74    JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
75    JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
76    awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
77
78    if [ "$JAVA_org" == "" ]; then 
79        echo "Java is not Sun version, plz install sun Java 1.6.X"
80        exit   
81    fi
82   
83    large16=$(echo "$JAVA_version >= 1.6" | bc)
84    if [ "${large16}" == 0 ]; then
85        echo "Java version is too old (it need 1.6.X above)"
86        exit
87    fi
88   
89    echo "System has Sun Java 1.6 above version."
90else
91    echo "Plz install Sun JAVA 1.6.X or above version"
92    exit
93fi
94
95unset JAVA_org
96unset JAVA_version
97}
98
99
100# 檢查是否有安裝openssh, openssh-server
101function check_ssh(){
102echo -e "\n= check_ssh (debug) ="
103if [ -e /usr/bin/ssh ]; then
104    echo -e "\nSystem has ssh."
105else
106    echo "Plz install ssh."
107    exit
108fi
109
110if [ -e /usr/sbin/sshd ]; then
111    echo "System has ssh Server (sshd)."
112else
113    echo "Plz install ssh Server (sshd)."
114    exit
115fi
116}
117
118
119# 檢查是否有安裝dialog
120function check_dialog(){
121echo -e "\n= check_dialog (debug) ="
122if [ -e /usr/bin/dialog ]; then
123    echo -e "\nSystem has dialog."
124else
125    echo "Plz install dialog."
126    exit
127fi
128}
129
130# scp nutchuser@master_ip:~ 把.ssh/目錄複製下來
131# 當使用者輸入nutchuser 密碼時,將此密碼紀錄到Nutchuser_Passwd
132# 此步驟若無法連到 master 則跳出
133function scp_master_nutchuser_sshkey(){
134echo -e "\n= scp_master_nutchuser_sshkey (debug) ="
135echo -e "mkdir -p /home/nutchuser/"
136mkdir -p /home/nutchuser/
137rm -fr /home/nutchuser/.ssh
138
139while [ ! -d "/home/nutchuser/.ssh" ]
140do
141    while [ "$Nutchuser_Passwd" != "$Nutchuser_Passwd2" ]
142    do
143        echo -e "\n"
144        read -p "Plz input nutchuser password of master node: " Nutchuser_Passwd
145        read -p "plz input nutchuser password, again: " Nutchuser_Passwd2
146            if [ "$1" == "$Nutchuser_Passwd2" ]; then
147                echo "Two Passwords match."
148            else
149                echo "two passwords do not match, plz re-input nutchuser's password."
150            fi
151    done
152   
153    unset Nutchuser_Passwd2
154
155    echo -e "scp nutchuser@$1:~/.ssh /home/nutchuser/"
156    expect -c "spawn scp -r -o StrictHostKeyChecking=no nutchuser@$1:~/.ssh /home/nutchuser/
157    expect \"*: \" { send \"$Nutchuser_Passwd\r\" }
158    expect \"*: \" { send_user \"Password is error\" }
159    expect eof"
160        if [ ! -d "/home/nutchuser/.ssh" ]; then
161            echo -e "\nPassword  is error, plz re-input nutchuser passwd of master node."
162        else
163            echo -e "\nscp correct."
164        fi
165        echo "chown -R nutchuser:nutchuser /home/nutchuser/.ssh"
166        chown -R nutchuser:nutchuser /home/nutchuser/.ssh
167done
168}
169
170
171# 新增nutchuser 帳號時用 Nutchuser_Passwd 當密碼
172function creat_nutchuser_account(){
173echo -e "\n= creat_nutchuser_account (debug) ="
174
175if [ $(cat /etc/passwd | grep nutchuser) ]; then
176    echo "System already has nutchuser, change nutchuser password."
177    expect -c "spawn passwd nutchuser
178    set timeout 1
179    expect \"*: \"
180    send \"$1\r\"
181    expect \"*: \"
182    send \"$1\r\"
183    expect eof"
184else
185    echo "Create nutchuser and change password."
186    useradd -m nutchuser -s /bin/bash
187    expect -c "spawn passwd nutchuser
188    set timeout 1
189    expect \"*: \"
190    send \"$1\r\"
191    expect \"*: \"
192    send \"$1\r\"
193    expect eof"
194fi
195}
196
197# 用scp 複製 master 的設定與安裝資料
198# 目前僅需做到能無礙的複製遠端的/opt/nutchez/到local的/opt/
199function scp_packages(){
200echo -e "\n= scp_packages (debug) ="
201chmod 777 /opt
202echo "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez/ /opt/"
203su nutchuser -c "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez/ /opt/"
204
205echo -e "\nchown -R nutchuser:nutchuser /opt/nutchez/"
206chown -R nutchuser:nutchuser /opt/nutchez/
207chmod 755 /opt
208}
Note: See TracBrowser for help on using the repository browser.