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

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

修改install, install_func.sh, client_install_func.sh(新增帳號timeout部份)

  • Property svn:executable set to *
File size: 6.3 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
131# 檢查是否安裝 php 5.5
132function check_php(){
133echo -e "\n= check_php (debug) ="
134if [ "$(php -v 2>/dev/null | grep "PHP 5" | awk '{print $2}' | cut -d "." -f1)" == 5 ]; then
135    echo -e "\nPHP'version is 5"
136else
137    echo -e "\nplz install PHP 5 version!"
138    exit
139fi
140}
141
142
143# scp nutchuser@master_ip:~ 把.ssh/目錄複製下來
144# 當使用者輸入nutchuser 密碼時,將此密碼紀錄到Nutchuser_Passwd
145# 此步驟若無法連到 master 則跳出
146function scp_master_nutchuser_sshkey(){
147echo -e "\n= scp_master_nutchuser_sshkey (debug) ="
148echo -e "mkdir -p /home/nutchuser/"
149mkdir -p /home/nutchuser/
150rm -fr /home/nutchuser/.ssh
151
152while [ ! -d "/home/nutchuser/.ssh" ]
153do
154    while [ "$Nutchuser_Passwd" != "$Nutchuser_Passwd2" ]
155    do
156        echo -e "\n"
157        read -p "Plz input nutchuser password of master node: " Nutchuser_Passwd
158        read -p "plz input nutchuser password, again: " Nutchuser_Passwd2
159            if [ "$1" == "$Nutchuser_Passwd2" ]; then
160                echo "Two Passwords match."
161            else
162                echo "two passwords do not match, plz re-input nutchuser's password."
163            fi
164    done
165   
166    unset Nutchuser_Passwd2
167
168    echo -e "scp nutchuser@$1:~/.ssh /home/nutchuser/"
169    expect -c "spawn scp -r -o StrictHostKeyChecking=no nutchuser@$1:~/.ssh /home/nutchuser/
170    expect \"*: \" { send \"$Nutchuser_Passwd\r\" }
171    expect \"*: \" { send_user \"Password is error\" }
172    expect eof"
173        if [ ! -d "/home/nutchuser/.ssh" ]; then
174            echo -e "\nPassword  is error, plz re-input nutchuser passwd of master node."
175        else
176            echo -e "\nscp correct."
177        fi
178        echo "chown -R nutchuser:nutchuser /home/nutchuser/.ssh"
179        chown -R nutchuser:nutchuser /home/nutchuser/.ssh
180done
181}
182
183
184# 新增nutchuser 帳號時用 Nutchuser_Passwd 當密碼
185function creat_nutchuser_account(){
186echo -e "\n= creat_nutchuser_account (debug) ="
187
188if [ $(cat /etc/passwd | grep nutchuser) ]; then
189    echo "System already has nutchuser, change nutchuser password."
190    expect -c "spawn passwd nutchuser
191    set timeout 1
192    expect \"*: \"
193    send \"$1\r\"
194    expect \"*: \"
195    send \"$1\r\"
196    expect eof"
197else
198    echo "Create nutchuser and change password."
199    useradd -m nutchuser -s /bin/bash
200    expect -c "spawn passwd nutchuser
201    set timeout 1
202    expect \"*: \"
203    send \"$1\r\"
204    expect \"*: \"
205    send \"$1\r\"
206    expect eof"
207fi
208}
209
210# 用scp 複製 master 的設定與安裝資料
211# 目前僅需做到能無礙的複製遠端的/opt/nutchez/到local的/opt/
212function scp_packages(){
213echo -e "\n= scp_packages (debug) ="
214chmod 777 /opt
215echo "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez/ /opt/"
216su nutchuser -c "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez/ /opt/"
217
218echo -e "\nchown -R nutchuser:nutchuser /opt/nutchez/"
219chown -R nutchuser:nutchuser /opt/nutchez/
220chmod 755 /opt
221}
Note: See TracBrowser for help on using the repository browser.