Penguin
Blame: ConfigurationScripts
EditPageHistoryDiffInfoLikePages
Annotated edit history of ConfigurationScripts version 3, including all changes. View license author blame.
Rev Author # Line
1 CraigBox 1 Everyone has to generate configuration files, and basically they're the same across multiple machines, normally with different IP addresses.
2
3 JohnMcPherson 3 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.
1 CraigBox 4
5 !config.m4
2 CraigBox 6
7 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.
8
9 The divert(0)dnl at the end returns to the main output without a line feed (DNL == do not linefeed.)
1 CraigBox 10
11 divert(-1)
12 define(conf_INTIF,`10.7.0.254')
13 define(conf_INTNET,`10.7.0.0')
14 define(conf_INTBCAST,`10.7.0.255')
15 divert(0)dnl
16
17 !Makefile
18
19 As always with makefiles, you can do lots of magic here. See MakefileHowto for a lot of useful information.
20
21 FILES=interfaces
22 all: $(FILES)
23 DESTDIR ?= ./etc
24
25 interfaces: interfaces.m4
26
27 %:%.m4
28 m4 < $< > $@
29
30 install:
31 cp -f interfaces $(DESTDIR)/network/
32
33 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.
34
35 Basically, what this does is lets you define files like this:
36
37 !interfaces.m4
38
39 include(`config.m4')dnl
40 # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
41
42 # The loopback interface
43 auto lo
44 iface lo inet loopback
45
46 # Internal network connection: eth0
47 auto eth0
48 iface eth0 inet static
49 address conf_INTIF
50 netmask conf_INTMASK
51 broadcast conf_INTBCAST
52
2 CraigBox 53 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:
1 CraigBox 54
55 !interfaces (automatically generated by m4 with a simple 'make')
56
57 # /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)
58
59 # The loopback interface
60 auto lo
61 iface lo inet loopback
62
63 # Internal network connection: eth0
64 auto eth0
65 iface eth0 inet static
66 address 10.7.0.254
67 netmask 255.255.255.0
68 broadcast 10.7.0.255