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 8929 tao
APACHE_SITE_FILE=/etc/apache2/sites-available/knb-ssl
10 8916 tao
NEW_JDK_PACKAGE=openjdk-7-jdk
11 8913 tao
NEW_JDK_HOME=/usr/lib/jvm/java-7-openjdk-amd64
12 8916 tao
13
JK_CONF=/etc/apache2/mods-enabled/jk.conf
14
15 8917 tao
OLD_TOMCAT=tomcat6
16
OLD_TOMCAT_BASE=/var/lib/${OLD_TOMCAT}
17
18 8916 tao
NEW_TOMCAT=tomcat7
19 8927 tao
NEW_TOMCAT_COMMON=${NEW_TOMCAT}-common
20
NEW_TOMCAT_LIB=lib${NEW_TOMCAT}-java
21 8917 tao
NEW_CATALINA_PROPERTIES=/etc/${NEW_TOMCAT}/catalina.properties
22
NEW_TOMCAT_HOME=/usr/share/${NEW_TOMCAT}
23
NEW_TOMCAT_BASE=/var/lib/${NEW_TOMCAT}
24 8930 tao
NEW_TOMCAT_SERVER_CONIF=$NEW_TOMCAT_BASE/conf/server.xml
25 8917 tao
26
KNB=knb
27
METACAT=metacat
28
WEBAPPS=webapps
29 8916 tao
TOMCAT_CONFIG_SLASH='org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true'
30
TOMCAT_CONFIG_BACKSLASH='org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true'
31 8917 tao
INIT_START_DIR=/etc/init.d
32 8913 tao
33 8927 tao
sudo /etc/init.d/apache2 stop
34 8916 tao
echo "install ${NEW_JDK_PACKAGE}"
35
sudo apt-get install ${NEW_JDK_PACKAGE}
36 8909 tao
sleep 3
37
echo "configure java, java, keytool and javaws"
38 8913 tao
sudo update-alternatives --set java ${NEW_JDK_HOME}/jre/bin/java
39
sudo update-alternatives --set javac ${NEW_JDK_HOME}/bin/javac
40
sudo update-alternatives --set keytool ${NEW_JDK_HOME}/jre/bin/keytool
41
sudo update-alternatives --set javaws ${NEW_JDK_HOME}/jre/bin/javaws
42 8909 tao
43 8916 tao
echo "install ${NEW_TOMCAT}"
44 8927 tao
sudo apt-get install ${NEW_TOMCAT_LIB}
45
sudo apt-get install ${NEW_TOMCAT_COMMON}
46 8916 tao
sudo apt-get install ${NEW_TOMCAT}
47 8917 tao
echo "configure ${NEW_TOMCAT}"
48 8916 tao
if grep -q "${TOMCAT_CONFIG_SLASH}" ${NEW_CATALINA_PROPERTIES}; then
49
echo "${TOMCAT_CONFIG_SLASH} exists and don't need to do anything."
50
else
51
   echo "${TOMCAT_CONFIG_SLASH} don't exist and add it."
52
   sudo sed -i.bak "$ a\\${TOMCAT_CONFIG_SLASH}" ${NEW_CATALINA_PROPERTIES}
53
fi
54
if grep -q "${TOMCAT_CONFIG_BACKSLASH}" ${NEW_CATALINA_PROPERTIES}; then
55
echo "${TOMCAT_CONFIG_BACKSLASH} exists and don't need to do anything."
56
else
57
   echo "${TOMCAT_CONFIG_BACKSLASH} don't exist and add it."
58
   sudo sed -i "$ a\\${TOMCAT_CONFIG_BACKSLASH}" ${NEW_CATALINA_PROPERTIES}
59
fi
60 8912 tao
61 8930 tao
echo "remove the 8080 ports and add the 8009 ports to the tomcat7 server.xml"
62
sudo cp $NEW_TOMCAT_SERVER_CONIF $NEW_TOMCAT_SERVER_CONIF.bak
63
sudo xmlstarlet ed -L -P -d "//Connector[@port='8080']" $NEW_TOMCAT_SERVER_CONIF
64
#echo "the configuration file is $NEW_TOMCAT_SERVER_CONIF"
65
result=$(sudo xmlstarlet sel -t --value-of "/Server/Service[@name='Catalina']/Connector[@protocol='AJP/1.3']/@port" $NEW_TOMCAT_SERVER_CONIF)
66
#echo "the result is $result"
67
if [[ -n $result ]]; then
68
  echo "An ajp 1.3 connector exists and we don't need to do anything."
69
else
70
  echo "No aip 1.3 connector found and we should add one"
