I am making an Ubuntu package that depends on Tomcat7 through HTTPS. To make it convenient for our customers, I would like the install script of the package enable HTTPS in Tomcat7. This is pretty easy to do manually; in the file /etc/tomcat7/server.xml, one needs to uncomment the following block:
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->
How could I do this from a shellscript? Preferebly in a way that it still works for slight modifications of the exact pattern. I think the rule would be something along the lines of search for '<Connector port="8443"' and then remove <!-- and --> before and after the block.
Consider apply a patch on your
server.xml.Generating a patch file:
Where
server.xml.oldis the original file, andserver.xml.newis the file as you want.The patch (
mydiff.patch) will look like this:Then, just apply the patch:
You can run the
patchcommand with the flag-N. Thus, it will skip files that seems already patched.