2 # InspIRCd Configuration Script
4 # Copyright 2003 The ChatSpike Development Team
5 # <brain@chatspike.net>
6 # <Craig@chatspike.net>
8 # [14:21] Brain: <matrix impression> i know perl-fu!
12 ########################################
15 $this = $ENV{PWD}; # PWD, Regardless.
16 @modlist = (); # Declare for Module List..
17 %config = (); # Initiate Configuration Hash..
18 $config{ME} = $ENV{PWD}; # Present Working Directory
19 $config{CONFIG_DIR} = $ENV{PWD}."/conf"; # Configuration Directory
20 $config{MODULE_DIR} = $ENV{PWD}."/modules"; # Modules Directory
21 $config{BINARY_DIR} = $ENV{PWD}."/bin"; # Binary Directory
22 $config{OPTIMITEMP} = "0"; # Default Optimisation Value
23 $config{OPTIMISATI} = "-g"; # Optimisation Flag
24 $config{NICK_LENGT} = "32"; # Default Nick Length
25 $config{CHAN_LENGT} = "64"; # Default Channel Name Length
26 $config{MAX_CHANNE} = "20"; # Default Max. Channels per user..
27 $config{MAXI_MODES} = "20"; # Default Max. Number of Modes set at once.
28 $config{HAS_STRLCPY} = "false"; # strlcpy Check.
29 chomp($config{MAX_CLIENT_T} = `sh -c \"ulimit -n\"`); # FD Limit
30 chomp($config{GCCVER} = `gcc -dumpversion | cut -c 1`); # Major GCC Version
31 chomp($config{GCC34} = `gcc -dumpversion | cut -c 3`); # Minor GCC Version
32 chomp($config{OSNAME} = `uname -s`); # Operating System Name
34 if (!$config{OSNAME}) {
35 $config{OSNAME} = "Unknown"; # For use when uname fails.
38 if (!$config{MAX_CLIENT_T}) {
39 $config{MAX_CLIENT_T} = 1024; # Set a reasonable 'Default'
40 $fd_scan_fail = "true"; # Used Later
43 # Get and Set some important vars..
46 my $arg = $ARGV[0]; # Do Some Argument Checks..
47 if ($arg eq "-clean") { `rm -rf .config.cache`; } # Remove the config.cache file.
49 if ($arg eq "-update") {
50 # Does the cache file exist?
52 # No, No it doesn't.. *BASH*
53 print "You have not run ./configure before. Please do this before trying to run the update script.\n";
56 # We've Loaded the cache file and all our variables..
57 print "Updating Files..\n";
69 if (!$config{MAX_CLIENT}) {
70 # If the cache hasn't set the max clients, copy the variable of MAX_CLIENT_T, this
71 # allows us to keep _T for testing purposes. (ie. "Are you sure you want to go
72 # higher than the found value" :))
73 $config{MAX_CLIENT} = $config{MAX_CLIENT_T};
76 # Perform the strlcpy() test..
77 open(STRLCPY, ">.test.cpp");
78 print STRLCPY "#include <string.h>
80 int main() { char a[10]; char b[10]; strlcpy(a,b,10); printf(\"%d\\n\",9); }\n";
84 system("g++ -o .test .test.cpp 2>&1");
86 # Was the build succesful?
88 $config{HAS_STRLCPY} = "true";
89 system("rm -f .test .test.cpp");
92 ################################################################################
93 # BEGIN INTERACTIVE PART #
94 ################################################################################
98 # Display Splash Logo..
100 chomp($wholeos = `uname -mnr`);
102 # Display Introduction Message..
104 Welcome to the InspIRCd Configuration program!
106 *** If you are unsure of any of these values, leave it blank for ***
107 *** standard settings that will work, and your server will run ***
108 *** using them. If you are running this server as part of a ***
109 *** larger network, you must consult with your network admins ***
110 *** for the proper values to use, or server links will be unstable! ***
112 Press \033[1m<RETURN>\033[0m to accept the default for any option, or enter
113 a new value. Please note: You will \033[1mHAVE\033[0m to read the docs
114 dir, otherwise you won't have a config file!
116 Your operating system is: \033[1;32m$config{OSNAME}\033[0m ($wholeos), fdmax: $config{MAX_CLIENT_T}\n\n";
118 # Directory Settings..
119 dir_check("are the configuration files", "CONFIG_DIR");
120 dir_check("are the modules to be compiled to", "MODULE_DIR");
121 dir_check("is the IRCd binary to be placed", "BINARY_DIR");
123 # File Descriptor Settings..
126 print "Maximum number of clients at any one time ($config{MAX_CLIENT_T})\n";
127 print "[\033[1;32m$config{MAX_CLIENT}\033[0m] -> ";
128 chomp($var = <STDIN>);
129 if ($var eq "") { $var = $config{MAX_CLIENT}; }
130 if ($var =~ /^\d+$/) {
131 if (($var > $config{MAX_CLIENT_T}) && ($fd_scan_failed ne true)) {
132 # Client has entered a larger number than the 'discovered' value
134 print "WARNING: Our scans have indicated that you are attempting
135 to use more sockets than there are avaliable. Are you sure
136 you wish to do this? It may cause the IRCd to malfunction [y/n]
137 [\033[1;32mn\033[0m] -> $c";
138 chomp($tmp = <STDIN>);
140 print "Please enter the correct value.\n\n";
145 print "You must enter a number in this field. Please try again.\n\n";
148 # If we get here, we should be good to go.
149 $config{MAX_CLIENT} = $var;
156 print "What is the Maximum length of nicknames?\n";
157 print "[\033[1;32m$config{NICK_LENGT}\033[0m] -> ";
158 chomp($var = <STDIN>);
159 if ($var eq "") { $var = $config{NICK_LENGT}; }
160 if ($var =~ /^\d+$/) {
161 # We don't care what the number is, set it and be on our way.
162 $config{NICK_LENGT} = $var;
166 print "You must enter a number in this field. Please try again.\n\n";
172 print "What is the Maximum number of mode changes in one line?\n";
173 print "[\033[1;32m$config{MAXI_MODES}\033[0m] -> ";
174 chomp($var = <STDIN>);
175 if ($var eq "") { $var = $config{MAXI_MODES}; }
176 if ($var =~ /^\d+$/) {
177 # We don't care what the number is, set it and be on our way.
178 $config{MAXI_MODES} = $var;
182 print "You must enter a number in this field. Please try again.\n\n";
187 print "Enter the Level Of Binary optimisation. This is a number between 0 and 3 (inclusive)
188 The InspIRCd Team will _NOT_ support any bug reports above 0.
189 Also note, the IRCd behaviour will be different depending on this value.
190 Please read the documentation for more information.
192 The Higher the number, the more optimised your binary will be. This value will default to 0
193 If you either a) Dont enter a number, or b) Enter a value outside the range.\n";
194 print "[\033[1;32m0\033[0m] -> ";
195 chomp($var = <STDIN>);
197 $config{OPTIMITEMP} = 1;
198 $config{OPTIMISATI} = "-O";
199 } elsif ($var == 2) {
200 $config{OPTIMITEMP} = 2;
201 $config{OPTIMISATI} = "-O2";
202 } elsif ($var == 3) {
203 $config{OPTIMITEMP} = 3;
204 $config{OPTIMISATI} = "-O3";
206 $config{OPTIMITEMP} = 0;
207 $config{OPTIMISATI} = "-g";
210 print "\n\033[1;32mPre-build configuration is complete!\033[0m\n\n";
211 print "\033[0mConfig path:\033[1;32m\t\t\t$config{CONFIG_DIR}\n";
212 print "\033[0mModule path:\033[1;32m\t\t\t$config{MODULE_DIR}\n";
213 print "\033[0mMax connections:\033[1;32m\t\t$config{MAX_CLIENT}\n";
214 print "\033[0mMax User Channels\033[1;32m\t\t$config{MAX_CHANNE}\n";
215 print "\033[0mMax nickname length:\033[1;32m\t\t$config{NICK_LENGT}\n";
216 print "\033[0mMax channel length:\033[1;32m\t\t$config{CHAN_LENGT}\n";
217 print "\033[0mMax mode length:\033[1;32m\t\t$config{MAXI_MODES}\n";
218 print "\033[0mGCC Version Found:\033[1;32m\t\t$config{GCCVER}.$config{GCC34}\n";
219 print "\033[0mOptimatizaton Flag:\033[1;32m\t\t$config{OPTIMISATI}\033[0m\n\n";
225 print "To build your server with these settings, please type '\033[1;32m$config{MAKEPROG}\033[0m' now.\n";
226 print "*** \033[1;32mRemember to edit your configuration files!!!\033[0m ***\n\n\n";
228 ################################################################################
230 ################################################################################
232 # Retrieves the .config.cache file, and loads values into the main config hash.
233 open(CACHE, ".config.cache") or return undef;
237 # Ignore Blank lines, and comments..
241 my ($key, $value) = split("=", $_);
242 $value =~ /^\"(.*)\"$/;
243 # Do something with data here!
251 # Dump the contents of %config
252 print "Writing \033[1;32mcache file\033[0m for future ./configures ...\n";
253 open(FILEHANDLE, ">.config.cache");
254 foreach $key (keys %config)
256 print FILEHANDLE "$key=\"$config{$key}\"\n";
262 my ($desc, $hash_key) = @_;
265 print "In what directory $desc?\n";
266 print "[\033[1;32m$config{$hash_key}\033[0m] -> ";
267 chomp($var = <STDIN>);
268 if ($var eq "") { $var = $config{$hash_key}; }
269 if (substr($var,0,1) ne "/")
271 # Assume relative Path was given.. fill in the rest.
272 $var = $this . "/$var";
274 if (substr($var, 0, 1) eq "~") {
275 # Convert it to a full path..
277 $var = $this . substr(1,0);
280 print "$var does not exist. Create it?\n[\033[1;32my\033[0m] ";
281 chomp($tmp = <STDIN>);
282 if (($tmp eq "") || ($tmp = "y")) {
283 # Attempt to Create the Dir..
284 $chk = system("mkdir -p \"$var\" >> /dev/null 2>&1") / 256;
286 print "Unable to create directory. ($var)\n\n";
291 # They said they don't want to create, and we can't install there.
297 # Target exists, but is not a directory.
298 print "File $var exists, but is not a directory.\n\n";
302 # Either Dir Exists, or was created fine.
303 $config{$hash_key} = $var;
310 if ($config{OSNAME} eq "FreeBSD") {
311 $config{LDLIBS} = "-Ldl";
312 $config{FLAGS} = "-fPIC -frtti $OPTIMISATI -Woverloaded-virtual -g";
313 $config{MAKEPROG} = "gmake";
315 $config{LDLIBS} = "-ldl";
316 $config{FLAGS} = "-fPIC -frtti $OPTIMISATI -Woverloaded-virtual -g";
317 $config{MAKEPROG} = "make";
335 opendir(DIRHANDLE, "src/modules");
336 foreach $name (sort readdir(DIRHANDLE)) {
337 if ($name =~ /^m_(.+)\.cpp$/)
347 print "Writing \033[1;32minspircd_config.h\033[0m\n";
348 # First File.. inspircd_config.h
349 chomp(my $incos = `uname -n -s -r`);
350 chomp(my $version = `sh ./src/version.sh`);
351 open(FILEHANDLE, "> include/inspircd_config.h");
352 print FILEHANDLE <<EOF;
353 /* Auto generated by configure, do not modify! */
354 #define SYSLOG_FACILITY LOG_DAEMON
355 #define SYSLOG_LEVEL LOG_NOTICE
356 #define CONFIG_FILE "$config{CONFIG_DIR}/inspircd.conf"
357 #define MOD_PATH "$config{MODULE_DIR}"
358 #define VERSION "$version"
359 #define MAXCLIENTS $config{MAX_CLIENT}
360 #define NICKMAX $config{NICK_LENGT}
361 #define CHANMAX $config{CHAN_LENGT}
362 #define MAXCHANS $config{MAX_CHANNE}
363 #define MAXMODES $config{MAXI_MODES}
364 #define OPTIMISATION $config{OPTIMITEMP}
365 #define SYSTEM "$incos"
369 if ($config{GCCVER} > 3) {
370 print FILEHANDLE "#define GCC3\n";
371 print FILEHANDLE "#define GCC34\n";
375 if ($config{GCCVER} == 3) {
376 print FILEHANDLE "#define GCC3\n";
377 if ($config{GCC34} > 3) {
378 print FILEHANDLE "#define GCC34\n";
382 if ($config{HAS_STRLCPY} eq "true") {
383 print FILEHANDLE "#define HAS_STRLCPY\n";
387 # Create a Modules List..
389 foreach $i (@modlist)
391 $modules .= "m_".$i.".so ";
393 chomp($modules); # Remove Redundant whitespace..
396 # Write all .in files.
399 opendir(DIRHANDLE, $this);
400 foreach $name (sort readdir(DIRHANDLE)) {
401 if ($name =~ /^\.(.+)\.inc$/)
404 # All .name.inc files need parsing!
406 open(FILEHANDLE, ".$file.inc");
407 while (<FILEHANDLE>) {
412 $tmp =~ s/\@MAKEPROG\@/$config{MAKEPROG}/;
413 $tmp =~ s/\@FLAGS\@/$config{FLAGS}/;
414 $tmp =~ s/\@LDLIBS\@/$config{LDLIBS}/;
415 $tmp =~ s/\@CONFIG_DIR\@/$config{CONFIG_DIR}/;
416 $tmp =~ s/\@MODULE_DIR\@/$config{MODULE_DIR}/;
417 $tmp =~ s/\@BINARY_DIR\@/$config{BINARY_DIR}/;
418 $tmp =~ s/\@MODULES\@/$modules/;
420 print "Writing \033[1;32m$file\033[0m\n";
421 open(FILEHANDLE, ">$file");
422 print FILEHANDLE $tmp;
427 # Make inspircd executable!
428 chmod 0744, 'inspircd';
431 print "Writing \033[1;32msrc/modules/Makefile\033[0m\n";
432 open(FILEHANDLE, ">src/modules/Makefile");
433 print FILEHANDLE <<EOF;
434 # (C) ChatSpike development team
435 # Makefile by <Craig\@ChatSpike.net>
436 # Many Thanks to Andrew Church <achurch\@achurch.org>
437 # for assisting with making this work right.
439 # Automatically Generated by ./configure to add a modules
440 # please run ./configure --update
446 # Create a Modules List..
449 foreach $i (@modlist)
451 $flags = getcompilerflags("src/modules/m_".$i.".cpp");
452 print FILEHANDLE <<EOCHEESE;
453 m_$i.so: m_$i.cpp ../../include/modules.h ../../include/users.h ../../include/channels.h ../../include/servers.h ../../include/base.h
454 \$(CC) -I../../include \$(FLAGS) -shared $flags -o m_$i.so m_$i.cpp
455 \@cp m_$i.so \$(MODPATH)/
461 sub getcompilerflags {
465 if ($_ =~ /^\/\* \$CompileFlags: (.+) \*\/$/) {
475 print "'\033[1;33m####\033[0m:'\033[1;33m##\033[0m::: \033[1;33m##\033[0m::'\033[1;33m######\033[0m::'\033[1;33m########\033[0m::'\033[1;33m####\033[0m:'\033[1;33m########\033[0m:::'\033[1;33m######\033[0m::'\033[1;33m########\033[0m::\n";
476 print ". \033[1;33m##\033[0m:: \033[1;33m###\033[0m:: \033[1;33m##\033[0m:'\033[1;33m##\033[0m... \033[1;33m##\033[0m: \033[1;33m##\033[0m.... \033[1;33m##\033[0m:. \033[1;33m##\033[0m:: \033[1;33m##\033[0m.... \033[1;33m##\033[0m:'\033[1;33m##\033[0m... \033[1;33m##\033[0m: \033[1;33m##\033[0m.... \033[1;33m##\033[0m:\n";
477 print ": \033[1;33m##\033[0m:: \033[1;33m####\033[0m: \033[1;33m##\033[0m: \033[1;33m##\033[0m:::..:: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:: \033[1;33m##\033[0m:: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m: \033[1;33m##\033[0m:::..:: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:\n";
478 print ": \033[1;33m##\033[0m:: \033[1;33m##\033[0m \033[1;33m##\033[0m \033[1;33m##\033[0m:. \033[1;33m######\033[0m:: \033[1;33m########\033[0m::: \033[1;33m##\033[0m:: \033[1;33m########\033[0m:: \033[1;33m##\033[0m::::::: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:\n";
479 print ": \033[1;33m##\033[0m:: \033[1;33m##\033[0m. \033[1;33m####\033[0m::..... \033[1;33m##\033[0m: \033[1;33m##\033[0m.....:::: \033[1;33m##\033[0m:: \033[1;33m##\033[0m.. \033[1;33m##\033[0m::: \033[1;33m##\033[0m::::::: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:\n";
480 print ": \033[1;33m##\033[0m:: \033[1;33m##\033[0m:. \033[1;33m###\033[0m:'\033[1;33m##\033[0m::: \033[1;33m##\033[0m: \033[1;33m##\033[0m::::::::: \033[1;33m##\033[0m:: \033[1;33m##\033[0m::. \033[1;33m##\033[0m:: \033[1;33m##\033[0m::: \033[1;33m##\033[0m: \033[1;33m##\033[0m:::: \033[1;33m##\033[0m:\n";
481 print "'\033[1;33m####\033[0m: \033[1;33m##\033[0m::. \033[1;33m##\033[0m:. \033[1;33m######\033[0m:: \033[1;33m##\033[0m::::::::'\033[1;33m####\033[0m: \033[1;33m##\033[0m:::. \033[1;33m##\033[0m:. \033[1;33m######\033[0m:: \033[1;33m########\033[0m::\n";
482 print "\033[0m\033[0m....::..::::..:::......:::..:::::::::....::..:::::..:::......:::........:::\n\n";