71
  sudo xmlstarlet ed -L -P -s "/Server/Service[@name='Catalina']" -t elem -name Connector -v "" $NEW_TOMCAT_SERVER_CONIF
72
  sudo xmlstarlet ed -L -P -s "/Server/Service/Connector[not(@port)]" --type attr -n port -v 8009 $NEW_TOMCAT_SERVER_CONIF
73
  sudo xmlstarlet ed -L -P -s "/Server/Service/Connector[not(@protocol)]" --type attr -n protocol -v AJP/1.3 $NEW_TOMCAT_SERVER_CONIF
74
  sudo xmlstarlet ed -L -P -s "/Server/Service/Connector[not(@redirectPort)]" --type attr -n redirectPort -v 8443 $NEW_TOMCAT_SERVER_CONIF
75
fi
76 8916 tao
77 8912 tao
echo "read the location of the workers.properties file from the jk_conf"
78
while read f1 f2
79
do
80
        if [ "$f1" = "JkWorkersFile" ]; then
81 8913 tao
		JK_WORKER_PATH="$f2"
82 8912 tao
	fi
83 8913 tao
done < ${JK_CONF}
84
echo "the jk workers.properties location is $JK_WORKER_PATH"
85 8912 tao
86
echo "update the tomcat home and java home in workers.properties file"
87 8917 tao
SAFE_NEW_TOMCAT_HOME=$(printf '%s\n' "$NEW_TOMCAT_HOME" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
88
SAFE_NEW_JDK_HOME=$(printf '%s\n' "$NEW_JDK_HOME" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
89
sudo sed -i.bak --regexp-extended "s/(workers\.tomcat_home=).*/\1${SAFE_NEW_TOMCAT_HOME}/;
90
                s/(workers\.java_home=).*/\1${SAFE_NEW_JDK_HOME}/;"\
91 8915 tao
                $JK_WORKER_PATH
92 8917 tao
93 8929 tao
echo "update the apache site file by replacing $OLD_TOMCAT by $NEW_TOMCAT"
94
sudo sed -i.bak "s/${OLD_TOMCAT}/${NEW_TOMCAT}/;" $APACHE_SITE_FILE
95
96 8917 tao
echo "move Metacat and other web applications from $OLD_TOMCAT to $NEW_TOMCAT"
97
sudo ${INIT_START_DIR}/${OLD_TOMCAT} stop
98
sudo ${INIT_START_DIR}/${NEW_TOMCAT} stop
99
sudo rm -rf ${NEW_TOMCAT_BASE}/${WEBAPPS}/*
100
sudo cp -R ${OLD_TOMCAT_BASE}/${WEBAPPS}/*  ${NEW_TOMCAT_BASE}/${WEBAPPS}/.
101
sudo chown -R ${NEW_TOMCAT}:${NEW_TOMCAT} ${NEW_TOMCAT_BASE}/${WEBAPPS}/*
102
echo "change the value of the application.deployDir in the metacat.properties file"
103
SAFE_NEW_TOMCAT_WEBAPPS=$(printf '%s\n' "$NEW_TOMCAT_BASE/$WEBAPPS" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
104
#echo "the escaped webpass value is ${SAFE_NEW_TOMCAT_WEBAPPS}"
105
if [ -f "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties" ]; then
106
	echo "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties exists and the application.deployDir will be updated"
107
	sudo sed -i.bak --regexp-extended "s/(application\.deployDir=).*/\1${SAFE_NEW_TOMCAT_WEBAPPS}/;" $NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties
108 8929 tao
        sudo sed -i --regexp-extended "s/(geoserver\.GEOSERVER_DATA_DIR=).*/\1${SAFE_NEW_TOMCAT_WEBAPPS}\/${KNB}\/spatial\/geoserver\/data/;" $NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties
109 8917 tao
else
110
	echo "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties does NOT exists and the application.deployDir will NOT be updated"
111
fi
112
113
if [ -f "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties" ]; then
114
                echo "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties eixsts and the application.deployDir will be updated"
115
                sudo sed -i.bak --regexp-extended "s/(application\.deployDir=).*/\1${SAFE_NEW_TOMCAT_WEBAPPS}/;" $NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties
116 8929 tao
		sudo sed -i --regexp-extended "s/(geoserver\.GEOSERVER_DATA_DIR=).*/\1${SAFE_NEW_TOMCAT_WEBAPPS}\/${METACAT}\/spatial\/geoserver\/data/;" $NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties
117 8917 tao
else
118
  echo "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties doesn't eixt and the application.deployDir will NOT be updated"
119
fi
120 8927 tao
121
sudo /etc/init.d/apache2 start
122
sudo /etc/init.d/tomcat7 start