Skip to content

Instantly share code, notes, and snippets.

@buckett
Last active January 3, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buckett/8476488 to your computer and use it in GitHub Desktop.
Save buckett/8476488 to your computer and use it in GitHub Desktop.
get-tomcat
#!/bin/bash -e
# Quick script to download, unpack and muller tomcat.
# Location to download file to, also used like a cache to check if we already have it.
downloads=~/Downloads
# Filename on remote server and in local download folder
file=apache-tomcat-7.0.50.tar.gz
# Location to get download from
remote=http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.50/bin
# Filename on remote server for mysql archive
mysql_file=mysql-connector-java-5.1.34.tar.gz
# MySQL location
mysql_remote=http://cdn.mysql.com//Downloads/Connector-J/
# Folder to unpack tomcat into
if [[ -z "$1" ]]; then
target=tomcat
else
target=$1
fi
if [ -f ${downloads}/${file} ]; then
echo "File already downloaded."
else
echo "Downloading file..."
mkdir -p ${downloads}
# wget --progress=dot -P ${downloads} ${remote}/${file}
(cd ${downloads} && curl -O "${remote}/${file}" )
fi
if [ -f ${downloads}/${mysql_file} ]; then
echo "MySQL already downloaded."
else
echo "Downloading MySQL JAR..."
(cd ${downloads} && curl -O "${mysql_remote}/${mysql_file}")
fi
if [ -d "${target}" ] ; then
echo "Tomcat folder already exists: ${target}"
exit 1
fi
mkdir "${target}"
pushd "${target}"
echo "Unpacking tomcat archive."
tar zxf ${downloads}/${file} --strip-components 1
echo "Removing existing webapps"
rm -r webapps/*
echo "Setting up custom classloaders"
sed -i.orig '/^common.loader=/s@$@,${catalina.base}/common/classes/,${catalina.base}/common/lib/*.jar@
/^shared.loader=/s@$@${catalina.base}/shared/classes/,${catalina.base}/shared/lib/*.jar@
/^server.loader=/s@$@${catalina.base}/server/classes/,${catalina.base}/server/lib/*.jar@' conf/catalina.properties
echo "Stop scanning all JARs"
sed -i.orig 's/^org.apache.catalina.startup.ContextConfig.jarsToSkip=.*/org.apache.catalina.startup.ContextConfig.jarsToSkip=*.jar/' conf/catalina.properties
echo "Increasing Tomcat startup threads"
sed -i.orig 's/<Host name="localhost"/<Host name="localhost" startStopThreads="4"/' conf/server.xml
mkdir -p shared/classes shared/lib common/classes common/lib server/classes server/lib
echo "Copying in MySQL JAR"
# This assumes the mysql JAR is inside a folder and has a .jar extension
(cd shared/lib; tar -x -f ${downloads}/${mysql_file} --include=mysql*.jar --strip-components 1 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment