释放双眼,带上耳机,听听看~!
安装脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106 1#!/bin/bash
2#
3###############################################
4#author: biezhi
5#email:i@biezhi.me
6#date: 2015-09-16
7###############################################
8
9base_dir=$(cd "$(dirname "$0")";pwd)
10
11JDK_FILE=$(ls | grep jdk-*-linux-*.tar.gz)
12TOMCAT_FILE=$(ls | grep apache-tomcat-*.tar.gz)
13#下载JDK
14download(){
15 os_version=`uname -a`
16 echo $os_version
17 architecture="64"
18 echo "$os_version" | grep -q "$architecture"
19
20 if [ $? -eq 0 ]
21 then
22 # 不存在即去外网下载jdk文件
23 if [ ! -f "$JDK_FILE" ]; then
24 echo "您正在使用64位操作系统,为您选择64位JDK"
25 wget http://7xls9k.dl1.z0.glb.clouddn.com/jdk-8u60-linux-x64.tar.gz
26 fi
27 else
28 # 不存在即去外网下载jdk文件
29 if [ ! -f "$JDK_FILE" ]; then
30 echo "您正在使用32位操作系统,为您选择32位JDK"
31 wget http://7xls9k.dl1.z0.glb.clouddn.com/jdk-8u60-linux-i586.tar.gz
32 fi
33 fi
34 #下载tomcat
35 if [ ! -f "$TOMCAT_FILE" ]; then
36 wget http://7xls9k.dl1.z0.glb.clouddn.com/apache-tomcat-8.0.26.tar.gz
37 fi
38 JDK_FILE=$(ls | grep jdk-*-linux-*.tar.gz)
39 TOMCAT_FILE=$(ls | grep apache-tomcat-*.tar.gz)
40}
41
42#安装JDK
43install_jdk(){
44 JAVA_DIR=/usr/local/java
45 JDK_DIR="jdk1.8.0_60"
46 JDK_PATH="$JAVA_DIR"/"$JDK_DIR"
47
48 tar xzf $JDK_FILE
49
50 mkdir -p $JAVA_DIR
51 mv $JDK_DIR $JAVA_DIR
52 #配置环境变量
53 cp ~/.bashrc ~/.bashrc.backup.java
54 if [ ! -n "$JAVA_HOME" ]; then
55 echo "export JAVA_HOME=\"$JDK_PATH\"" >> ~/.bashrc
56 fi
57 if [ ! -n "$JRE_HOME" ]; then
58 echo "export JRE_HOME=\"\$JAVA_HOME/jre\"" >> ~/.bashrc
59 fi
60 if [ ! -n "$CLASSPATH" ]; then
61 echo "export CLASSPATH=.:\$JDK_PATH/lib/dt.jar:\$JDK_PATH/lib/tools.jar" >> ~/.bashrc
62 fi
63 echo "export PATH=\$JAVA_HOME/bin:\$JRE_HOME/bin:\$PATH" >> ~/.bashrc
64 source ~/.bashrc
65 echo "JDK install success!"
66}
67#安装tomcat
68install_tomcat(){
69 TOMCAT_DIR=/usr/local/tomcat8
70
71 mkdir -p $TOMCAT_DIR
72
73 tar xzf $TOMCAT_FILE
74 mv apache-tomcat-8.0.26 tomcat8
75 mv tomcat8 /usr/local/
76
77 cp ~/.bashrc ~/.bashrc.backup.tomcat8
78 if [ ! -n "$TOMCAT_HOME" ]; then
79 echo "export TOMCAT_HOME=$TOMCAT_DIR" >> ~/.bashrc
80 fi
81 if [ ! -n "$CATALINA_HOME" ]; then
82 echo "export CATALINA_HOME=$TOMCAT_DIR" >> ~/.bashrc
83 fi
84 source ~/.bashrc
85 echo "Tomact install success!"
86}
87
88main(){
89 download
90 if [ $? != 0 ]; then
91 echo "tomcat & JDK download failed"
92 exit 1
93 fi
94 install_jdk
95 if [ $? != 0 ]; then
96 echo "JDK install failed"
97 exit 1
98 fi
99 install_tomcat
100 if [ $? != 0 ]; then
101 echo "Tomcat install failed"
102 exit 1
103 fi
104}
105main
106
卸载脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 1#!/bin/bash
2#
3###############################################
4#author: biezhi
5#email:i@biezhi.me
6#date: 2015-09-16
7###############################################
8
9#卸载JDK
10uninstall_jdk(){
11 JAVA_DIR=/usr/local/java/jdk1.8.0_60
12 TOMCAT_DIR=/usr/local/tomcat8
13
14 if [ -d "$JAVA_DIR" ]; then
15 rm -rf $JAVA_DIR
16 fi
17
18 if [ -d "$TOMCAT_DIR" ]; then
19 rm -rf $TOMCAT_DIR
20 fi
21
22 #环境变量
23 if [ -f "~/.bashrc.backup.tomcat8" ]; then
24 mv ~/.bashrc.backup.tomcat8 ~/.bashrc
25 fi
26
27 if [ -f "~/.bashrc.backup.java" ]; then
28 mv ~/.bashrc.backup.java ~/.bashrc
29 fi
30 source ~/.bashrc
31 echo "JDK,Tomcat uninstall success!"
32 cd
33}
34
35main(){
36 uninstall_jdk
37 if [ $? != 0 ]; then
38 echo "JDK,Tomcat uninstall failed"
39 exit 1
40 fi
41}
42main
43
我的github地址:http://github.com/biezhi
开源框架Blade:http://github.com/biezhi/blade