]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - configure
Fixed bug with falsly reporting that configs CAN be copied.
[user/henk/code/inspircd.git] / configure
1 #!/bin/sh
2 # InspIRCd Configuration Script
3 #
4 # Copyright 2003 The ChatSpike Development Team
5 # <brain@chatspike.net>
6 # <Craig@chatspike.net>
7 #
8 # $Id$
9 #
10 #
11 ########################################
12
13 echo "Configuring default values..."
14
15 ME=`pwd`
16 GCCVER=`gcc -dumpversion | cut -c 1`
17 CONFIG_DIR=$ME/conf
18 MODULE_DIR=$ME/modules
19 BINARY_DIR=$ME/bin
20 INSTALL=`which install`
21 OPTIMITEMP=0
22 OPTIMISATI="-g"
23 MAX_CLIENT_T=`ulimit -n`
24 NICK_LENGT=32
25 CHAN_LENGT=64
26 MAX_CHANNE=20
27 MAXI_MODES=20
28 OSNAME=`(uname -s) 2>/dev/null` || OSNAME="unknown"
29
30 if [ -z $MAX_CLIENT_T ] ; then
31         MAX_CLIENT_T=1024
32         SCAN_FAILED=1
33 fi
34
35
36 if [ "$1" = "-clean" -o "$2" = "-clean" ] ; then
37   `rm -rf .config.cache`
38 fi
39
40 if [ -e ".config.cache" -a -z "$CLEAN" ] ; then
41     . .config.cache 
42 fi
43
44 if [ "$1" = "-update" -o "$2" = "-update" ] ; then
45    # They wanna update their Makefile.. good for 'em
46    # Make sure .config.cache exists
47    if [ ! -e ".config.cache" ] ; then
48      echo "You have not run ./configure before. Please do this before trying to run the update script."
49      exit 0
50    fi
51    # Right, load the cache values
52    . .config.cache
53    # Check for modules
54
55    case "$OSNAME" in
56            (FreeBSD)
57                    LDLIBS="-Ldl"
58                    FLAGS="-fPIC -frtti $OPTIMISATI"
59                    MAKEPROG="gmake"
60                    ;;
61            (*)
62                    LDLIBS="-ldl"
63                    FLAGS="-fPIC -frtti $OPTIMISATI"
64                    MAKEPROG="make"
65                    ;;
66    esac
67
68    MODULES=""
69    for module in src/modules/*.cpp ; do
70            mod=`echo $module | sed 's/.cpp/.so/' | sed 's/src\/modules\///'`
71            MODULES="$MODULES $mod"
72    done
73
74    # Write the new makefile.
75    . .Makefile.inc
76    echo "Complete."
77    exit 1; 
78 fi
79
80
81 if [ -z $MAX_CLIENT ] ; then
82         MAX_CLIENT=$MAX_CLIENT_T
83 fi
84
85
86 c=""
87 n=""
88 if [ "`eval echo -e -n 'a'`" = "-n a" ] ; then
89         c="\c"
90 else
91         n="-n"
92 fi
93
94 exists () { # because some shells don't have test -e
95     if [ -f $1 -o -d $1 -o -p $1 -o -c $1 -o -b $1 ] ; then
96         return 0
97     else
98         return 1
99     fi
100 }
101
102 clear
103 echo -e "'\033[1;33m####\033[0;37m:'\033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m::'\033[1;33m######\033[0;37m::'\033[1;33m########\033[0;37m::'\033[1;33m####\033[0;37m:'\033[1;33m########\033[0;37m:::'\033[1;33m######\033[0;37m::'\033[1;33m########\033[0;37m::"
104 echo -e ". \033[1;33m##\033[0;37m:: \033[1;33m###\033[0;37m:: \033[1;33m##\033[0;37m:'\033[1;33m##\033[0;37m... \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:. \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:'\033[1;33m##\033[0;37m... \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m.... \033[1;33m##\033[0;37m:"
105 echo -e ": \033[1;33m##\033[0;37m:: \033[1;33m####\033[0;37m: \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m:::..:: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m:::..:: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:"
106 echo -e ": \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m \033[1;33m##\033[0;37m \033[1;33m##\033[0;37m:. \033[1;33m######\033[0;37m:: \033[1;33m########\033[0;37m::: \033[1;33m##\033[0;37m:: \033[1;33m########\033[0;37m:: \033[1;33m##\033[0;37m::::::: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:"
107 echo -e ": \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m. \033[1;33m####\033[0;37m::..... \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m.....:::: \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m.. \033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m::::::: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:"
108 echo -e ": \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m:. \033[1;33m###\033[0;37m:'\033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m::::::::: \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m::. \033[1;33m##\033[0;37m:: \033[1;33m##\033[0;37m::: \033[1;33m##\033[0;37m: \033[1;33m##\033[0;37m:::: \033[1;33m##\033[0;37m:"
109 echo -e "'\033[1;33m####\033[0;37m: \033[1;33m##\033[0;37m::. \033[1;33m##\033[0;37m:. \033[1;33m######\033[0;37m:: \033[1;33m##\033[0;37m::::::::'\033[1;33m####\033[0;37m: \033[1;33m##\033[0;37m:::. \033[1;33m##\033[0;37m:. \033[1;33m######\033[0;37m:: \033[1;33m########\033[0;37m::"
110 echo -e "\033[0;37m\033[0;37m....::..::::..:::......:::..:::::::::....::..:::::..:::......:::........:::"
111 echo ""
112 echo -e "\033[1;37mWelcome to the InspIRCd Configuration program!"
113 echo ""
114 echo "*** If you are unsure of any of these values, leave it blank for    ***"
115 echo "*** standard settings that will work, and your server will run      ***"
116 echo "*** using them. If you are running this server as part of a         ***"
117 echo "*** larger network, you must consult with your network admins       ***"
118 echo "*** for the proper values to use, or server links will be unstable! ***"
119 echo -e "\033[0;37m"
120 echo -e "Press \033[1;37m<RETURN>\033[0;37m to accept the default for any option, or enter"
121 echo -e "a new value. Please note: You will \033[1;37mHAVE\033[0;37m to read the docs"
122 echo -e "dir, otherwise you won't have a config file!"
123 echo ""
124 echo -e "Your operating system is: \033[1;37m$OSNAME\033[0;37m (`uname -mnr`), fdmax: $MAX_CLIENT_T"
125 echo ""
126
127 #############################################################################
128
129     ok=0
130     asked=1
131     echo "In what directory are the configuration files?"
132     while [ $ok -eq 0 ] ; do
133         echo -e $n "[\033[1;32m$CONFIG_DIR\033[0;37m] -> $c"
134         if read INPUT ; then : ; else echo "" ; exit 1 ; fi
135         if [ ! "$INPUT" ] ; then
136             INPUT=$CONFIG_DIR
137             default=1
138         fi
139         if echo "$INPUT" | grep -q \[\'\"\\\] ; then
140             echo 'Please use a pathname without the characters: '\'' " \'
141         elif [ ! "$NO_DIR_CHECK" -a ! -d "$INPUT" ] ; then
142             if exists "$INPUT" ; then
143                 echo "$INPUT exists, but is not a directory!"
144             else
145                 echo "$INPUT does not exist.  Create it?"
146                 echo -e $n "[\033[1;32my\033[0;37m] $c"
147                 read YN
148                 if [ "$YN" != "n" ] ; then
149                     if mkdir -p "$INPUT" ; then
150                         ok=1
151                     fi
152                 fi
153             fi
154             else
155             ok=1
156         fi
157     done
158     CONFIG_DIR=$INPUT
159     echo ""
160
161
162 ##############################################################################
163
164     ok=0
165     asked=1
166     echo "In What directory are the modules to be compiled to?"
167     while [ $ok -eq 0 ] ; do
168         echo -e $n "[\033[1;32m$MODULE_DIR\033[0;37m] -> $c"
169         if read INPUT ; then : ; else echo "" ; exit 1 ; fi
170         if [ ! "$INPUT" ] ; then
171             INPUT=$MODULE_DIR
172             default=1
173         fi
174         if echo "$INPUT" | grep -q \[\'\"\\\] ; then
175             echo 'Please use a pathname without the characters: '\'' " \'
176         elif [ ! "$NO_DIR_CHECK" -a ! -d "$INPUT" ] ; then
177             if exists "$INPUT" ; then
178                 echo "$INPUT exists, but is not a directory!"
179             else
180                 echo "$INPUT does not exist.  Create it?"
181                 echo -e $n "[\033[1;32my\033[0;37m] $c"
182                 read YN
183                 if [ "$YN" != "n" ] ; then
184                     if mkdir -p "$INPUT" ; then
185                         ok=1
186                     fi
187                 fi
188             fi
189             else
190             ok=1
191         fi
192     done
193     MODULE_DIR=$INPUT
194     echo ""
195
196
197 ##############################################################################
198
199     ok=0
200     asked=1
201     echo "In what directory is the IRCd binary to be placed?"
202     while [ $ok -eq 0 ] ; do
203         echo -e $n "[\033[1;32m$BINARY_DIR\033[0;37m] -> $c"
204         if read INPUT ; then : ; else echo "" ; exit 1 ; fi
205         if [ ! "$INPUT" ] ; then
206             INPUT=$BINARY_DIR
207             default=1
208         fi
209         if echo "$INPUT" | grep -q \[\'\"\\\] ; then
210             echo 'Please use a pathname without the characters: '\'' " \'
211         elif [ ! "$NO_DIR_CHECK" -a ! -d "$INPUT" ] ; then
212             if exists "$INPUT" ; then
213                 echo "$INPUT exists, but is not a directory!"
214             else
215                 echo "$INPUT does not exist.  Create it?"
216                 echo -e $n "[\033[1;32my\033[0;37m] $c"
217                 read YN
218                 if [ "$YN" != "n" ] ; then
219                     if mkdir -p "$INPUT" ; then
220                         ok=1
221                     fi
222                 fi
223             fi
224             else
225             ok=1
226         fi
227     done
228     BINARY_DIR=$INPUT
229     echo ""
230
231 ###############################################################################
232 # Craigs Version 3 With slightly less Cheeze :p
233
234 cheeze=0
235 echo -e "Maximum number of clients at any one time (\033[1;32m1-$MAX_CLIENT_T\033[0;37m)?"
236 while [ "$cheeze" -eq "0" ] ; do
237         echo -e $n "[\033[1;32m$MAX_CLIENT\033[0;37m] -> $c"
238         read cc
239
240         if [ -z "$cc" ] ; then
241                 cc=$MAX_CLIENT
242         fi
243
244         case "$cc" in 
245                 [0-9]*)
246                         if [ "$cc" -gt "$MAX_CLIENT_T" -a -z "$SCAN_FAILED" ] ; then
247                                 echo -e "WARNING: Our scans have indicated that you are attempting"
248                                 echo -e "to use more sockets than there are avaliable. Are you sure"
249                                 echo -e "you wish to do this? It may cause the IRCd to malfunction [y/n]"
250                                 echo -e $n "[\033[1;32mn\033[0;37m] -> $c"
251                                 read YN
252                                 if [ "$YN" = "y" ] ; then
253                                         MAX_CLIENT=$cc
254                                         cheeze=1
255                                 else
256                                         echo ""
257                                         echo -e "Please enter the correct value (\033[1;32m1-$MAX_CLIENT_T\033[0;37m)"
258                                 fi
259                         else
260                                 echo $SCAN_FAILED
261                                 cheeze=1
262                                 MAX_CLIENT=$cc
263                         fi
264                         ;;
265                 *)
266                         echo ""
267                         echo "You must enter a number in this field. Please try again."
268                         ;;
269         esac
270 done
271 echo ""
272
273
274 ###############################################################################
275
276   cheeze=0
277   echo -e "What is the Maximum length of nicknames?"
278   while [ "$cheeze" -eq "0" ] ; do
279         echo -e $n "[\033[1;32m$NICK_LENGT\033[0;37m] -> $c"
280         read cc
281         if [ "$cc" ] ; then
282                 case "$cc" in
283                         [0-9]*)
284                         NICK_LENGT=$cc
285                         cheeze=1
286                         ;;
287                         *)
288                         echo ""
289                         echo "You Must Enter a Number in this field. Please Try Again."
290                         cheeze=0
291                         ;;
292                 esac
293         else
294                 cheeze=1
295         fi
296   done
297   echo ""
298
299 ###############################################################################
300
301   cheeze=0
302   echo -e "What is the Maximum length of channel names?"
303   while [ "$cheeze" -eq "0" ] ; do
304         echo -e $n "[\033[1;32m$MAX_CHANNE\033[0;37m] -> $c"
305         read cc
306         if [ "$cc" ] ; then
307                 case "$cc" in
308                         [0-9]*)
309                         MAX_CHANNE=$cc
310                         cheeze=1
311                         ;;
312                         *)
313                         echo ""
314                         echo "You Must Enter a Number in this field. Please Try Again."
315                         cheeze=0
316                         ;;
317                 esac
318         else
319                 cheeze=1
320         fi
321   done
322   echo ""
323
324 ###############################################################################
325
326   cheeze=0
327   echo -e "What is the Maximum number of mode changes in one line?"
328   while [ "$cheeze" -eq "0" ] ; do
329         echo -e $n "[\033[1;32m$MAXI_MODES\033[0;37m] -> $c"
330         read cc
331         if [ "$cc" ] ; then
332                 case "$cc" in
333                         [0-9]*)
334                         MAXI_MODES=$cc
335                         cheeze=1
336                         ;;
337                         *)
338                         echo ""
339                         echo "You Must Enter a Number in this field. Please Try Again."
340                         cheeze=0
341                         ;;
342                 esac
343         else
344                 cheeze=1
345         fi
346   done
347   echo ""
348
349 ###############################################################################
350 # Code Optimisation?
351
352   cheeze=0
353   echo -e "Enter the Level Of Binary optimisation. This is a number between 0 and 3 (inclusive)"
354   echo -e "The InspIRCd Team will _NOT_ support any bug reports above 0."
355   echo -e "Also note, the IRCd behaviour will be different depending on this value."
356   echo -e "Please read the documentation for more information."
357   echo -e ""
358   echo -e "The Higher the number, the more optimised your binary will be. This value will default to 0"
359   echo -e "If you either a) Dont enter a number, or b) Enter a value outside the range."
360   echo -e $n "[\033[1;32m$OPTIMITEMP\033[0;37m] -> $c"
361   read cc
362   if [ -z "$cc" ] ; then
363         cc=$OPTIMITEMP
364   fi
365   case "$cc" in
366         (1)
367                 OPTIMITEMP=1
368                 OPTIMISATI="-O"
369                 ;;
370         (2)
371                 OPTIMITEMP=2
372                 OPTIMISATI="-O2"
373                 ;;
374         (3)
375                 OPTIMITEMP=3
376                 OPTIMISATI="-O3"
377                 ;;
378         (*)
379                 OPTIMITEMP=0
380                 OPTIMISATI="-g"
381                 ;;
382   esac
383   echo ""
384
385 ###############################################################################
386
387
388 echo -e "\033[1;32mPre-build configuration is complete!\033[0;37m"
389 echo ""
390 echo -e "\033[0;37mConfig path:\033[1;32m\t\t\t$CONFIG_DIR"
391 echo -e "\033[0;37mModule path:\033[1;32m\t\t\t$MODULE_DIR"
392 echo -e "\033[0;37mMax connections:\033[1;32m\t\t$MAX_CLIENT"
393 echo -e "\033[0;37mMax User Channels\033[1;32m\t\t$MAX_CHANNE"
394 echo -e "\033[0;37mMax nickname length:\033[1;32m\t\t$NICK_LENGT"
395 echo -e "\033[0;37mMax channel length:\033[1;32m\t\t$CHAN_LENGT"
396 echo -e "\033[0;37mMax mode length:\033[1;32m\t\t$MAXI_MODES"
397 echo -e "\033[0;37mGCC Version Found:\033[1;32m\t\t$GCCVER"
398 echo -e "\033[0;37mOptimation Flag:\033[1;32m\t\t$OPTIMISATI"
399 echo -e "\033[0;37m"
400
401 echo "Writing cache file for future ./configures ..."
402
403 if [ "$CONFIG_DIR" != "$ME/conf" ] ; then
404     COPY_CONF=1
405 fi
406
407
408 if [ -e ".config.cache" ] ; then
409         rm .config.cache
410 fi
411 echo "CONFIG_DIR=\"$CONFIG_DIR\"" >> .config.cache
412 echo "MODULE_DIR=\"$MODULE_DIR\"" >> .config.cache
413 echo "BINARY_DIR=\"$BINARY_DIR\"" >> .config.cache
414 echo "MAX_CLIENT=\"$MAX_CLIENT\"" >> .config.cache
415 echo "MAX_CHANNE=\"$MAX_CHANNE\"" >> .config.cache
416 echo "NICK_LENGT=\"$NICK_LENGT\"" >> .config.cache
417 echo "MAXI_MODES=\"$MAXI_MODES\"" >> .config.cache 
418 echo "OPTIMITEMP=\"$OPTIMITEMP\"" >> .config.cache
419 echo "OPTIMISATI=\"$OPTIMISATI\"" >> .config.cache
420 echo "COPY_CONF=\"$COPY_CONF\"" >> .config.cache
421
422 echo "Writing include/inspircd_config.h ..."
423
424 echo "/* Auto generated by configure, do not modify! */" >include/inspircd_config.h
425 echo "" >>include/inspircd_config.h
426 if [ "$GCCVER" -eq "3" ] ; then
427 echo "#define GCC3" >>include/inspircd_config.h
428 fi
429 echo "#define SYSLOG_FACILITY LOG_DAEMON" >>include/inspircd_config.h
430 echo "#define SYSLOG_LEVEL LOG_NOTICE" >>include/inspircd_config.h
431 echo "#define CONFIG_FILE \"$CONFIG_DIR/inspircd.conf\"" >>include/inspircd_config.h
432 echo "#define MOD_PATH \"$MODULE_DIR\"" >>include/inspircd_config.h
433 echo "#define VERSION \"`sh ./src/version.sh`\"" >>include/inspircd_config.h
434 echo "#define MAXCLIENTS $MAX_CLIENT" >>include/inspircd_config.h
435 echo "#define NICKMAX $NICK_LENGT" >>include/inspircd_config.h
436 echo "#define CHANMAX $CHAN_LENGT" >>include/inspircd_config.h
437 echo "#define MAXCHANS $MAX_CHANNE" >>include/inspircd_config.h
438 echo "#define MAXMODES $MAXI_MODES" >>include/inspircd_config.h
439 echo "#define OPTIMISATION $OPTIMITEMP" >>include/inspircd_config.h
440 echo "#define SYSTEM \"`uname -n -s -r`\"" >>include/inspircd_config.h
441 echo "#define MAXBUF 514">>include/inspircd_config.h
442 touch include/inspircd_config.h
443
444 echo "Preparing Variables for the Makefile"
445
446 case "$OSNAME" in
447         (FreeBSD)
448                 LDLIBS="-Ldl"
449                 FLAGS="-fPIC -frtti $OPTIMISATI"
450                 MAKEPROG="gmake"
451                 ;;
452         (*)
453                 LDLIBS="-ldl"
454                 FLAGS="-fPIC -frtti $OPTIMISATI"
455                 MAKEPROG="make"
456                 ;;
457 esac
458
459 MODULES=""
460 for module in src/modules/*.cpp ; do
461         mod=`echo $module | sed 's/.cpp/.so/' | sed 's/src\/modules\///'`
462         MODULES="$MODULES $mod" 
463 done
464
465 echo -e "Writing \033[1;37m$OSNAME\033[0;37m makefile"
466 echo ""
467
468 . .Makefile.inc
469
470 echo ""
471
472 echo ""
473 echo "Do you want to compile the IRCd binaries?"
474 echo -e $n "[\033[1;32my\033[0;37m] $c"
475 read YN
476 if [ "$YN" != "n" ] ; then
477         echo ""
478         echo -e "\033[1;32mCompiling...\033[0;37m"
479         echo ""
480         cd $ME
481         $MAKEPROG
482         echo ""
483         echo "Done!"
484         echo ""
485 else
486         echo ""
487         echo "Done!"
488         echo ""
489         echo -e "To build your server with these settings, please type '\033[1;32mmake\033[0;37m' now."
490         echo ""
491         echo -e "*** \033[1;32mRemember to edit your configuration files!!!\033[0;37m ***"
492         echo ""
493 fi
494
495
496 echo ""
497 echo "Do you want to run the config file maker?"
498 echo -e $n "[\033[1;32my\033[0;37m] $c"
499 read YN
500 if [ "$YN" != "n" ] ; then
501         sh makeconf
502 fi
503
504 echo -e "*** \033[1;32mRemember to edit your configuration files!!!\033[0;37m ***"
505 echo ""
506