|
1 | 1 | #!/usr/bin/env bash |
2 | | -################################################################################### |
3 | | -# Linux CentOS 环境部署脚本 |
4 | | -# Author: Zhang Peng |
5 | | -################################################################################### |
6 | 2 |
|
7 | | -function printHeadInfo() { |
| 3 | +# 打印头部信息 |
| 4 | +printHeadInfo() { |
8 | 5 | cat << EOF |
| 6 | +
|
9 | 7 | *********************************************************************************** |
10 | | -* Welcome to using the deployment script for CentOS. |
| 8 | +* 欢迎使用 Linux CentOS 环境运维脚本 |
11 | 9 | * Author: Zhang Peng |
12 | 10 | *********************************************************************************** |
| 11 | +
|
13 | 12 | EOF |
14 | 13 | } |
15 | 14 |
|
16 | | -function printFootInfo() { |
| 15 | +# 打印尾部信息 |
| 16 | +printFootInfo() { |
17 | 17 | cat << EOF |
| 18 | +
|
18 | 19 | *********************************************************************************** |
19 | | -* Deployment is over. |
20 | | -* Thank you for using! |
| 20 | +* 脚本执行结束,感谢使用! |
21 | 21 | *********************************************************************************** |
| 22 | +
|
22 | 23 | EOF |
23 | 24 | } |
24 | 25 |
|
25 | | -function checkOsVersion(){ |
26 | | - if(($1 == 1)) |
27 | | - then |
| 26 | +# 检查操作系统环境 |
| 27 | +checkOsVersion(){ |
| 28 | + if(($1 == 1)); then |
| 29 | + echo -e "检查操作系统环境是否兼容本套脚本" |
| 30 | + |
28 | 31 | platform=`uname -i` |
29 | 32 | if [[ ${platform} != "x86_64" ]]; then |
30 | | - echo "this script is only for 64bit Operating System !" |
31 | | - exit 1 |
32 | | - fi |
33 | | - echo "the platform is ok" |
34 | | - version=`lsb_release -r |awk '{print substr($2,1,1)}'` |
35 | | - if [[ ${version} != 6 ]]; then |
36 | | - echo "this script is only for CentOS 6 !" |
37 | | - exit 1 |
| 33 | + echo "脚本仅支持 64 位操作系统!" |
| 34 | + exit 1 |
38 | 35 | fi |
39 | | - fi |
40 | | -} |
41 | | - |
42 | | - |
43 | | -function showMenu() { |
44 | | -cat << EOF |
45 | 36 |
|
46 | | -=================================== Deploy Menu =================================== |
47 | | -【1 - System Environment】 |
48 | | - [sys] initial system environment |
49 | | - [libs] install commonly libs |
50 | | -
|
51 | | -【2 - Common Tools】 |
52 | | - [2 | tools] install all tools. |
53 | | - [git] install git [svn] install svn |
54 | | - [jdk8] install jdk8 [maven] install maven |
55 | | - [tomcat] install tomcat8 [nginx] install nginx |
56 | | - [nodejs] install node.js [elk] install elk |
57 | | - [redis] install redis [mongodb] install mongodb |
58 | | - [kafka] install kafka |
59 | | -
|
60 | | -【3 - Recommended Tools】 |
61 | | - [sdk] install sdkman |
62 | | - [springboot] install spring boot cli |
| 37 | + version=`cat /etc/redhat-release | awk '{print substr($4,1,1)}'` |
| 38 | + if [[ ${version} != 7 ]]; then |
| 39 | + echo "脚本仅支持 CentOS 7!" |
| 40 | + exit 1 |
| 41 | + fi |
63 | 42 |
|
64 | | -Press <CTRL-D> to exit |
65 | | -Please input key: |
66 | | -EOF |
| 43 | + echo -e "脚本可以在本环境运行!" |
| 44 | + fi |
67 | 45 | } |
68 | 46 |
|
69 | | -function chooseOper() { |
70 | | - key="" |
71 | | - filepath=$(cd "$(dirname "$0")"; pwd) |
72 | | - while read key |
73 | | - do |
74 | | - case ${key} in |
75 | | - # 2 - System Environment |
76 | | - sys ) ${filepath}/sys/init.sh;; |
77 | | - libs ) ${filepath}/lib/install-libs.sh;; |
78 | | - |
79 | | - # 2 - Common Tools |
80 | | - 2 | tools ) ${filepath}/ops/service/install-all.sh;; |
81 | | - git ) ${filepath}/ops/service/git/install-git.sh;; |
82 | | - svn ) ${filepath}/ops/service/svn/install-svn.sh;; |
83 | | - jdk8 ) ${filepath}/ops/service/jdk/install-jdk8.sh;; |
84 | | - maven ) ${filepath}/ops/service/maven/install-maven3.sh;; |
85 | | - nginx ) ${filepath}/ops/service/nginx/install-nginx.sh;; |
86 | | - nodejs ) ${filepath}/ops/service/nodejs/install-nodejs.sh;; |
87 | | - tomcat ) ${filepath}/ops/service/tomcat/install-tomcat8.sh;; |
88 | | - elk ) ${filepath}/ops/service/elk/install-elk.sh;; |
89 | | - redis ) ${filepath}/ops/service/redis/install-redis.sh;; |
90 | | - mongodb ) ${filepath}/ops/service/mongodb/install-mongodb.sh;; |
91 | | - kafka ) ${filepath}/ops/service/kafka/install-kafka.sh;; |
92 | | - |
93 | | - # 3 - Recommended Tools |
94 | | - sdk ) ${filepath}/ops/service/sdk/install-sdk.sh;; |
95 | | - springboot ) ${filepath}/ops/service/springboot/install-springboot.sh;; |
96 | | - |
97 | | - * ) echo "${key} is invalid key";; |
98 | | - esac |
99 | | - |
100 | | - showMenu |
101 | | - done |
| 47 | +# 入口函数 |
| 48 | +main() { |
| 49 | +PS3="请选择要执行的脚本分类:" |
| 50 | +select item in "配置系统" "安装服务" |
| 51 | +do |
| 52 | +case ${item} in |
| 53 | + "配置系统") |
| 54 | + ${path}/sys/main.sh |
| 55 | + ;; |
| 56 | + "安装服务") |
| 57 | + ${path}/service/main.sh |
| 58 | + ;; |
| 59 | + *) |
| 60 | + echo -e "输入项不支持!" |
| 61 | + main |
| 62 | + ;; |
| 63 | +esac |
| 64 | +break |
| 65 | +done |
102 | 66 | } |
103 | 67 |
|
104 | 68 | ######################################## MAIN ######################################## |
| 69 | +path=$(cd "$(dirname "$0")"; pwd) |
| 70 | + |
105 | 71 | printHeadInfo |
106 | 72 | checkOsVersion 0 |
107 | | -showMenu |
108 | | -chooseOper |
| 73 | +main |
109 | 74 | printFootInfo |
0 commit comments