Project

General

Profile

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
APACHE_SITE_FILE=/etc/apache2/sites-available/knb-ssl
10
NEW_JDK_PACKAGE=openjdk-7-jdk
11
NEW_JDK_HOME=/usr/lib/jvm/java-7-openjdk-amd64
12

    
13
JK_CONF=/etc/apache2/mods-enabled/jk.conf
14

    
15
OLD_TOMCAT=tomcat6
16
OLD_TOMCAT_BASE=/var/lib/${OLD_TOMCAT}
17

    
18
NEW_TOMCAT=tomcat7
19
NEW_TOMCAT_COMMON=${NEW_TOMCAT}-common
20
NEW_TOMCAT_LIB=lib${NEW_TOMCAT}-java
21
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

    
25
KNB=knb
26
METACAT=metacat
27
WEBAPPS=webapps
28
TOMCAT_CONFIG_SLASH='org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true'
29
TOMCAT_CONFIG_BACKSLASH='org.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true'
30
INIT_START_DIR=/etc/init.d
31

    
32
sudo /etc/init.d/apache2 stop
33
echo "install ${NEW_JDK_PACKAGE}"
34
sudo apt-get install ${NEW_JDK_PACKAGE}
35
sleep 3
36
echo "configure java, java, keytool and javaws"
37
sudo update-alternatives --set java ${NEW_JDK_HOME}/jre/bin/java
38
sudo update-alternatives --set javac ${NEW_JDK_HOME}/bin/javac
39
sudo update-alternatives --set keytool ${NEW_JDK_HOME}/jre/bin/keytool
40
sudo update-alternatives --set javaws ${NEW_JDK_HOME}/jre/bin/javaws
41

    
42
echo "install ${NEW_TOMCAT}"
43
sudo apt-get install ${NEW_TOMCAT_LIB}
44
sudo apt-get install ${NEW_TOMCAT_COMMON}
45
sudo apt-get install ${NEW_TOMCAT}
46
echo "configure ${NEW_TOMCAT}"
47
if grep -q "${TOMCAT_CONFIG_SLASH}" ${NEW_CATALINA_PROPERTIES}; then  
48
echo "${TOMCAT_CONFIG_SLASH} exists and don't need to do anything."  
49
else  
50
   echo "${TOMCAT_CONFIG_SLASH} don't exist and add it."
51
   sudo sed -i.bak "$ a\\${TOMCAT_CONFIG_SLASH}" ${NEW_CATALINA_PROPERTIES} 
52
fi
53
if grep -q "${TOMCAT_CONFIG_BACKSLASH}" ${NEW_CATALINA_PROPERTIES}; then
54
echo "${TOMCAT_CONFIG_BACKSLASH} exists and don't need to do anything."  
55
else
56
   echo "${TOMCAT_CONFIG_BACKSLASH} don't exist and add it."
57
   sudo sed -i "$ a\\${TOMCAT_CONFIG_BACKSLASH}" ${NEW_CATALINA_PROPERTIES}
58
fi
59

    
60

    
61
echo "read the location of the workers.properties file from the jk_conf"
62
while read f1 f2 
63
do
64
        if [ "$f1" = "JkWorkersFile" ]; then
65
		JK_WORKER_PATH="$f2"	
66
	fi
67
done < ${JK_CONF}
68
echo "the jk workers.properties location is $JK_WORKER_PATH"
69

    
70
echo "update the tomcat home and java home in workers.properties file"
71
SAFE_NEW_TOMCAT_HOME=$(printf '%s\n' "$NEW_TOMCAT_HOME" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
72
SAFE_NEW_JDK_HOME=$(printf '%s\n' "$NEW_JDK_HOME" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
73
sudo sed -i.bak --regexp-extended "s/(workers\.tomcat_home=).*/\1${SAFE_NEW_TOMCAT_HOME}/;
74
                s/(workers\.java_home=).*/\1${SAFE_NEW_JDK_HOME}/;"\
75
                $JK_WORKER_PATH
76

    
77
echo "update the apache site file by replacing $OLD_TOMCAT by $NEW_TOMCAT"
78
sudo sed -i.bak "s/${OLD_TOMCAT}/${NEW_TOMCAT}/;" $APACHE_SITE_FILE
79

    
80
echo "move Metacat and other web applications from $OLD_TOMCAT to $NEW_TOMCAT"
81
sudo ${INIT_START_DIR}/${OLD_TOMCAT} stop
82
sudo ${INIT_START_DIR}/${NEW_TOMCAT} stop
83
sudo rm -rf ${NEW_TOMCAT_BASE}/${WEBAPPS}/*
84
sudo cp -R ${OLD_TOMCAT_BASE}/${WEBAPPS}/*  ${NEW_TOMCAT_BASE}/${WEBAPPS}/.
85
sudo chown -R ${NEW_TOMCAT}:${NEW_TOMCAT} ${NEW_TOMCAT_BASE}/${WEBAPPS}/*
86
echo "change the value of the application.deployDir in the metacat.properties file"
87
SAFE_NEW_TOMCAT_WEBAPPS=$(printf '%s\n' "$NEW_TOMCAT_BASE/$WEBAPPS" | sed 's/[[\.*^$(){}?+|/]/\\&/g')
88
#echo "the escaped webpass value is ${SAFE_NEW_TOMCAT_WEBAPPS}"
89
if [ -f "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties" ]; then
90
	echo "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties exists and the application.deployDir will be updated"	
91
	sudo sed -i.bak --regexp-extended "s/(application\.deployDir=).*/\1${SAFE_NEW_TOMCAT_WEBAPPS}/;" $NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties
92
        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
93
else
94
	echo "$NEW_TOMCAT_BASE/$WEBAPPS/$KNB/WEB-INF/metacat.properties does NOT exists and the application.deployDir will NOT be updated"
95
fi
96

    
97
if [ -f "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties" ]; then
98
                echo "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties eixsts and the application.deployDir will be updated" 
99
                sudo sed -i.bak --regexp-extended "s/(application\.deployDir=).*/\1${SAFE_NEW_TOMCAT_WEBAPPS}/;" $NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties
100
		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
101
else 
102
  echo "$NEW_TOMCAT_BASE/$WEBAPPS/$METACAT/WEB-INF/metacat.properties doesn't eixt and the application.deployDir will NOT be updated"
103
fi
104

    
105
sudo /etc/init.d/apache2 start
106
sudo /etc/init.d/tomcat7 start
(5-5/10)