Penguin

Everyone has to generate configuration files, and basically they're the same across multiple machines, normally with different IP addresses.

m4(1) is the GNU macro processor. You may recognise it from such tools as autoconf(1) and SendMail. Here are some cool things you can do with it.

config.m4

This file will basically define our variables. We later include it in all our other files. The command divert is used to divert to a numbered temporary stream where you can reinsert it later. In this case, we dont want these commands to be inserted into any of our output files, because they are definitions. So we divert(-1), and they don't get displayed.

The divert(0)dnl at the end returns to the main output without a line feed (DNL == do not linefeed.)

divert(-1) define(conf_INTIF,`10.7.0.254') define(conf_INTNET,`10.7.0.0') define(conf_INTBCAST,`10.7.0.255') divert(0)dnl

Makefile

As always with makefiles, you can do lots of magic here. See MakefileHowto for a lot of useful information.

FILES=interfaces all: $(FILES) DESTDIR ?= ./etc

interfaces: interfaces.m4

%:%.m4

m4 < $< > $@

install

cp -f interfaces $(DESTDIR)/network/

The magic is all in the m4 section: that rule says to build any file % from a %.m4, pipe the .m4 file into the m4 command (confused yet?) and then divert the output into the eventual file.

Basically, what this does is lets you define files like this:

interfaces.m4

include(`config.m4')dnl

  1. /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
  2. The loopback interface

auto lo iface lo inet loopback

  1. Internal network connection: eth0

auto eth0 iface eth0 inet static

address conf_INTIF netmask conf_INTMASK broadcast conf_INTBCAST

We include the file we created before (with another DNL). The m4 processor will go through the config.m4 file you have included and generate a file like this:

interfaces (automatically generated by m4 with a simple 'make')

  1. /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
  2. The loopback interface

auto lo iface lo inet loopback

  1. Internal network connection: eth0

auto eth0 iface eth0 inet static

address 10.7.0.254 netmask 255.255.255.0 broadcast 10.7.0.255

lib/main.php:944: Notice: PageInfo: Cannot find action page

lib/main.php:839: Notice: PageInfo: Unknown action