Adapt security plugin to new configuration model
[MonkeyD.git] / configure
blob7d035998f0a7c788601a0877401ebeeae8f07819
1 #!/bin/bash
3 # Monkey HTTP Daemon
4 # ------------------
5 # Copyright (C) 2001-2009, Eduardo Silva P.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 VERSION="0.11.0-dev"
22 SYSNAME=`uname -s`
23 SYSINFO=`uname -sr`
25 INCDIR="src/include/"
27 messages_en()
29 case "$*" in
30 "1")
31 echo "+ Creating conf/monkey.conf"
33 "2")
34 echo "+ Creating Makefile"
36 "3")
37 echo "+ Creating src/Makefile"
39 "4")
40 echo "+ Creating src/include/info.h"
42 "5")
43 echo "+ Creating banana script"
45 "6")
46 echo -n "Configuration done, just type 'make"
48 "7")
49 echo -n "+ Checking for Pthreads lib.........."
51 esac
54 # Create configuration files under 'conf/'
55 make_conf()
57 cat $INCDIR/config.path lang/"$*"/mconf lang/"$*"/sites/default > makeconf.sh
58 chmod 755 makeconf.sh
59 ./makeconf.sh
60 rm makeconf.sh
61 rm $INCDIR/config.path
64 local_dirs()
66 bin="bin"
67 logs="logs"
68 sites="conf/sites"
70 if [ ! -d $bin ]; then
71 mkdir $bin
74 if [ ! -d $logs ]; then
75 mkdir $logs
78 if [ ! -d $sites ]; then
79 mkdir $sites
84 main()
86 local_dirs
87 dir=0
88 actual_path=`pwd`
90 if [ "$prefix" != "$actual_path" ]; then
91 dir=1
94 if [ "$bindir" != "$actual_path/bin" ]; then
95 dir=1
98 if [ "$cgibin" != "$actual_path/cgi-bin" ]; then
99 dir=1
102 if [ "$sysconfdir" != "$actual_path/conf" ]; then
103 dir=1
106 if [ "$datadir" != "$actual_path/htdocs" ]; then
107 dir=1
110 if [ "$logdir" != "$actual_path/logs" ]; then
111 dir=1
114 echo
115 echo "Checking dependencies"
116 echo "====================="
117 echo
118 messages_$lang "7"
119 check_lib lang
121 echo
122 echo "Creating Makefiles and scripts"
123 echo "=============================="
124 echo
126 messages_$lang "1"
127 create_conf prefix bindir cgibin sysconfdir datadir logdir
129 make_conf $lang
130 messages_$lang "2"
132 if [ "$dir" = 0 ]; then
133 create_makefile1 bindir
134 else
135 create_makefile1_install prefix bindir cgibin sysconfdir datadir logdir
138 messages_$lang "3"
139 create_makefile2 mod_libs mod_obj make_script add_obj_mod cheetah_obj
141 messages_$lang "4"
142 create_info sysconfdir SYSNAME VERSION
144 messages_$lang "5"
145 create_banana_script bindir logdir
146 echo
147 messages_$lang "6"
149 if [ "$dir" = 1 ]; then
150 echo -n " && make install' "
151 else
152 echo "' "
154 echo
156 create_makefile_plugins $plugdir
158 echo "#define CC \"${CC}\"" > src/include/env.h
161 # Check pthreads lib
162 check_lib()
164 cat > check.c <<EOF
165 #include <pthread.h>
166 int main(){ return 0;}
169 libtest=`gcc check.c -lpthread &>configure.log`
170 libstatus=`cat configure.log`
171 if test -n "$libstatus" ; then
172 echo "no"
173 rm -fr check* configure.log
174 exit 1
176 echo "yes"
177 rm -fr check* configure.log a.out
181 # Create Makefile
182 create_makefile1()
184 cat > Makefile << EOF
185 # Monkey HTTP Daemon: Makefile
186 # ============================
187 default:
188 @(cd src; make all)
190 plugins:
191 @(cd plugins; make all)
193 clean:
194 @(cd src; make clean)
195 distclean:
196 @(cd src; make distclean)
200 create_makefile1_install()
202 # Look for plugins and create list
203 for entry in plugins/*
205 if [ -d $entry ]; then
206 echo -e "\tinstall -s -m 644 $entry/*.so \${PLUGINDIR}" >> plugins.list
208 done;
209 plglist=`cat plugins.list`
210 rm -rf plugins.list
212 # Look for plugins configuration
213 for entry in conf/plugins/*
215 if [ -d $entry ]; then
216 echo -e "\tcp -r $entry \${SYSCONFDIR}/plugins/" >> plugins.conf
218 done;
219 plgconf=`cat plugins.conf`
220 rm -rf plugins.conf
222 cat > Makefile <<EOF
223 # Monkey HTTP Daemon: Makefile
224 # ============================
225 PREFIX=\$(DESTDIR)${prefix}
226 BINDIR=\$(DESTDIR)${bindir}
227 CGIBIN=\$(DESTDIR)${cgibin}
228 SYSCONFDIR=\$(DESTDIR)${sysconfdir}
229 DATADIR=\$(DESTDIR)${datadir}
230 LOGDIR=\$(DESTDIR)${logdir}
231 PLUGINDIR=\$(DESTDIR)${plugdir}
233 default:
234 @(cd src; make all)
235 clean:
236 @(cd src; make clean)
237 distclean:
238 @(cd src; make distclean)
240 install:
241 make -C src all
242 install -d \$(BINDIR)
243 install -d \$(CGIBIN)
244 install -d \$(SYSCONFDIR)
245 install -d \${SYSCONFDIR}/sites
246 install -d \${SYSCONFDIR}/plugins
247 install -d \$(DATADIR)
248 install -d \${DATADIR}/imgs
249 install -d \${DATADIR}/php
250 install -d \${DATADIR}/docs
251 install -d \${LOGDIR}
252 install -d \${PLUGINDIR}
253 install -m 755 bin/monkey \$(BINDIR)
254 $STRIP \$(BINDIR)/monkey
255 install -m 755 bin/banana \$(BINDIR)
256 install -m 644 ./conf/*.* \$(SYSCONFDIR)
257 $plgconf
258 install -m 644 ./conf/sites/* \${SYSCONFDIR}/sites
259 $plglist
260 install -m 644 ./htdocs/*.* \$(DATADIR)
261 install -m 644 ./htdocs/imgs/*.* \${DATADIR}/imgs
262 @echo
263 @echo " Running Monkey :"
264 @echo " ----------------"
265 @echo
266 @echo " # $bindir/monkey"
267 @echo
268 @echo " For more help use '-h' option"
269 @echo
274 # Create monkey/src/Makefile
275 create_makefile2()
278 cat > src/Makefile<<EOF
279 CC = $CC
280 CFLAGS = $CFLAGS
281 DEFS = $DEFS
282 INCDIR = ./include
283 LDFLAGS =
284 DESTDIR = ../bin/monkey
285 LIBS = -ldl -lpthread $mod_libs $MORE_LIBS
286 OBJ = monkey.o method.o mimetype.o request.o \\
287 header.o config.o logfile.o signals.o \\
288 user.o utils.o chars.o epoll.o scheduler.o \\
289 str.o memory.o connection.o iov.o http.o \\
290 file.o socket.o clock.o cache.o worker.o \\
291 server.o plugin.o \\
292 $add_obj_mod
294 all: ../bin/monkey
296 ../bin/monkey: \$(OBJ)
297 @echo
298 @echo "Compiling Monkey"
299 @echo "================"
300 \$(CC) \$(CFLAGS) \$(DEFS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
301 @echo
302 @echo "Compiling Plugins"
303 @echo "================="
304 @(cd ../plugins && make all && cd ..)
306 clean:
307 rm -rf *.o
308 rm -rf ../bin/monkey
310 distclean:
311 rm -rf *.o ../bin/* Makefile \\
312 ../Makefile ../conf/monkey.conf \\
313 ../conf/sites/* include/info.h ../logs/*\\
315 .c.o:
316 \$(CC) -c \$(CFLAGS) \$(DEFS) -I\$(INCDIR) \$<
320 create_makefile_plugins()
322 cd plugins
323 cat > Makefile <<EOF
324 all:
326 dir=`pwd`
327 plugins_load="../conf/plugins.load"
328 echo -n > $plugins_load
329 echo "# Monkey Plugins Loader" >> $plugins_load
330 echo "# =====================" >> $plugins_load
331 echo "# Monkey plugins are extended functionalities for Monkey," >> $plugins_load
332 echo "# the main directive to load a plugin is LoadPlugin plus" >> $plugins_load
333 echo "# the absolute path for the desired plugin." >> $plugins_load
334 echo "#" >> $plugins_load
335 echo "# Please check the following list of available plugins:" >> $plugins_load
336 echo "" >> $plugins_load
337 echo "[PLUGINS]" >> $plugins_load
338 echo "" >> $plugins_load
340 for plugin_dir in `echo */ "" | sed "s/\/ /\n/g"`;
342 comment=" "
343 if test -e $plugin_dir/DISABLED ; then
344 continue
347 if test -e $plugin_dir/MANDATORY ; then
348 comment=" "
351 if test -e $plugin_dir/OPTIONAL ; then
352 comment=" # "
355 echo " @(cd $plugin_dir && make && cd ..)" >> Makefile;
356 sed -e "s/\$CC/$CC/" -e "s/\$CFLAGS/$CFLAGS/" -e "s/\$DEFS/$DEFS/" $plugin_dir/Makefile.in > $plugin_dir/Makefile
358 if test -e $plugin_dir/ABOUT ; then
359 cat $plugin_dir/ABOUT | sed -e 's/^/ # /' >> ../conf/plugins.load
360 echo " #" >> ../conf/plugins.load
361 else
362 echo " #" >> ../conf/plugins.load
365 if [ "$plugdir" != "" ]; then
366 echo "${comment}Load $plugdir/monkey-$plugin_dir.so" >> ../conf/plugins.load
367 else
368 echo "${comment}Load $dir/$plugin_dir/monkey-$plugin_dir.so" >> ../conf/plugins.load
371 echo "" >> ../conf/plugins.load
372 done
374 # Add 'install' option to make file if plugdir was specified
375 if [ "$plugdir" != "" ]; then
376 echo -e "\ninstall:" >> Makefile
377 echo -e "\tinstall -d $plugdir" >> Makefile
379 list=`echo */ "" | sed "s/\/ /\n/g"`
380 for i in $list;
382 echo -e "\tinstall -m 644 $dir/$i/monkey-$i.so $plugdir/" >> Makefile
383 done
385 cd ..
388 # Creando include/info.h
389 create_info()
391 cat > $INCDIR/info.h <<EOF
392 #define OS "$SYSNAME"
393 #define VERSION "$VERSION" /* Version de Monkey */
394 #define MONKEY_PATH_CONF "$sysconfdir"
398 create_conf()
400 cat > $INCDIR/config.path <<EOF
401 #!/bin/sh
402 prefix=$prefix
403 bindir=$bindir
404 cgibin=$cgibin
405 sysconfdir=$sysconfdir
406 datadir=$datadir
407 logdir=$logdir
411 create_banana_script()
413 cat > bin/banana << EOF
414 #!/bin/sh
416 # Monkey HTTP Daemon - Banana Script
417 # -----------------------------------
418 # This script allow you to control monkey. Written by Eduardo Silva
419 # ----------------------------
420 # Date : 2002/09/01.
421 # ----------------------------
423 # Use: ./banana OPTION
425 # Options available to banana:
427 # start -> start monkey
428 # restart -> restart monkey
429 # stop -> stop monkey if this is running
430 # help -> what do u think ?
432 PIDFILE="$logdir/monkey.pid"
433 BINMONKEY="$bindir/monkey"
435 for arg in \$*; do
436 case "\$arg" in
437 -*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
438 *) optarg= ;;
439 esac
441 if ! test -f \$PIDFILE ; then
442 STATUS="no"
443 else
444 PIDMONKEY=\`cat \$PIDFILE\`
445 if ! kill -0 \$PIDMONKEY 2>/dev/null; then
446 STATUS="no"
447 else
448 STATUS="yes"
452 case "\$arg" in
453 start)
454 if [ "\$STATUS" = "yes" ] ; then
455 echo "Monkey is running... (PID=\$PIDMONKEY)"
456 exit 1
458 if ! test -x \$BINMONKEY ; then
459 echo "Error: I can't run binary file"
460 exit 1
461 else
462 if \$BINMONKEY -D 2>/dev/null ; then
463 echo "Running Monkey -> OK"
464 exit 0
468 stop)
469 if [ "\$STATUS" = "no" ]; then
470 echo "Monkey is not running."
471 exit 1
473 kill -9 \$PIDMONKEY
474 rm -rf \$PIDFILE > /dev/null
475 echo "Monkey stopped (\$PIDMONKEY)"
476 exit 0
478 restart)
479 if [ "\$STATUS" = "yes" ]; then
480 if ! kill \$PIDMONKEY > /dev/null ; then
481 killall -9 monkey
482 else
483 echo -n "Stopping Monkey... "
485 else
486 echo -n "Monkey is not running... "
488 if ! test -x \$BINMONKEY ; then
489 echo "Error: I can't run binary file"
490 exit 1
491 else
492 \$BINMONKEY -D > /dev/null
493 echo "Restarting -> OK"
494 exit 0
498 echo "Use : banana [start|stop|restart|help]"
499 exit 1
501 esac
502 done
503 echo "Use : banana [start|stop|restart|help]"
505 exit 0
507 chmod 755 bin/banana
510 #---------------------------#
511 # End Functions
512 #---------------------------#
515 #---------------------------#
516 # Starting configure
517 #---------------------------#
518 aux=`pwd`
520 prefix="$aux"
521 bindir="$aux/bin"
522 cgibin="$aux/cgi-bin"
523 sysconfdir="$aux/conf"
524 datadir="$aux/htdocs"
525 logdir="$aux/logs"
526 plugdir=""
528 for arg in $*; do
529 case "$arg" in
530 -*=*)
531 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
532 *) optarg= ;;
533 esac
535 case "$arg" in
536 --prefix*)
537 prefix=$optarg
538 bindir="$optarg/bin"
539 cgibin="$optarg/cgi-bin"
540 sysconfdir="$optarg/conf"
541 datadir="$optarg/htdocs"
542 logdir="$optarg/logs"
543 plugdir="$optarg/plugins"
545 --bindir*)
546 bindir=$optarg
548 --cgibin*)
549 cgibin=$optarg
551 --sysconfdir*)
552 sysconfdir=$optarg
554 --datadir*)
555 datadir=$optarg
557 --logdir*)
558 logdir=$optarg
560 --plugdir*)
561 plugdir=$optarg
563 --debug*)
564 debug=1
566 --trace*)
567 trace=1
569 --version*)
570 echo "Monkey HTTP Daemon v$VERSION"
571 echo "-------------------------"
572 echo "Copyright 2001-2010"
573 echo "Developed by Eduardo Silva Pereira"
574 echo "Monkey Home : http://www.monkey-project.com"
575 echo "Contact Email : edsiper@gmail.com"
576 echo
577 exit 1
580 echo "Usage: configure [--prefix=PREFIXDIR] [ --bindir=BINDIR]"
581 echo " [--sysconfdir=SYSCONFDIR] [--datadir=DATADIR]"
582 echo " [--logdir=LOGDIR] [--plugdir=PLUGDIR]"
583 echo
584 echo "Options: "
585 echo " --help Display this help and exit"
586 echo " --version Display version information and exit"
587 echo " --debug Compile Monkey with debugging symbols"
588 echo " --trace Compile Monkey with trace messages (don't use in production)"
589 echo
590 echo " --prefix=PREFIX Install Monkey under PREFIX directory"
591 echo " --bindir=BINDIR Install Monkey binaries under BINDIR directory"
592 echo " --sysconfdir=SYSCONFDIR Install Monkey conf files under SYSCONFDIR dir"
593 echo " --datadir=DATADIR Install Monkey data dir files under DATADIR directory"
594 echo " --logdir=LOGDIR Install Monkey log files under LOGDIR directory"
595 echo " --plugdir=PLUGDIR Target directory for Monkey plugins"
596 echo
597 exit 1
599 esac
600 done
602 echo "********************************************"
603 echo " Monkey HTTP Daemon v$VERSION "
604 echo "* http://www.monkey-project.com *"
605 echo "* ---------------------------------------- *"
606 echo "* We need beta testers, developers and *"
607 echo "* translators!, if you want to contribute *"
608 echo "* to this wonderful project contact us ! *"
609 echo "* *"
610 echo "* irc.freenode.net #monkeyd *"
611 echo "* *"
612 echo "* Thanks for use Monkey!!! *"
613 echo "* *"
614 echo "********************************************"
615 echo "System : $SYSINFO"
617 lang="en"
620 # Configure environment
621 if test -z "$CC" ; then
622 gcc_path=`which gcc`
623 if test -x "$gcc_path" ; then
624 CC="gcc"
625 else
626 echo "I'm a Monkey not a compiler! how do you suppose to compile me ? Install a compiler"
627 exit 1
631 if test -z "$STRIP" ; then
632 STRIP="strip"
635 if test -z "$debug" ; then
636 CFLAGS="$CFLAGS -O2 -Wall"
637 else
638 CFLAGS="$CFLAGS -g -Wall"
641 if [ $trace ] ; then
642 DEFS="-DTRACE"
645 # Starting main function
646 main prefix lang bindir cgibin sysconfdir datadir logdir plugdir modules SYSNAME VERSION
647 exit 0