Commit | Line | Data |
---|---|---|
e0f3765a PH |
1 | From: John Jetmore <jetmore@cinergycom.com> |
2 | Date: Wed, 24 Sep 2003 13:12:58 -0500 (CDT) | |
3 | ||
4 | I'm sure that everyone who's interested in something like this has already | |
5 | come up with their own way to do this, but here's my solution: | |
6 | ||
7 | When I moved from smail to exim I built a program that took individual | |
8 | config pieces stripped all the comments and built a config file. As a | |
9 | bonus, it also runs exim -C <testfile> -bV on the new file and reports any | |
10 | config errors before copying it over the old config. In addition to just | |
11 | being familiar in general w/ all the files being broken up according to | |
12 | their major categories, I also got the benfit of being able to have config | |
13 | pieces that were easily updatable (just replace the whole file and rebuild | |
14 | the configure file). | |
15 | ||
16 | The script has some site-specific stuff hard coded, but it's easily | |
17 | fixable. Essentially in my exim configd I have a directory called | |
18 | subconfigure, which can contain directories named \d\d.\w+. Mine | |
19 | currently contains: | |
20 | 10.general/ 30.routers/ 50.retry/ 70.authenticators/ | |
21 | 20.acls/ 40.transports/ 60.rewrite/ 80.local_scan/ | |
22 | ||
23 | Each of these directories can contain files in the form \d\d.\w+. For | |
24 | instance, my 30.routers contains: | |
25 | 00.begin 80.l_user_delivery_normal _50.l_mx | |
26 | 10.r_forcepaths _12.r_static_route_junk _60.l_psp | |
27 | 15.r_stalemail _17.r_internal_route _72.l_aliases_list | |
28 | 33.r_mailrtrd_router _20.r_conditionalforce _74.l_aliases_isp | |
29 | 40.r_standard _31.r_mailrtrd_bypass_spam _76.l_aliases_mer | |
30 | 70.l_aliases _39.r_smarthost _80.l_user_delivery_isp | |
31 | ||
32 | those files prefixed by "_" will not be used to build the live configure | |
33 | file. They are "turned off". This allows me to keep a general list of | |
34 | configure pieces that are easily updatable but not necessarily every rule | |
35 | is used on every machine. Not every file contains a single router - for | |
36 | instance 60.l_psp is our virtual hosting solution and contains 10 routers. | |
37 | They're just grouped by logical role. | |
38 | ||
39 | All of these sub pieces are built in to the configure file w/ a shell | |
40 | script called mkconfigure, inline below. Again, my assumption is that | |
41 | anyone who wants a system like this built it for themselves, but it | |
42 | would be kind of fun to flesh this script out to be more generic. | |
43 | Maybe post it and some samples on a webpage. Or no one responds to this | |
44 | and I shut up about it =). | |
45 | ||
46 | This system is way overkill for some people (for instance, my home machine | |
47 | uses a single configure file because I don't do that much special with | |
48 | it), but it's useful in a larger system role. | |
49 | ||
50 | --John | |
51 | ||
52 | mkconfigure: | |
53 | ||
54 | #!/bin/ksh | |
55 | ||
56 | # I have found that our custom set up of exim's configure file is overly | |
57 | # confusing. To help alleviate this, I have broken the file out into its | |
58 | # core pieces (general, tansports, directors, routers, retry, rewrite, and | |
59 | # authentication), and then each of those into logical sub-pieces (SIS, | |
60 | # for instance. This program is to take all of those sub pieces and put | |
61 | # them back together into the file that exim understands. | |
62 | ||
63 | # No one should every touch the 'configure' file from now on, one should | |
64 | # instead manipulate the files in the subconfigure directory and run this | |
65 | # program | |
66 | ||
67 | # jetmore 20011119 | |
68 | ||
69 | EXIMD=$1 | |
70 | CONFIGSUFF=$2 | |
71 | ||
72 | if [ "X$EXIMD" == "X" ] ; then | |
73 | EXIMD=/local/exim | |
74 | fi | |
75 | if [ ! -d "$EXIMD" ] ; then | |
76 | echo "$EXIMD is not a directory" >&2 | |
77 | exit 1 | |
78 | fi | |
79 | ETCD=$EXIMD/etc | |
80 | SUBCD=$ETCD/subconfigure$CONFIGSUFF | |
81 | CONFIGF=$ETCD/configure$CONFIGSUFF | |
82 | ||
83 | if [ ! -d $SUBCD ] ; then | |
84 | echo "$SUBCD is not a directory" >&2 | |
85 | exit 1 | |
86 | fi | |
87 | ||
88 | GREP=/bin/grep | |
89 | ||
90 | # initialize the temporary config file in case some trash got left around | |
91 | cat /dev/null > $CONFIGF.t | |
92 | ||
93 | # print the banner to the temp config file | |
94 | echo >> $CONFIGF.t | |
95 | echo "#########################################################" >> $CONFIGF.t | |
96 | echo "# DO NOT DIRECTLY MANIPULATE THIS FILE " >> $CONFIGF.t | |
97 | echo "# " >> $CONFIGF.t | |
98 | echo "# if you need to make configuration change, do so in " >> $CONFIGF.t | |
99 | echo "# $SUBCD and run the mkconfigure" >> $CONFIGF.t | |
100 | echo "# command. Changes made to this file will be lost " >> $CONFIGF.t | |
101 | echo "# " >> $CONFIGF.t | |
102 | echo "# See jetmore w/ questions " >> $CONFIGF.t | |
103 | echo "#########################################################" >> $CONFIGF.t | |
104 | echo >> $CONFIGF.t | |
105 | ||
106 | # get the major categories | |
107 | for CAT in $SUBCD/[0-9]* | |
108 | do | |
109 | # print which category we're in | |
110 | echo >> $CONFIGF.t | |
111 | echo "## major category $CAT" >> $CONFIGF.t | |
112 | echo >> $CONFIGF.t | |
113 | ||
114 | # get the subcategories | |
115 | for SUBCAT in $CAT/[0-9]* | |
116 | do | |
117 | # print which sub category we're in | |
118 | echo "## sub category $SUBCAT" >> $CONFIGF.t | |
119 | echo >> $CONFIGF.t | |
120 | ||
121 | # place the contents of any non-comment line into the configure file | |
122 | $GREP -v "^ *#" $SUBCAT >> $CONFIGF.t | |
123 | echo >> $CONFIGF.t | |
124 | done | |
125 | done | |
126 | ||
127 | # check and make sure there aren't any typos in the new config file | |
128 | $EXIMD/bin/exim -C $CONFIGF.t -bV > $CONFIGF.test 2>&1 | |
129 | if [ "$?" -eq "1" ] ; then | |
130 | #/bin/rm $CONFIGF.t | |
131 | echo | |
132 | echo "There is a problem with the configure file. " | |
133 | echo "moving paniclog to paniclog.mkfail" | |
134 | echo "$CONFIGF.test has details:" | |
135 | echo | |
136 | echo ##################################################################### | |
137 | cat $CONFIGF.test | |
138 | echo ##################################################################### | |
139 | echo | |
140 | echo "$CONFIGF not changed!" | |
141 | /bin/mv -f /log/exim/paniclog /log/exim/paniclog.mkfail | |
142 | exit 1 | |
143 | fi | |
144 | /bin/rm $CONFIGF.test | |
145 | ||
146 | /bin/mv $CONFIGF.t $CONFIGF | |
147 | echo "$CONFIGF updated successfully." | |
148 | echo "Don't forget to HUP the mail daemon" | |
149 | exit 0 | |
150 |