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