[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 | |
---|
[219] | 12 | source /home/nutchuser/nutchez/system/lang_link |
---|
[200] | 13 | # 需要 master_install 設定的參數區 |
---|
| 14 | # Master IP here |
---|
| 15 | Master_IP_Address=input.your.master.ip_address |
---|
| 16 | # Master Hostname here |
---|
| 17 | Master_Hostname=input_your_master_hostname |
---|
| 18 | |
---|
| 19 | ########## echo function ########## |
---|
| 20 | function debug_info () { |
---|
| 21 | if [ $? -eq 0 ]; then |
---|
| 22 | echo -e "\033[1;35;40m info - $1 \033[0m" |
---|
| 23 | fi |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | function show_info () { |
---|
| 28 | if [ $? -eq 0 ]; then |
---|
| 29 | echo -e "\033[1;32;40m $1 \033[0m" |
---|
| 30 | fi |
---|
| 31 | } |
---|
| 32 | ##########end echo function ########## |
---|
| 33 | |
---|
| 34 | # check root |
---|
| 35 | function check_root(){ |
---|
| 36 | debug_info "check_root" |
---|
| 37 | if [ $USER != "root" ]; then |
---|
[213] | 38 | show_info "$CR_check_root_1" # "請切換成 root 身份執行移除程式!!!" |
---|
[200] | 39 | exit |
---|
| 40 | fi |
---|
[213] | 41 | show_info "$CR_check_root_2" # "已確認為root身份, 將繼續執行此移除程式!" |
---|
[200] | 42 | } |
---|
| 43 | |
---|
| 44 | # shutdown service |
---|
| 45 | function shutdown_service () { |
---|
[213] | 46 | show_info "$CR_shutdown_service_echo_1" # "關閉本機服務..." |
---|
[200] | 47 | su nutchuser -c "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop datanode" |
---|
| 48 | su nutchuser -c "/opt/nutchez/nutch/bin/hadoop-daemon.sh stop tasktracker" |
---|
[213] | 49 | show_info "$CR_shutdown_service_echo_2" # "本機服務已關閉" |
---|
[200] | 50 | } |
---|
| 51 | |
---|
| 52 | # 移除檔案及資料夾 |
---|
| 53 | function remove_folders () { |
---|
[213] | 54 | show_info "$CR_remove_folders_echo_1" # "正在刪除安裝時所建立的檔案及資料夾..." |
---|
[206] | 55 | rm -rf /opt/nutchez |
---|
| 56 | rm -rf /var/nutchez |
---|
[213] | 57 | show_info "$CR_remove_folders_echo_2" # "安裝時所建立的檔案及資料夾已刪除" |
---|
[200] | 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | # 還原/etc/hosts |
---|
| 62 | function edit_hosts () { |
---|
[213] | 63 | show_info "$CR_edit_hosts_echo_1" # "修改/etc/hosts..." |
---|
| 64 | # Line_NO=`cat /etc/hosts | grep -n $Master_IP_Address | sed 's/:.*//g'` |
---|
| 65 | # if [[ $Line_NO -ge 1 ]]; then |
---|
| 66 | # sed -i ''$Line_NO'd' /etc/hosts |
---|
| 67 | # fi |
---|
| 68 | cat > /etc/hosts < /home/nutchuser/nutchez/system/hosts.bak |
---|
| 69 | show_info "$CR_edit_hosts_echo_2" # "完成修改/etc/hosts" |
---|
[200] | 70 | } |
---|
| 71 | |
---|
| 72 | |
---|
| 73 | # 移除使用者 |
---|
| 74 | function user_delete () { |
---|
[213] | 75 | show_info "$CR_user_delete_echo_1" # "正在刪除nutchuser使用者..." |
---|
[206] | 76 | userdel -r nutchuser |
---|
[213] | 77 | show_info "$CR_user_delete_echo_2" # "使用者nutchuser已刪除" |
---|
[200] | 78 | } |
---|
| 79 | |
---|
| 80 | # Main function |
---|
| 81 | function main () { |
---|
[230] | 82 | check_root |
---|
[213] | 83 | show_info "$CR_main_echo_1" #"警告 - 此一程式為移除此用戶端的nutch node, 若您為誤執行此一程式, 請按Ctrl+c離開此程序!" |
---|
| 84 | show_info "$CR_main_echo_2" #"本執行程序將會移除安裝nutchEZ時所新增的檔案及nutchuser使用者帳號" |
---|
[200] | 85 | # 詢問是否繼續 |
---|
[213] | 86 | read -p "$CR_main_echo_3" confirm # "請問是否確定移除此一節點:1.確定 2.取消" |
---|
[200] | 87 | # 確認移除 |
---|
| 88 | if [ $confirm -eq 1 ]; then |
---|
| 89 | shutdown_service |
---|
| 90 | remove_folders |
---|
| 91 | edit_hosts |
---|
| 92 | user_delete |
---|
[213] | 93 | show_info "$CR_main_echo_4" # "移除程序已完成!" |
---|
[200] | 94 | elif [ $confirm -eq 2 ]; then |
---|
[213] | 95 | show_info "$CR_main_echo_5" # "您已取消移除程序!" |
---|
| 96 | show_info "$CR_main_echo_6" # "若要移除請再重新執行!" |
---|
[200] | 97 | fi |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | main |
---|