1 |
#!/bin/sh |
2 |
|
3 |
# Default values |
4 |
|
5 |
destdir="/usr/local" |
6 |
bindir="$destdir/bin" |
7 |
mandir="$destdir/man" |
8 |
|
9 |
debug="yes" |
10 |
checkperms="yes" |
11 |
encpasswds="yes" |
12 |
ssltls="yes" |
13 |
cram="yes" |
14 |
|
15 |
libs="" |
16 |
libssl="-lssl" |
17 |
libcrypto="-lcrypto" |
18 |
|
19 |
cflags="" |
20 |
ldflags="" |
21 |
|
22 |
interactive="no" |
23 |
|
24 |
|
25 |
# Get options and arguments |
26 |
|
27 |
while getopts "hid:b:m:o:" opt |
28 |
do |
29 |
case $opt in |
30 |
d) |
31 |
destdir=$OPTARG |
32 |
bindir=$destdir/bin |
33 |
mandir=$destdir/man |
34 |
;; |
35 |
b) |
36 |
bindir=$OPTARG |
37 |
;; |
38 |
m) |
39 |
mandir=$OPTARG |
40 |
;; |
41 |
o) |
42 |
head=`echo $OPTARG | cut -d= -f1` |
43 |
body=`echo $OPTARG | cut -d= -f2` |
44 |
if [ $head = "debug" ] |
45 |
then |
46 |
if [ $body = "yes" ]; then debug="yes" |
47 |
elif [ $body = "no" ]; then debug="no" |
48 |
fi |
49 |
elif [ $head = "checkperms" ] |
50 |
then |
51 |
if [ $body = "yes" ]; then checkperms="yes" |
52 |
elif [ $body = "no" ]; then checkperms="no" |
53 |
fi |
54 |
elif [ $head = "encpasswds" ] |
55 |
then |
56 |
if [ $body = "yes" ]; then encpasswds="yes" |
57 |
elif [ $body = "no" ]; then encpasswds="no" |
58 |
fi |
59 |
elif [ $head = "ssltls" ] |
60 |
then |
61 |
if [ $body = "yes" ]; then ssltls="yes" |
62 |
elif [ $body = "no" ]; then ssltls="no" |
63 |
fi |
64 |
elif [ $head = "cram" ] |
65 |
then |
66 |
if [ $body = "yes" ]; then cram="yes" |
67 |
elif [ $body = "no" ]; then cram="no" |
68 |
fi |
69 |
fi |
70 |
;; |
71 |
i) |
72 |
interactive="yes" |
73 |
;; |
74 |
h | *) |
75 |
cat << EOF |
76 |
Usage: |
77 |
config [-hi] [-d destdir] [-b bindir] [-m mandir] [-o option=argument] |
78 |
|
79 |
Description: |
80 |
-h This brief usage and description message. |
81 |
-i Interactive mode. |
82 |
-d destdir Installation path for program's files [$destdir] |
83 |
-b bindir Installation path for binaries [$bindir] |
84 |
-m mandir Installation path for manual pages [$mandir] |
85 |
-o option=argument Enabling/disabling of program's options. |
86 |
|
87 |
Options: |
88 |
debug Debugging information, useful during development [$debug] |
89 |
checkperms Configuration file's permissions checking [$checkperms] |
90 |
encpasswds Encrypted passwords support [$encpasswds] |
91 |
ssltls Secure Socket Layer and Transport Layer Security [$ssltls] |
92 |
cram Challenge-Response Authentication Mechanism [$cram] |
93 |
EOF |
94 |
exit 1 |
95 |
;; |
96 |
esac |
97 |
done |
98 |
|
99 |
|
100 |
# Interactive or non-interactive mode |
101 |
|
102 |
if [ $interactive = "yes" ] |
103 |
then |
104 |
printf "Destination directory [$destdir]: " |
105 |
read tmp |
106 |
if [ -n "$tmp" ]; then destdir="$tmp"; fi |
107 |
|
108 |
printf "Binaries directory [$bindir]: " |
109 |
read tmp |
110 |
if [ -n "$tmp" ]; then bindir="$tmp"; fi |
111 |
|
112 |
printf "Manual pages directory [$mandir]: " |
113 |
read tmp |
114 |
if [ -n "$tmp" ]; then mandir="$tmp"; fi |
115 |
|
116 |
printf "Debugging information [$debug]: " |
117 |
read tmp |
118 |
if [ -n "$tmp" ]; then debug="$tmp"; fi |
119 |
|
120 |
printf "Configuration file permissions checking [$checkperms]: " |
121 |
read tmp |
122 |
if [ -n "$tmp" ]; then checkperms="$tmp"; fi |
123 |
|
124 |
printf "Encrypted passwords support [$encpasswds]: " |
125 |
read tmp |
126 |
if [ -n "$tmp" ]; then encpasswds="$tmp"; fi |
127 |
|
128 |
printf "Secure Socket Layer and Transport Layer Security [$ssltls]: " |
129 |
read tmp |
130 |
if [ -n "$tmp" ]; then ssltls="$tmp"; fi |
131 |
|
132 |
printf "Challenge-Response Authentication Mechanism [$cram]: " |
133 |
read tmp |
134 |
if [ -n "$tmp" ]; then cram="$tmp"; fi |
135 |
else |
136 |
cat << EOF |
137 |
Destination directory: $destdir |
138 |
Binaries directory: $bindir |
139 |
Manual pages directory: $mandir |
140 |
Debugging information: $debug |
141 |
Configuration file permissions checking: $checkperms |
142 |
Encrypted passwords support: $encpasswds |
143 |
Secure Socket Layer and Transport Layer Security: $ssltls |
144 |
Challenge-Response Authentication Mechanism: $cram |
145 |
EOF |
146 |
fi |
147 |
|
148 |
|
149 |
# Libraries |
150 |
|
151 |
if [ $ssltls = "yes" ] |
152 |
then |
153 |
libs="$libs $libssl $libcrypto" |
154 |
elif [ $encpasswds = "yes" ] || [ $cram = "yes" ] |
155 |
then |
156 |
libs="$libs $libcrypto" |
157 |
fi |
158 |
|
159 |
|
160 |
# C flags |
161 |
|
162 |
if [ $debug = "yes" ] |
163 |
then |
164 |
cflags="-g" |
165 |
else |
166 |
cflags="-O" |
167 |
fi |
168 |
|
169 |
|
170 |
# Backup of original Makefile and config.h |
171 |
|
172 |
if [ ! -f .Makefile ]; then cp -f Makefile .Makefile; fi |
173 |
if [ ! -f .config.h ]; then cp -f config.h .config.h; fi |
174 |
|
175 |
|
176 |
# Write Makefile |
177 |
|
178 |
mv -f Makefile Makefile~ |
179 |
|
180 |
cat > Makefile << EOF |
181 |
CC = cc |
182 |
CFLAGS = $cflags |
183 |
LDFLAGS = |
184 |
|
185 |
DESTDIR = $destdir |
186 |
BINDIR = $bindir |
187 |
MANDIR = $mandir |
188 |
|
189 |
MAN_BIN = imapfilter.1 |
190 |
MAN_RC = imapfilterrc.5 |
191 |
|
192 |
BIN = imapfilter |
193 |
OBJ = account.o action.o auth.o buffer.o cert.o destroy.o file.o filter.o \\ |
194 |
imap.o imapfilter.o lock.o log.o match.o memory.o misc.o parse.o \\ |
195 |
passwd.o response.o request.o socket.o tty.o |
196 |
|
197 |
LIBS = $libs |
198 |
|
199 |
all: imapfilter |
200 |
|
201 |
imapfilter: \$(OBJ) |
202 |
\$(CC) \$(LIBS) \$(LDFLAGS) -o \$(BIN) \$(OBJ) |
203 |
|
204 |
account.o action.o auth.o buffer.o cert.o destroy.o file.o filter.o imap.o \\ |
205 |
imapfilter.o lock.o log.o match.o memory.o parse.o passwd.o \\ |
206 |
request.o response.o socket.o tty.o: config.h imapfilter.h |
207 |
account.o destroy.o filter.o imapfilter.o match.o: account.h |
208 |
destroy.o filter.o imapfilter.o match.o: filter.h |
209 |
account.o filter.o: struct.h |
210 |
buffer.o imap.o imapfilter.o response.o: buffer.h |
211 |
cert.o file.o lock.o parse.o: pathnames.h |
212 |
imapfilter.o: version.h |
213 |
|
214 |
install: imapfilter |
215 |
if test ! -d \$(BINDIR); then mkdir -p \$(BINDIR); fi |
216 |
cp -f \$(BIN) \$(BINDIR) && chmod 0755 \$(BINDIR)/\$(BIN) |
217 |
if test ! -d \$(MANDIR)/man1; then mkdir -p \$(MANDIR)/man1; fi |
218 |
cp -f \$(MAN_BIN) \$(MANDIR)/man1 && chmod 0644 \$(MANDIR)/man1/\$(MAN_BIN) |
219 |
if test ! -d \$(MANDIR)/man5; then mkdir -p \$(MANDIR)/man5; fi |
220 |
cp -f \$(MAN_RC) \$(MANDIR)/man5 && chmod 0644 \$(MANDIR)/man5/\$(MAN_RC) |
221 |
|
222 |
deinstall: |
223 |
rm -f \$(BINDIR)/\$(BIN) \$(MANDIR)/man1/\$(MAN_BIN) \$(MANDIR)/man5/\$(MAN_RC) |
224 |
|
225 |
uninstall: deinstall |
226 |
|
227 |
clean: |
228 |
rm -f \$(OBJ) \$(BIN) imapfilter.core core *.BAK *~ |
229 |
|
230 |
distclean: clean |
231 |
@if test -f .Makefile; then mv -f .Makefile Makefile; fi |
232 |
@if test -f .config.h; then mv -f .config.h config.h; fi |
233 |
EOF |
234 |
|
235 |
|
236 |
# Write config.h |
237 |
|
238 |
mv -f config.h config.h~ |
239 |
|
240 |
echo "#ifndef CONFIG_H" > config.h |
241 |
echo "#define CONFIG_H" >> config.h |
242 |
echo >> config.h; echo >> config.h |
243 |
|
244 |
echo "/* Debugging information. */" >> config.h |
245 |
if [ $debug = "yes" ] |
246 |
then |
247 |
echo "#define DEBUG" >> config.h |
248 |
else |
249 |
echo "#undef DEBUG" >> config.h |
250 |
fi |
251 |
echo >> config.h |
252 |
|
253 |
echo "/* Configuration file's permissions checking. */" >> config.h |
254 |
if [ $checkperms = "yes" ] |
255 |
then |
256 |
echo "#define CHECK_PERMISSIONS" >> config.h |
257 |
else |
258 |
echo "#undef CHECK_PERMISSIONS" >> config.h |
259 |
fi |
260 |
echo >> config.h |
261 |
|
262 |
echo "/* Encrypted passwords support. */" >> config.h |
263 |
if [ $encpasswds = "yes" ] |
264 |
then |
265 |
echo "#define ENCRYPTED_PASSWORDS" >> config.h |
266 |
else |
267 |
echo "#undef ENCRYPTED_PASSWORDS" >> config.h |
268 |
fi |
269 |
echo >> config.h |
270 |
|
271 |
echo "/* Secure Socket Layer and Transport Layer Security support. */" >> config.h |
272 |
if [ $ssltls = "yes" ] |
273 |
then |
274 |
echo "#define SSL_TLS" >> config.h |
275 |
else |
276 |
echo "#undef SSL_TLS" >> config.h |
277 |
fi |
278 |
echo >> config.h |
279 |
|
280 |
echo "/* Challenge-Response Authentication Mechanism support. */" >> config.h |
281 |
if [ $cram = "yes" ] |
282 |
then |
283 |
echo "#define CRAM_MD5" >> config.h |
284 |
else |
285 |
echo "#undef CRAM_MD5" >> config.h |
286 |
fi |
287 |
|
288 |
echo >> config.h; echo >> config.h |
289 |
echo "#endif /* CONFIG_H */" >> config.h |
290 |
|
291 |
|
292 |
exit 0 |