1
|
#!/bin/bash
|
2
|
#This script will install openjdk-7 and tomcat7.
|
3
|
#It will update the alternatives for java, javac, keytool and javaws to openjdk-7.
|
4
|
#It will modify the /etc/tomcat7/catalina.properties to allow DataONE idenifiers.
|
5
|
#It will modify the workers.properties file for apache-tomcat connector.
|
6
|
#It will move Metacat and other web applications from the old context directory to the new context directory.
|
7
|
#The user running the script should have the sudo permission.
|
8
|
|
9
|
NEW_JDK_PACKAGE=openjdk-7-jdk
|
10
|
NEW_JDK_HOME=/usr/lib/jvm/java-7-openjdk-amd64
|
11
|
|
12
|
JK_CONF=/etc/apache2/mods-enabled/jk.conf
|
13
|
|
14
|
OLD_TOMCAT=tomcat6
|
15
|
OLD_TOMCAT_BASE=/var/lib/${OLD_TOMCAT}
|
16
|
|
17
|
NEW_TOMCAT=tomcat7
|
18
|
NEW_TOMCAT_COMMON=${NEW_TOMCAT}-common
|
19
|
NEW_TOMCAT_LIB=lib${NEW_TOMCAT}-java
|
20
|
NEW_CATALINA_PROPERTIES=/etc/${NEW_TOMCAT}/catalina.properties
|
21
|
NEW_TOMCAT_HOME=/usr/share/${NEW_TOMCAT}
|
22
|
NEW_TOMCAT_BASE=/var/lib/${NEW_TOMCAT}
|
23
|
|
24
|
KNB=knb
|
25
|
METACAT=metacat
|
26
|
WEBAPPS=webapps
|
27
|
TOMCAT_CONFIG_SLASH='org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true'
|
28
|
TOMCAT_CONFIG_BACKSLASH='org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true'
|
29
|
INIT_START_DIR=/etc/init.d
|
30
|
|
31
|
sudo /etc/init.d/apache2 stop
|
32
|
echo "install ${NEW_JDK_PACKAGE}"
|
33
|
sudo apt-get install ${NEW_JDK_PACKAGE}
|
34
|
sleep 3
|
35
|
echo "configure java, java, keytool and javaws"
|
36
|
sudo update-alternatives --set java ${NEW_JDK_HOME}/jre/bin/java
|
37
|
sudo update-alternatives --set javac ${NEW_JDK_HOME}/bin/javac
|
38
|
sudo update-alternatives --set keytool ${NEW_JDK_HOME}/jre/bin/keytool
|
39
|
sudo update-alternatives --set javaws ${NEW_JDK_HOME}/jre/bin/javaws
|
40
|
|
41
|
echo "install ${NEW_TOMCAT}"
|
42
|
sudo apt-get install ${NEW_TOMCAT_LIB}
|
43
|
sudo apt-get install ${NEW_TOMCAT_COMMON}
|
44
|
sudo apt-get install ${NEW_TOMCAT}
|
45
|
echo "configure ${NEW_TOMCAT}"
|
46
|
if grep -q "${TOMCAT_CONFIG_SLASH}" ${NEW_CATALINA_PROPERTIES}; then
|
47
|
echo "${TOMCAT_CONFIG_SLASH} exists and don't need to do anything."
|
48
|
else
|
49
|
echo "${TOMCAT_CONFIG_SLASH} don't exist and add it."
|
50
|
sudo sed -i.bak "$ a\\${TOMCAT_CONFIG_SLASH}" ${NEW_CATALINA_PROPERTIES}
|
51
|
fi
|
52
|
if grep -q "${TOMCAT_CONFIG_BACKSLASH}" ${NEW_CATALINA_PROPERTIES}; then
|
53
|
echo "${TOMCAT_CONFIG_BACKSLASH} exists and don't need to do anything."
|
54
|
else
|
55
|
echo "${TOMCAT_CONFIG_BACKSLASH} don't exist and add it."
|
56
|
sudo sed -i "$ a\\${TOMCAT_CONFIG_BACKSLASH}" ${NEW_CATALINA_PROPERTIES}
|
57
|
fi
|
58
|
|
59
|
|
60
|
echo "read the location of the workers.properties file from the jk_conf"
|
61
|
while read f1 f2
|
62
|
do
|
63
|
if [ "$f1" = "JkWorkersFile" ]; then
|
64
|
JK_WORKER_PATH="$f2"
|
65
|
fi
|
66
|
done < ${JK_CONF}
|
67
|
echo "the jk workers.properties location is $JK_WORKER_PATH"
|
68
|
|
69
|
echo "update the tomcat home and java home in workers.properties file"
|
70
|
SAFE_NEW_TOMCAT_HOME=$(printf '%s\n' "$NEW_TOMCAT_HOME" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
|
71
|
SAFE_NEW_JDK_HOME=$(printf '%s\n' "$NEW_JDK_HOME" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
|
72
|
sudo sed -i.bak --regexp-extended "s/(workers\.tomcat_home=).*/\1${SAFE_NEW_TOMCAT_HOME}/;
|
73
|
s/(workers\.java_home=).*/\1${SAFE_NEW_JDK_HOME}/;"\
|
74
|
$JK_WORKER_PATH
|
75
|
|
76
|
echo "move Metacat and other web applications from $OLD_TOMCAT to $NEW_TOMCAT"
|
77
|
sudo ${INIT_START_DIR}/${OLD_TOMCAT} stop
|
78
|
sudo ${INIT_START_DIR}/${NEW_TOMCAT} stop
|
79
|
sudo rm -rf ${NEW_TOMCAT_BASE}/${WEBAPPS}/*
|
80
|
sudo cp -R ${OLD_TOMCAT_BASE}/${WEBAPPS}/* ${NEW_TOMCAT_BASE}/${WEBAPPS}/.
|
81
|
sudo chown -R ${NEW_TOMCAT}:${NEW_TOMCAT} ${NEW_TOMCAT_BASE}/${WEBAPPS}/*
|
82
|
echo "change the value of the application.deployDir in the metacat.properties file"
|
83
|
SAFE_NEW_TOMCAT_WEBAPPS=$(printf '%s\n' "$NEW_TOMCAT_BASE/$WEBAPPS" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
|
84
|
#echo "the escaped webpass value is ${SAFE_NEW_TOMCAT_WEBAPPS}"
|
85
|
if [ -f "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties" ]; then
|
86
|
echo "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties exists and the application.deployDir will be updated"
|
87
|
sudo sed -i.bak --regexp-extended "s/(application\.deployDir=).*/\1${SAFE_NEW_TOMCAT_WEBAPPS}/;" $NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties
|
88
|
else
|
89
|
echo "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties does NOT exists and the application.deployDir will NOT be updated"
|
90
|
fi
|
91
|
|
92
|
if [ -f "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties" ]; then
|
93
|
echo "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties eixsts and the application.deployDir will be updated"
|
94
|
sudo sed -i.bak --regexp-extended "s/(application\.deployDir=).*/\1${SAFE_NEW_TOMCAT_WEBAPPS}/;" $NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties
|
95
|
else
|
96
|
echo "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties doesn't eixt and the application.deployDir will NOT be updated"
|
97
|
fi
|
98
|
|
99
|
sudo /etc/init.d/apache2 start
|
100
|
sudo /etc/init.d/tomcat7 start
|