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

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

修改部份功能

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