Project

General

Profile

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