[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] | 13 | function check_root(){ |
---|
[123] | 14 | # 正式版後可拿掉此 echo |
---|
[128] | 15 | echo -e "\n= check_root (debug) =" |
---|
[122] | 16 | if [ $USER != "root" ]; then |
---|
| 17 | echo -e "\nPlz Change root to execute it!!!" |
---|
| 18 | exit |
---|
| 19 | fi |
---|
[123] | 20 | # 正式版後可拿掉此 echo |
---|
| 21 | echo -e "Identify is root." |
---|
[122] | 22 | } |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | # 查出此主機的作業系統,以及版本 |
---|
| 26 | function check_systemInfo(){ |
---|
[128] | 27 | echo -e "\n= check_systemInfo (debug) =" |
---|
[122] | 28 | echo -e "\nYour system information are:" |
---|
| 29 | lsb_release -a 2>/dev/null |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | # 檢查之前是否有安裝NutchEz |
---|
| 34 | # 目前先檢查是否有/opt/nutchez 這個資料夾即可 |
---|
| 35 | function check_nez_installed(){ |
---|
[128] | 36 | echo -e "\n= chcheck_nez_installed (debug) =" |
---|
| 37 | test -d /opt/nutchez && echo -e "\nYour system already had NutchEz." || \ |
---|
| 38 | echo -e "\nYour system does not has NutchEz." |
---|
[122] | 39 | } |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | # 檢查是否有安裝sun java ,並檢查是否為jdk 1.6 以上版本 |
---|
| 43 | # 4種判斷可能性 (1)系統沒安裝 JAVA (2)系統有安裝JAVA,但非sun版本 |
---|
| 44 | # (3)系統有安裝但Sun Java 在非預設路徑下 (4)以正確安裝 Sun JAVA 預設路徑下 |
---|
| 45 | function check_sunJava(){ |
---|
[128] | 46 | echo -e "\n= check_sunJava (debug) =" |
---|
[122] | 47 | echo -e "\nNutchEz need Sun Java JDK 1.6.x or above version" |
---|
| 48 | javaPath="/usr/" |
---|
| 49 | |
---|
[123] | 50 | test -e $javaPath/bin/java || read -p "Plz input specific Java path\ |
---|
[122] | 51 | (ex./opt/jvm/java-6-sun-1.6.0.20/): " javaPath |
---|
| 52 | |
---|
| 53 | if [ -e $javaPath/bin/java ]; then |
---|
| 54 | JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)") |
---|
| 55 | JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \ |
---|
| 56 | awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2) |
---|
| 57 | |
---|
| 58 | if [ "$JAVA_org" == "" ]; then |
---|
[123] | 59 | echo "Java is not Sun version, plz install sun Java 1.6.X" |
---|
[122] | 60 | exit |
---|
| 61 | fi |
---|
[128] | 62 | |
---|
| 63 | large16=$(echo "$JAVA_version >= 1.6" | bc) |
---|
| 64 | if [ "${large16}" == 0 ]; then |
---|
[123] | 65 | echo "Java version is too old (it need 1.6.X above)" |
---|
[122] | 66 | exit |
---|
| 67 | fi |
---|
[128] | 68 | |
---|
| 69 | echo "System has Sun Java 1.6 above version." |
---|
[122] | 70 | else |
---|
| 71 | echo "Plz install Sun JAVA 1.6.X or above version" |
---|
| 72 | exit |
---|
| 73 | fi |
---|
| 74 | |
---|
| 75 | unset JAVA_org |
---|
| 76 | unset JAVA_version |
---|
[123] | 77 | } |
---|
[122] | 78 | |
---|
[123] | 79 | |
---|
| 80 | # 檢查是否有安裝openssh, openssh-server |
---|
| 81 | function check_ssh(){ |
---|
[128] | 82 | echo -e "\n= check_ssh (debug) =" |
---|
[123] | 83 | if [ -e /usr/bin/ssh ]; then |
---|
| 84 | echo -e "\nSystem has ssh." |
---|
| 85 | else |
---|
| 86 | echo "Plz install ssh." |
---|
| 87 | exit |
---|
| 88 | fi |
---|
| 89 | |
---|
| 90 | if [ -e /usr/sbin/sshd ]; then |
---|
| 91 | echo "System has ssh Server (sshd)." |
---|
| 92 | else |
---|
| 93 | echo "Plz install ssh Server (sshd)." |
---|
| 94 | exit |
---|
| 95 | fi |
---|
[122] | 96 | } |
---|
[123] | 97 | |
---|
| 98 | |
---|
| 99 | # 檢查是否有安裝dialog |
---|
| 100 | function check_dialog(){ |
---|
[128] | 101 | echo -e "\n= check_dialog (debug) =" |
---|
[123] | 102 | if [ -e /usr/bin/dialog ]; then |
---|
| 103 | echo -e "\nSystem has dialog." |
---|
| 104 | else |
---|
| 105 | echo "Plz install dialog." |
---|
| 106 | exit |
---|
| 107 | fi |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | # 檢查是否安裝 php 5.5 |
---|
| 112 | function check_php(){ |
---|
[128] | 113 | echo -e "\n= check_php (debug) =" |
---|
[123] | 114 | if [ "$(php -v 2>/dev/null | grep "PHP 5" | awk '{print $2}' | cut -d "." -f1)" == 5 ]; then |
---|
| 115 | echo -e "\nPHP'version is 5" |
---|
| 116 | else |
---|
[128] | 117 | echo -e "\nplz install PHP 5 version!" |
---|
[123] | 118 | # exit |
---|
| 119 | fi |
---|
| 120 | } |
---|
[128] | 121 | |
---|
| 122 | |
---|
| 123 | # scp nutchuser@master_ip:~ 把.ssh/目錄複製下來 |
---|
| 124 | # 當使用者輸入nutchuser 密碼時,將此密碼紀錄到Nutchuser_Passwd |
---|
| 125 | # 此步驟若無法連到 master 則跳出 |
---|
| 126 | function scp_master_nutchuser_sshkey(){ |
---|
| 127 | echo -e "\n= scp_master_nutchuser_sshkey (debug) =" |
---|
| 128 | echo -e "mkdir -p /home/nutchuser/" |
---|
| 129 | mkdir -p /home/nutchuser/ |
---|
| 130 | |
---|
[129] | 131 | while [ ! -d "/home/nutchuser/.ssh" ] |
---|
| 132 | do |
---|
| 133 | echo -e "\n" |
---|
| 134 | read -p "Plz input nutchuser passwd of master node: " Nutchuser_Passwd |
---|
| 135 | echo -e "scp nutchuser@$1:~/.ssh /home/nutchuser/" |
---|
| 136 | expect -c "spawn scp -r -o StrictHostKeyChecking=no nutchuser@$1:~/.ssh /home/nutchuser/ |
---|
| 137 | expect \"*: \" { send \"$Nutchuser_Passwd\r\" } |
---|
| 138 | expect \"*: \" { send_user \"Passwd is error\" } |
---|
| 139 | expect eof" |
---|
| 140 | if [ ! -d "/home/nutchuser/.ssh" ]; then |
---|
| 141 | echo -e "\nPasswd is error, plz re-input nutchuser passwd of master node." |
---|
| 142 | else |
---|
| 143 | echo -e "\nscp correct." |
---|
| 144 | fi |
---|
| 145 | echo "chown -R nutchuser:nutchuser /home/nutchuser/.ssh" |
---|
| 146 | chown -R nutchuser:nutchuser /home/nutchuser/.ssh |
---|
| 147 | done |
---|
[128] | 148 | } |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | # 新增nutchuser 帳號時用 Nutchuser_Passwd 當密碼 |
---|
| 152 | function creat_nutchuser_account(){ |
---|
| 153 | echo -e "\n= creat_nutchuser_account (debug) =" |
---|
| 154 | |
---|
[129] | 155 | # 若沒 nutchuser_Passwd 的參數傳遞才將註解打開讓使用者字型輸入 |
---|
| 156 | #while [ "1" != "$Nutchuser_Passwd2" ] |
---|
| 157 | #do |
---|
| 158 | # read -p "Create nutchuser, plz input nutchuser's password: " Nutchuser_Passwd |
---|
| 159 | # read -p "plz input nutchuser's password, again: " Nutchuser_Passwd2 |
---|
| 160 | |
---|
| 161 | # if [ "$1" == "$Nutchuser_Passwd2" ]; then |
---|
| 162 | # echo "Two Passwords match." |
---|
| 163 | # else |
---|
| 164 | # echo "two passwords do not match, plz re-input nutchuser's password." |
---|
| 165 | # fi |
---|
| 166 | #done |
---|
| 167 | |
---|
| 168 | #unset Nutchuser_Passwd2 |
---|
| 169 | |
---|
| 170 | if [ $(cat /etc/passwd | grep nutchuser) ]; then |
---|
| 171 | echo "System already has nutchuser, change nutchuser password." |
---|
| 172 | expect -c "spawn passwd nutchuser |
---|
| 173 | expect \"*: \" |
---|
| 174 | send \"$1\r\" |
---|
| 175 | expect \"*: \" |
---|
| 176 | send \"$1\r\" |
---|
| 177 | expect eof" |
---|
| 178 | else |
---|
| 179 | echo "System already has nutchuser, create nutchuser and change password." |
---|
| 180 | useradd -m nutchuser -s /bin/bash |
---|
| 181 | expect -c "spawn passwd nutchuser |
---|
| 182 | expect \"*: \" |
---|
| 183 | send \"$1\r\" |
---|
| 184 | expect \"*: \" |
---|
| 185 | send \"$1\r\" |
---|
| 186 | expect eof" |
---|
| 187 | fi |
---|
[128] | 188 | } |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | # 用scp 複製 master 的設定與安裝資料 |
---|
| 192 | # 目前僅需做到能無礙的複製遠端的/opt/nutchez/到local的/opt/ |
---|
| 193 | function scp_packages(){ |
---|
| 194 | echo -e "\n= scp_packages (debug) =" |
---|
| 195 | echo "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez/ /opt/" |
---|
| 196 | scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez/ /opt/ |
---|
| 197 | |
---|
| 198 | echo "chown -R nutchuser:nutchuser /opt/nutchez/" |
---|
| 199 | chown -R nutchuser:nutchuser /opt/nutchez/ |
---|
| 200 | } |
---|