Improve plugin handler return values and actions
[MonkeyD.git] / configure
blob26aa2f7eaa050ea259f52095407b0cc1f4989f84
1 #!/bin/sh
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 VERSION="0.10.0-git"
22 SYSNAME=`uname -s`
23 SYSINFO=`uname -sr`
25 INFOMODS="extras/inf/"
26 INCDIR="src/include/"
28 messages_en()
30 case "$*" in
31 "1")
32 echo "+ Creating conf/monkey.conf"
34 "2")
35 echo "+ Creating Makefile"
37 "3")
38 echo "+ Creating src/Makefile"
40 "4")
41 echo "+ Creating src/include/info.h"
43 "5")
44 echo "+ Creating banana script"
46 "6")
47 echo -n "Configuration done, just type 'make"
49 "7")
50 echo -n "+ Checking for Pthreads lib.........."
52 esac
55 # Create configuration files under 'conf/'
56 make_conf()
58 cat $INCDIR/config.path lang/"$*"/mconf lang/"$*"/sites/default > makeconf.sh
59 chmod 755 makeconf.sh
60 ./makeconf.sh
61 rm makeconf.sh
62 rm $INCDIR/config.path
63 cp lang/"$*"/INSTALL ./
64 cp lang/"$*"/README ./
67 local_dirs()
69 bin="bin"
70 logs="logs"
71 sites="conf/sites"
73 if [ ! -d $bin ]; then
74 mkdir $bin
77 if [ ! -d $logs ]; then
78 mkdir $logs
81 if [ ! -d $sites ]; then
82 mkdir $sites
87 main()
89 local_dirs
90 dir=0
91 actual_path=`pwd`
93 if [ "$prefix" != "$actual_path" ]; then
94 dir=1
97 if [ "$bindir" != "$actual_path/bin" ]; then
98 dir=1
101 if [ "$cgibin" != "$actual_path/cgi-bin" ]; then
102 dir=1
105 if [ "$sysconfdir" != "$actual_path/conf" ]; then
106 dir=1
109 if [ "$datadir" != "$actual_path/htdocs" ]; then
110 dir=1
113 if [ "$logdir" != "$actual_path/logs" ]; then
114 dir=1
117 echo
118 echo "Checking dependencies"
119 echo "====================="
120 echo
121 messages_$lang "7"
122 check_lib lang
124 echo
125 echo "Creating Makefiles and scripts"
126 echo "=============================="
127 echo
129 messages_$lang "1"
130 create_conf prefix bindir cgibin sysconfdir datadir logdir
132 make_conf $lang
133 messages_$lang "2"
135 if [ "$dir" = 0 ]; then
136 create_makefile1 bindir
137 else
138 create_makefile1_install prefix bindir cgibin sysconfdir datadir logdir
141 messages_$lang "3"
142 create_makefile2 mod_libs mod_defs mod_obj make_script add_obj_mod cheetah_obj
144 messages_$lang "4"
145 create_info sysconfdir SYSNAME VERSION
147 messages_$lang "5"
148 create_banana_script bindir logdir
149 echo
150 messages_$lang "6"
152 if [ "$dir" = 1 ]; then
153 echo -n " && make install' "
154 else
155 echo "' "
157 echo
159 create_makefile_plugins $plugdir
162 # Check pthreads lib
163 check_lib()
165 cat > check.c <<EOF
166 #include <pthread.h>
167 int main(){ return 0;}
170 libtest=`gcc check.c -lpthread &>configure.log`
171 libstatus=`cat configure.log`
172 if test -n "$libstatus" ; then
173 echo "no"
174 rm -fr check* configure.log
175 exit 1
177 echo "yes"
178 rm -fr check* configure.log a.out
182 # Create Makefile
183 create_makefile1()
185 cat > Makefile << EOF
186 # Monkey HTTP Daemon: Makefile
187 # ============================
188 default:
189 @(cd src; make all)
190 @echo
191 @echo " Running Monkey :"
192 @echo " ----------------"
193 @echo
194 @echo " # $bindir/monkey"
195 @echo
196 @echo " For more help use '-h' option."
197 @echo
199 plugins:
200 @(cd plugins; make all)
202 clean:
203 @(cd src; make clean)
204 distclean:
205 @(cd src; make distclean)
209 create_makefile1_install()
212 # Look for plugins and create list
213 for entry in plugins/*
215 if [ -d $entry ]; then
216 echo "\tinstall -s -m 644 $entry/*.so \${PLUGINDIR}" >> plugins.list
218 done;
219 plglist=`cat plugins.list`
220 rm -rf plugins.list
222 # Look for plugins configuration
223 for entry in conf/plugins/*
225 if [ -d $entry ]; then
226 echo "\tcp -r $entry \${SYSCONFDIR}/plugins/" >> plugins.conf
228 done;
229 plgconf=`cat plugins.conf`
230 rm -rf plugins.conf
232 cat > Makefile <<EOF
233 # Monkey HTTP Daemon: Makefile
234 # ============================
235 PREFIX=${prefix}
236 BINDIR=${bindir}
237 CGIBIN=${cgibin}
238 SYSCONFDIR=${sysconfdir}
239 DATADIR=${datadir}
240 LOGDIR=${logdir}
241 PLUGINDIR=${plugdir}
243 default:
244 @(cd src; make all)
245 clean:
246 @(cd src; make clean)
247 distclean:
248 @(cd src; make distclean)
250 install:
251 make -C src all
252 install -d \$(BINDIR)
253 install -d \$(CGIBIN)
254 install -d \$(SYSCONFDIR)
255 install -d \${SYSCONFDIR}/sites
256 install -d \${SYSCONFDIR}/plugins
257 install -d \$(DATADIR)
258 install -d \${DATADIR}/imgs
259 install -d \${DATADIR}/php
260 install -d \${DATADIR}/docs
261 install -d \${LOGDIR}
262 install -d \${PLUGINDIR}
263 install -s -m 755 bin/monkey \$(BINDIR)
264 install -m 755 bin/banana \$(BINDIR)
265 install -m 755 ./cgi-bin/* \$(CGIBIN)
266 install -m 600 ./conf/*.* \$(SYSCONFDIR)
267 $plgconf
268 install -m 600 ./conf/sites/* \${SYSCONFDIR}/sites
269 $plglist
270 install -m 644 ./htdocs/*.* \$(DATADIR)
271 install -m 644 ./htdocs/imgs/*.* \${DATADIR}/imgs
272 install -m 644 ./htdocs/php/*.* \${DATADIR}/php
273 install -m 644 ./htdocs/docs/*.* \${DATADIR}/docs
274 @echo
275 @echo " Running Monkey :"
276 @echo " ----------------"
277 @echo
278 @echo " # $bindir/monkey"
279 @echo
280 @echo " For more help use '-h' option"
281 @echo
286 # Create monkey/src/Makefile
287 create_makefile2()
290 if test -z $CC ; then
291 CC="gcc"
293 if test -z $STRIP ; then
294 STRIP="strip "
297 ##### Internal options ####
298 # just for remember that one time we support this :_(
299 # ---------------------------------------------------
300 #if [ "$disable_sendfile" = "on" ]; then
301 # internal_options="-DDISABLE_SENDFILE_SYSCALL"
304 cat > src/Makefile<<EOF
305 CC = $CC
306 DEFS = $mod_defs $internal_options
307 CFLAGS = $CFLAGS \$(DEFS) -g -O2 -Wall
308 INCDIR = ./include
309 LDFLAGS =
310 DESTDIR = ../bin/monkey
311 LIBS = -ldl -lpthread $mod_libs $MORE_LIBS
312 OBJ = monkey.o method.o mimetype.o request.o \\
313 header.o config.o logfile.o signals.o \\
314 user.o utils.o chars.o epoll.o scheduler.o \\
315 str.o memory.o connection.o iov.o http.o \\
316 file.o socket.o clock.o cache.o worker.o \\
317 server.o plugin.o \\
318 $add_obj_mod
320 all: ../bin/monkey
322 ../bin/monkey: \$(OBJ)
323 @echo "Compiling Monkey"
324 @echo "================"
325 \$(CC) \$(CFLAGS) \$(LIBS) \$(LDFLAGS) -o \$@ \$(OBJ) $mod_obj
326 $STRIP ../bin/monkey
327 @echo
328 @echo "Compiling Plugins"
329 @echo "================="
330 @(cd ../plugins && make all && cd ..)
332 clean:
333 rm -rf *.o
334 rm -rf ../bin/monkey
336 distclean:
337 rm -rf *.o ../bin/* Makefile \\
338 ../Makefile ../conf/monkey.conf \\
339 ../conf/sites/* include/info.h ../logs/*\\
340 @(cd extras && ./cleanmods.sh && cd ..)
342 .c.o:
343 \$(CC) -c \$(CFLAGS) -I\$(INCDIR) \$<
347 create_makefile_plugins()
349 cd plugins
350 cat > Makefile <<EOF
351 all:
353 dir=`pwd`
354 plugins_load="../conf/plugins.load"
355 echo -n > $plugins_load
356 echo "# Monkey plugins are loaded on run, by default all " >> $plugins_load
357 echo "# plugins are disabled, if you want to enable" >> $plugins_load
358 echo "# one, just remove the comment character for each line" >> $plugins_load
359 echo "" >> $plugins_load
361 list=`echo */ "" | sed "s/\/ /\n/g"`
362 for i in $list;
364 echo " @(cd $i && make && cd ..)" >> Makefile;
366 if [ "$plugdir" != "" ]; then
367 echo "#LoadPlugin $plugdir/monkey-$i.so" >> ../conf/plugins.load
368 else
369 echo "#LoadPlugin $dir/$i/monkey-$i.so" >> ../conf/plugins.load
371 done
373 # Add 'install' option to make file if plugdir was specified
374 if [ "$plugdir" != "" ]; then
375 echo "\ninstall:" >> Makefile
376 echo "\tinstall -d $plugdir" >> Makefile
378 list=`echo */ "" | sed "s/\/ /\n/g"`
379 for i in $list;
381 echo "\tinstall -m 644 $dir/$i/monkey-$i.so $plugdir/" >> Makefile
382 done
386 # Creando include/info.h
387 create_info()
389 cat > $INCDIR/info.h <<EOF
390 #define OS "$SYSNAME"
391 #define VERSION "$VERSION" /* Version de Monkey */
392 #define MONKEY_PATH_CONF "$sysconfdir"
396 create_conf()
398 cat > $INCDIR/config.path <<EOF
399 #!/bin/sh
400 prefix=$prefix
401 bindir=$bindir
402 cgibin=$cgibin
403 sysconfdir=$sysconfdir
404 datadir=$datadir
405 logdir=$logdir
409 create_banana_script()
411 cat > bin/banana << EOF
412 #!/bin/sh
414 # Monkey HTTP Daemon - Banana Script
415 # -----------------------------------
416 # This script allow you to control monkey. Written by Eduardo Silva
417 # ----------------------------
418 # Date : 2002/09/01.
419 # ----------------------------
421 # Use: ./banana OPTION
423 # Options available to banana:
425 # start -> start monkey
426 # restart -> restart monkey
427 # stop -> stop monkey if this is running
428 # help -> what do u think ?
430 PIDFILE="$logdir/monkey.pid"
431 BINMONKEY="$bindir/monkey"
433 for arg in \$*; do
434 case "\$arg" in
435 -*=*) optarg=\`echo "\$arg" | sed 's/[-_a-zA-Z0-9]*=//'\` ;;
436 *) optarg= ;;
437 esac
439 if ! test -f \$PIDFILE ; then
440 STATUS="no"
441 else
442 PIDMONKEY=\`cat \$PIDFILE\`
443 if ! kill -0 \$PIDMONKEY 2>/dev/null; then
444 STATUS="no"
445 else
446 STATUS="yes"
450 case "\$arg" in
451 start)
452 if [ "\$STATUS" = "yes" ] ; then
453 echo "Monkey is running... (PID=\$PIDMONKEY)"
454 exit 1
456 if ! test -x \$BINMONKEY ; then
457 echo "Error: I can't run binary file"
458 exit 1
459 else
460 if \$BINMONKEY -D 2>/dev/null ; then
461 echo "Running Monkey -> OK"
462 exit 0
466 stop)
467 if [ "\$STATUS" = "no" ]; then
468 echo "Monkey is not running."
469 exit 1
471 kill -9 \$PIDMONKEY
472 rm -rf \$PIDFILE > /dev/null
473 echo "Monkey stopped (\$PIDMONKEY)"
474 exit 0
476 restart)
477 if [ "\$STATUS" = "yes" ]; then
478 if ! kill \$PIDMONKEY > /dev/null ; then
479 killall -9 monkey
480 else
481 echo -n "Stopping Monkey... "
483 else
484 echo -n "Monkey is not running... "
486 if ! test -x \$BINMONKEY ; then
487 echo "Error: I can't run binary file"
488 exit 1
489 else
490 \$BINMONKEY -D > /dev/null
491 echo "Restarting -> OK"
492 exit 0
496 echo "Use : banana [start|stop|restart|help]"
497 exit 1
499 esac
500 done
501 echo "Use : banana [start|stop|restart|help]"
503 exit 0
505 chmod 755 bin/banana
508 #---------------------------#
509 # End Functions
510 #---------------------------#
513 #---------------------------#
514 # Starting configure
515 #---------------------------#
516 aux=`pwd`
518 prefix="$aux"
519 bindir="$aux/bin"
520 cgibin="$aux/cgi-bin"
521 sysconfdir="$aux/conf"
522 datadir="$aux/htdocs"
523 logdir="$aux/logs"
525 for arg in $*; do
526 case "$arg" in
527 -*=*)
528 optarg=`echo "$arg" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
529 *) optarg= ;;
530 esac
532 case "$arg" in
533 --prefix*)
534 prefix=$optarg
535 bindir="$optarg/bin"
536 cgibin="$optarg/cgi-bin"
537 sysconfdir="$optarg/conf"
538 datadir="$optarg/htdocs"
539 logdir="$optarg/logs"
541 --bindir*)
542 bindir=$optarg
544 --cgibin*)
545 cgibin=$optarg
547 --sysconfdir*)
548 sysconfdir=$optarg
550 --datadir*)
551 datadir=$optarg
553 --logdir*)
554 logdir=$optarg
556 --lang*)
557 lang=$optarg
559 --plugdir*)
560 plugdir=$optarg
562 --version*)
563 echo "Monkey HTTP Daemon v$VERSION"
564 echo "-------------------------"
565 echo "Copyright 2001-2010"
566 echo "Developed by Eduardo Silva Pereira"
567 echo "Monkey Home : http://www.monkey-project.com"
568 echo "Contact Email : edsiper@gmail.com"
569 echo
570 exit 1
573 echo "Usage: configure [--prefix=PREFIXDIR] [--lang=LANGUAGE] [ --bindir=BINDIR]"
574 echo " [--cgibin=CGIBINDIR] [--sysconfdir=SYSCONFDIR]"
575 echo " [--datadir=DATADIR] [--logdir=LOGDIR] [--plugdir=PLUGDIR]"
576 echo
577 echo "Options: "
578 echo " --help Display this help and exit"
579 echo " --version Display version information and exit"
580 echo
581 echo " --prefix=PREFIX Install Monkey under PREFIX directory"
582 echo " --bindir=BINDIR Install Monkey binaries under BINDIR directory"
583 echo " --cgibin=CGIBINDIR Install Monkey cgi-bin under CGIBIN directory"
584 echo " --sysconfdir=SYSCONFDIR Install Monkey conf files under SYSCONFDIR dir"
585 echo " --datadir=DATADIR Install Monkey data dir files under DATADIR directory"
586 echo " --logdir=LOGDIR Install Monkey log files under LOGDIR directory"
587 echo " --plugdir=PLUGDIR Target directory for Monkey plugins"
588 echo
589 exit 1
591 esac
592 done
594 echo "********************************************"
595 echo " Monkey HTTP Daemon v$VERSION "
596 echo "* http://www.monkey-project.com *"
597 echo "* ---------------------------------------- *"
598 echo "* We need beta testers, developers and *"
599 echo "* translators!, if u want help to this *"
600 echo "* project, email me : *"
601 echo "* *"
602 echo "* edsiper@gmail.com *"
603 echo "* *"
604 echo "* Thanks for use Monkey!!! *"
605 echo "* *"
606 echo "********************************************"
607 echo "System : $SYSINFO"
609 lang="en"
611 # starting main function
612 main prefix lang bindir cgibin sysconfdir datadir logdir plugdir modules SYSNAME VERSION
613 exit 0