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