6. Create RPMs of Your Fonts

Do not just throw .ttf files someplace on your system. It makes migrations more difficult, and makes a big mess in your computer. Package management software like RPM lets you easily install your fonts in an organized standard way, manage font upgrades, and make massive font distribution a piece of cake.

Here we'll provide templates and instructions for you to easily build RPM packages of your fonts. We'll accept contributions with instructions to build different types of packages.

6.1. Step 1: Prepare Your Environment to Build The Package

To build RPMs, you need a special structure of directories and some configurations on your environment. You should do everything as a regular user, in all steps. In fact, we recommend that you do not do this as root.

To create this directories, do this:


bash$ cd ~
bash$ mkdir -p src/rpm
bash$ cd src/rpm
bash$ cp -r /usr/src/redhat/* .
bash$ ls
BUILD/  RPMS/  SOURCES/  SPECS/  SRPMS/
bash$ 
			

(the "~" is an alias to the current user's home directory name, and the command line knows it should interpret it this way)

Of course this is on a Red Hat system, but the important point is to have the following directories under src/rpm:

Then, you'll have to create the .rpmmacros file in you home directory, with this single line content:


%_topdir        YOUR_HOME_DIR_HERE/src/rpm
			

And you should substitute YOUR_HOME_DIR_HERE with the absolute name of your $HOME directory. So as an example, my .rpmmacros file contains this line:


%_topdir        /home/aviram/src/rpm
			

6.2. Step 2: Prepare the Fonts Files to Package

Now you must think about a name for your font collection. To make things easy in this documentation, we'll use the name myfonts from now on. Then you must create a directory named ~/src/myfonts/myfonts (yes, myfonts two times) and put all your .ttf files right under it. So you'll have something like:


bash$ cd ~/src
bash$ find myfonts/myfonts/

myfonts/myfonts/
myfonts/myfonts/font1.ttf
myfonts/myfonts/font2.ttf
myfonts/myfonts/font3.ttf
...

			

6.3. Step 3: Create a .spec File With This Template

To build an RPM package you'll have to create a .spec file that provides instructions to the package builder on how to organize the files, package description, author, copyright, etc. We provide a template here that you can use to start your work. The template looks like this:

Example 1. The .spec file template


Name: myfonts     (1)
Summary: Collection of My Funny Fonts   (2)
Version: 1.1   (3)
Release: 1
License: GPL    (4)
Group: User Interface/X
Source: %{name}.tar.gz
BuildRoot: %{_tmppath}/build-root-%{name}
BuildArch: noarch
Requires: freetype
Packager: Avi Alkalay <avi unix sh>    (5)
Prefix: /usr/share/fonts
Url: http://myfonts.com/     (6)

%description    (7)
These are the fonts used in our marketing campaign, designed by our marketing agency specially for us.
The package includes the following fonts: Font 1, Font 2, Font 3, Font 4.


%prep

%setup -q -n %{name}

%build

%install
mkdir -p $RPM_BUILD_ROOT/%{prefix}
cp -r %{name}/ $RPM_BUILD_ROOT/%{prefix}


%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,0755)
%{prefix}/%{name}


%post
{
	if test -x /sbin/conf.d/SuSEconfig.fonts ; then
		# This is a SUSE system. Use proprietary SuSE tools...
		if test "$YAST_IS_RUNNING" != "instsys" ; then
			if test -x /sbin/SuSEconfig -a -f /sbin/conf.d/SuSEconfig.fonts ; then
				/sbin/SuSEconfig --module fonts
			else
				echo -e "\nERROR: SuSEconfig or requested SuSEconfig module not present!\n" ; exit 1
			fi
		fi

		if test -x /sbin/conf.d/SuSEconfig.pango ; then
			if test "$YAST_IS_RUNNING" != "instsys" ; then 
				if test -x /sbin/SuSEconfig -a -f /sbin/conf.d/SuSEconfig.pango ; then
					/sbin/SuSEconfig --module pango
				else
					echo -e "\nERROR: SuSEconfig or requested SuSEconfig module not present!\n" ; exit 1
				fi
			fi
		fi
	else
		# Use regular open standards methods...
		ttmkfdir -d %{prefix}/%{name} \
			-o %{prefix}/%{name}/fonts.scale
		umask 133
		/usr/X11R6/bin/mkfontdir %{prefix}/%{name}
		/usr/sbin/chkfontpath -q -a %{prefix}/%{name}
		[ -x /usr/bin/fc-cache ] && /usr/bin/fc-cache
	fi
} &> /dev/null || :


%preun
{
	if [ "$1" = "0" ]; then
		cd %{prefix}/%{name}
		rm -f fonts.dir fonts.scale fonts.cache*
	fi
} &> /dev/null || :

%postun

{
	if test -x /sbin/conf.d/SuSEconfig.fonts ; then
		# This is a SUSE system. Use proprietary SuSE tools...
		if test "$YAST_IS_RUNNING" != "instsys" ; then
			if test -x /sbin/SuSEconfig -a -f /sbin/conf.d/SuSEconfig.fonts ; then
				/sbin/SuSEconfig --module fonts
			else
				echo -e "\nERROR: SuSEconfig or requested SuSEconfig module not present!\n" ; exit 1
			fi
		fi

		if test -x /sbin/conf.d/SuSEconfig.pango ; then
			if test "$YAST_IS_RUNNING" != "instsys" ; then 
				if test -x /sbin/SuSEconfig -a -f /sbin/conf.d/SuSEconfig.pango ; then
					/sbin/SuSEconfig --module pango
				else
					echo -e "\nERROR: SuSEconfig or requested SuSEconfig module not present!\n" ; exit 1
				fi
			fi
		fi
	else
		# Use regular open standards methods...
		if [ "$1" = "0" ]; then
			/usr/sbin/chkfontpath -q -r %{prefix}/%{name}
		fi
		[ -x /usr/bin/fc-cache ] && /usr/bin/fc-cache
	fi
} &> /dev/null || :








%changelog    (8)
* Sun Apr 15 2007 Avi Alkalay <avi unix sh> 1.1
- Added support to SUSE on installation scriptlets
* Thu Dec 14 2002 Avi Alkalay <avi unix sh> 1.0
- Tested
- Ready for deployment
* Thu Dec 10 2002 Avi Alkalay <avi unix sh> 0.9
- First version of the template

					

You must change the following items to meet your package characteristic's (leave everything else untouched):

(1)
Put the name of your package or font collection here.
(2)
Put a brief summary about your package here.
(3)
The version of the package.
(4)
The usage license of your package here.
(5)
The name of the person responsible for this package here.
(6)
URL to get more info about this package or fonts here. This entire line can be removed if there is no URL to point to.
(7)
A more detailed description about this fonts here.
(8)
The evolution history of this package here. Must follow this layout.

This file must be named as the name of the package - myfonts.spec in our example. And you must put it under the main directory of the package. So in the end we'll have something like this:


bash$ cd ~/src
bash$ find myfonts
myfonts/
myfonts/myfonts.spec
myfonts/myfonts/
myfonts/myfonts/font1.ttf
myfonts/myfonts/font2.ttf
myfonts/myfonts/font3.ttf
...

			

6.4. Step 4: Build It

We are almost ready to go. Next steps:


bash$ cd ~/src
bash$ tar -czvf myfonts.tar.gz myfonts
bash$ rpmbuild -ta myfonts.tar.gz
			

Done (after seeing a lot of messages about the building process). So we basically created a .tar.gz containing all our font files and myfonts.spec, and then we used rpmbuild on it, that will look for myfonts.spec inside the archive and follow its instructions.

You'll find the generated RPM under ~/src/rpm/RPMS/noarch/ directory, and this is the file you'll deploy and install. Under ~/src/rpm/SRPMS/ you'll find the source RPM file, which you should backup if you need to regenerate the deployable RPM again in the future. When you'll need it, you should do:


bash$ rpmbuild --rebuild myfonts-1.0-1.src.rpm
			

And the RPM file will be generated again.

For more information and advanced RPM packaging, read the Maximum RPM book, available in many formats in the rpm.org site.