-
This article presumes the reader has a good working knowledge of the FreeBSD ports system. For more information see the ports manpage, the FreeBSD handbooks section on ports and the FreeBSD porters handbook.
-
The FreeBSD ports tree is great, but when it comes to making changes to the files that are installed by a port you have to be careful so as not to lose any changes when you upgrade. Say you install a port like the
Serendipity weblog software, then go to
modify a template. Everything works great but unfortunately when you next use
portupgrade you find the changes you made were all clobbered by the upgrade! Not good.
There are a few solutions to this problem, but probably the most natural method - in terms of keeping with the ports system and your own changes in harmony - is to create your own custom patch files and place them inside the
port's 'files' directory. This way when you install or upgrade a port, the files you want patching to include your modifications will automatically be patched.
Here's a simple example using this weblog, Serendipity. I want to modify the template I'm using so it includes a
Google Analytics tracker in each and every page to help track web usage. The easiest way to do this is to modify the index.tpl file so it includes the analytics tracker code just before the closing </body> tag of the index.tpl file.
To make the changes permanent after an upgrade, instead of just going ahead and modifying the 'live' index.tpl that's already installed I'm going to make the changes to the index.tpl file located in the serendipity ports working directory 'work' and then create a patch file that will transform the original index.tpl to the modified index.tpl.
To do this step by step:
Ensure the working directory for serendipity is available - to do this run 'make extract' to extract the distfile's contents into the 'work' directory:
CODE:
root@users /home/munk/ports/www/serendipity# cd /usr/ports/www/serendipity/
root@users /home/munk/ports/www/serendipity# make extract
===> Found saved configuration for serendipity-1.0.1
===> Extracting for serendipity-1.0.1
=> MD5 Checksum OK for serendipity-1.0.1.tar.gz.
=> SHA256 Checksum OK for serendipity-1.0.1.tar.gz.
Move into the template directory and create a copy of the file you want to modify, naming it <file>.orig, where <file> is the name of the file to be modified:
CODE:
root@users /home/munk/ports/www/serendipity# cd work/serendipity/templates/contest/
root@users /home/munk/ports/www/serendipity/work/serendipity/templates/contest# cp index.tpl
index.tpl.orig
Make the changes to the file you're modifying - note NOT the .orig file! - in this case I need to make changes to index.tpl to add the following before the ending