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

Last change on this file since 132 was 132, checked in by rock, 14 years ago

修改部份功能,測試正常(於 Ubuntu 10.04 的桌機上測試)

  • Property svn:executable set to *
File size: 6.4 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:"
29distribution=$(lsb_release -d 2>/dev/null)
30Linux_Distribution=$(echo $distribution | awk '{print $2}')
31Linux_Version=$(echo $distribution | awk '{print $3}')
32echo $Linux_Distribution , $Linux_Version
33unset distribution
34}
35
36
37# 安裝需要的相依套件 (目前只支援 deb 套件的系統自動安裝,yum或其他套件系統的則需手動安裝)
38function install_packages(){
39# deb 系列系統
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/
150
151while [ ! -d "/home/nutchuser/.ssh" ]
152    do
153    echo -e "\n"
154    read -p "Plz input nutchuser passwd of master node: " Nutchuser_Passwd
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 \"Passwd is error\" }
159    expect eof"
160        if [ ! -d "/home/nutchuser/.ssh" ]; then
161            echo -e "\nPasswd 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
175# 若沒 nutchuser_Passwd 的參數傳遞才將註解打開讓使用者字型輸入
176#while [ "1" != "$Nutchuser_Passwd2" ]
177#do
178#    read -p "Create nutchuser, plz input nutchuser's password: " Nutchuser_Passwd
179#    read -p "plz input nutchuser's password, again: " Nutchuser_Passwd2
180
181#    if [ "$1" == "$Nutchuser_Passwd2" ]; then
182#        echo "Two Passwords match."
183#    else
184#        echo "two passwords do not match, plz re-input nutchuser's password."
185#    fi
186#done
187
188#unset Nutchuser_Passwd2
189
190if [ $(cat /etc/passwd | grep nutchuser) ]; then
191    echo "System already has nutchuser, change nutchuser password."
192    expect -c "spawn passwd nutchuser                 
193    expect \"*: \"                         
194    send \"$1\r\"                         
195    expect \"*: \"                         
196    send \"$1\r\"                         
197    expect eof"
198else
199    echo "Create nutchuser and change password."
200    useradd -m nutchuser -s /bin/bash
201    expect -c "spawn passwd nutchuser                 
202    expect \"*: \"
203    send \"$1\r\"
204    expect \"*: \"
205    send \"$1\r\"
206    expect eof"
207fi
208}
209
210
211# 用scp 複製 master 的設定與安裝資料
212# 目前僅需做到能無礙的複製遠端的/opt/nutchez/到local的/opt/
213function scp_packages(){
214echo -e "\n= scp_packages (debug) ="
215echo "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez/ /opt/"
216scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez/ /opt/
217
218echo "chown -R nutchuser:nutchuser /opt/nutchez/"
219chown -R nutchuser:nutchuser /opt/nutchez/
220}
Note: See TracBrowser for help on using the repository browser.