Skip to content

Instantly share code, notes, and snippets.

@stuart-warren
Last active July 1, 2022 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save stuart-warren/5685730 to your computer and use it in GitHub Desktop.
Save stuart-warren/5685730 to your computer and use it in GitHub Desktop.
Create deb of Tomcat installing into its own dir (to allow multiple versions) Uses fpm
#!/bin/bash -xe
#
# sudo gem install fpm
# sudo apt-get install curl
# # Put this script in a folder called tomcat-packaging
# ./mkdeb.sh 7.0.40
# ./mkdeb.sh 6.0.37
#
VERSION=$1
VERSION_=${VERSION//./}
MAJOR=${VERSION:0:1}
rm -rf ./usr/local/*
mkdir -p ./usr/local/share/
pushd ./usr/local/share/
curl "http://mirror.catn.com/pub/apache/tomcat/tomcat-${MAJOR}/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz" | tar -xz
popd
cd ..
rm -f *.deb
fpm -n tomcat${VERSION_} \
-v ${VERSION}-0custom1 \
-d default-jre \
-a all \
--vendor apache \
--license 'Apache Version 2.0' \
-C tomcat-packaging/ \
-m "DSI <dsi@custom.com>" \
-t deb \
-s dir \
--config-files usr/local/share/apache-tomcat-${VERSION}/conf/web.xml \
--config-files usr/local/share/apache-tomcat-${VERSION}/conf/context.xml \
--config-files usr/local/share/apache-tomcat-${VERSION}/conf/catalina.policy \
--config-files usr/local/share/apache-tomcat-${VERSION}/conf/catalina.properties \
--config-files usr/local/share/apache-tomcat-${VERSION}/conf/tomcat-users.xml \
--config-files usr/local/share/apache-tomcat-${VERSION}/conf/logging.properties \
--config-files usr/local/share/apache-tomcat-${VERSION}/conf/server.xml \
--description "Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies." \
--url 'http://tomcat.apache.org/' \
usr
# Add these?
# --pre-install ./tomcat.preinstall \
# --post-install ./tomcat.postinstall \
@alfredocambera
Copy link

Very useful!. It came handy to create my custom tomcat package. Thanks for sharing

@Naramsim
Copy link

Naramsim commented Nov 2, 2016

Does this .deb provide the init.d scripts to start/stop tomcat?
@stuart-warren

@ukreddy-erwin
Copy link

I need to install tomcat Version 9.0.35 and deploy some war files and install some related files. Can you suggest how to do this.

So, direct dumping of files is not an option.I got one sh file for that.Main page link The required prerequisite is installed.

In the sh file, changed the URL and updated the curl file to this link It is a different version of tomcat but still used for testing.

But I am getting this error.

Invalid package configuration: Cannot chdir to 'tomcat-packaging/'. Does it exist? {:level=>:error}

I guess this folder should be there but missing details about it. So deleted that folder line and tried. Now, getting this error:

Missing required -s flag. What package source did you want? {:level=>:warn} Missing required -t flag. What package output did you want? {:level=>:warn} No parameters given. You need to pass additional command arguments so that I know what you want to build packages from. For example, for '-s dir' you would pass a list of files and directories. For '-s gem' you would pass a one or more gems to package from. As a full example, this will make an rpm of the 'json' rubygem: fpm -s gem -t rpm json {:level=>:warn}

My modified sh file:

#!/bin/bash -xe

sudo gem install fpm

sudo apt-get install curl

# Put this script in a folder called tomcat-packaging

./mkdeb.sh 7.0.40

./mkdeb.sh 6.0.37

VERSION=$1
VERSION_=${VERSION//./}
MAJOR=${VERSION:0:1}

rm -rf ./usr/local/*
mkdir -p ./usr/local/share/
pushd ./usr/local/share/
curl "https://mirrors.estointernet.in/apache/tomcat/tomcat-${MAJOR}/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz" | tar -xz
#curl "http://mirror.catn.com/pub/apache/tomcat/tomcat-${MAJOR}/v${VERSION}/bin/apache-tomcat-${VERSION}.tar.gz" | tar -xz
popd
cd ..
rm -f *.deb

fpm -n tomcat${VERSION_} \
    -v ${VERSION}-0custom1 \
    -d default-jre \
    -a all \
    --vendor apache \
    --license 'Apache Version 2.0' \
    #-C tomcat-packaging/ \
    -m "DSI <dsi@custom.com>" \
    -t deb \
    -s dir \
    --config-files usr/local/share/apache-tomcat-${VERSION}/conf/web.xml \
    --config-files usr/local/share/apache-tomcat-${VERSION}/conf/context.xml \
    --config-files usr/local/share/apache-tomcat-${VERSION}/conf/catalina.policy \
    --config-files usr/local/share/apache-tomcat-${VERSION}/conf/catalina.properties \
    --config-files usr/local/share/apache-tomcat-${VERSION}/conf/tomcat-users.xml \
    --config-files usr/local/share/apache-tomcat-${VERSION}/conf/logging.properties \
    --config-files usr/local/share/apache-tomcat-${VERSION}/conf/server.xml \
    --description "Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies." \
    --url 'http://tomcat.apache.org/' \
    usr

Add these?

--pre-install ./tomcat.preinstall \

--post-install ./tomcat.postinstall \

I am running the file as below.

./tomcatdeb.sh 9.0.43

@stuart-warren
Copy link
Author

I need to install tomcat Version 9.0.35 and deploy some war files and install some related files. Can you suggest how to do this?

Sorry, I haven't touched Tomcat in 7 years. I'd assume there is a package available by now, or at least a better process to build one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment