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