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