source: nutchez-0.2/src/shell/client_remove @ 261

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

Debug: nutchez (/etc/hosts timestamp )

  • Property svn:executable set to *
File size: 3.1 KB
RevLine 
[200]1#!/bin/bash
2# Program:
3#   remove shell script for client uninstall
4# Author:
5#   Waue, Shunfa, Rock {waue, shunfa, rock}@nchc.org.tw
6# Version:
7#    1.0
8# History:
9#   
10
11
12# 需要 master_install 設定的參數區
13# Master IP here
[249]14Master_IP_Address=140.110.138.179
[200]15# Master Hostname here
16Master_Hostname=input_your_master_hostname
17
18##########  echo function  ##########
19function debug_info () {
20  if [ $? -eq 0 ]; then
21    echo -e "\033[1;35;40m info - $1 \033[0m"
22  fi
23}
24
25
26function show_info () {
27  if [ $? -eq 0 ]; then
28    echo -e "\033[1;32;40m $1 \033[0m"
29  fi
30}
31##########end echo function ##########
32
[244]33function load_default_lang(){
34
35lang=$(locale | grep 'LANG=' | cut -d "=" -f2)
36
37# Default: source english
38. lang/lang_en_US
39# if locale is zh then source chinese
40
41echo $lang | grep 'zh' >> /dev/null && source lang/lang_zh_TW
42}
43
44
45
[200]46# check root
47function check_root(){
48  debug_info "check_root"
49  if [ $USER != "root" ]; then
[213]50    show_info "$CR_check_root_1" # "請切換成 root 身份執行移除程式!!!"
[200]51    exit
52  fi
[213]53  show_info "$CR_check_root_2" # "已確認為root身份, 將繼續執行此移除程式!"
[200]54}
55
56# shutdown service
57function shutdown_service () {
[213]58  show_info "$CR_shutdown_service_echo_1" # "關閉本機服務..."
[200]59  su nutchuser -c "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode"
60  su nutchuser -c "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker"
[213]61  show_info "$CR_shutdown_service_echo_2" # "本機服務已關閉"
[200]62}
63
64# 移除檔案及資料夾
65function remove_folders () {
[213]66  show_info "$CR_remove_folders_echo_1" # "正在刪除安裝時所建立的檔案及資料夾..."
[206]67  rm -rf /opt/nutchez
68  rm -rf /var/nutchez
[213]69  show_info "$CR_remove_folders_echo_2" # "安裝時所建立的檔案及資料夾已刪除"
[200]70}
71
72
73# 還原/etc/hosts
74function edit_hosts () {
[213]75  show_info "$CR_edit_hosts_echo_1" # "修改/etc/hosts..."
76#  Line_NO=`cat /etc/hosts | grep -n $Master_IP_Address | sed 's/:.*//g'`
77#  if [[ $Line_NO -ge 1 ]]; then
78#    sed -i ''$Line_NO'd' /etc/hosts
79#  fi
80  cat > /etc/hosts < /home/nutchuser/nutchez/system/hosts.bak
81  show_info "$CR_edit_hosts_echo_2" # "完成修改/etc/hosts"
[200]82}
83
84
85# 移除使用者
86function user_delete () {
[213]87  show_info "$CR_user_delete_echo_1" # "正在刪除nutchuser使用者..."
[206]88  userdel -r nutchuser
[213]89  show_info "$CR_user_delete_echo_2" # "使用者nutchuser已刪除"
[200]90}
91
92# Main function
93function main () {
[244]94  load_default_lang
[230]95  check_root
[213]96  show_info "$CR_main_echo_1" #"警告 - 此一程式為移除此用戶端的nutch node, 若您為誤執行此一程式, 請按Ctrl+c離開此程序!"
97  show_info "$CR_main_echo_2" #"本執行程序將會移除安裝nutchEZ時所新增的檔案及nutchuser使用者帳號"
[200]98# 詢問是否繼續
[213]99  read -p "$CR_main_echo_3" confirm # "請問是否確定移除此一節點:1.確定 2.取消"
[200]100# 確認移除
101  if [ $confirm -eq 1 ]; then
102    shutdown_service
103    remove_folders
104    edit_hosts
105    user_delete
[213]106    show_info "$CR_main_echo_4" # "移除程序已完成!"
[200]107  elif [ $confirm -eq 2 ]; then
[213]108    show_info "$CR_main_echo_5" # "您已取消移除程序!"
109    show_info "$CR_main_echo_6" # "若要移除請再重新執行!"
[200]110  fi
111}
112
113main
Note: See TracBrowser for help on using the repository browser.