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