]> git.donarmstrong.com Git - infobot.git/blob - infobot
* Move rebranding branch to trunk
[infobot.git] / infobot
1 #!/usr/bin/perl
2
3 # infobot  -- copyright kevin lenzo (c) 1997-1999
4 # blootbot -- copyright david sobon (c) 1999-infinity
5
6 use strict;
7 use vars qw($bot_base_dir $bot_src_dir $bot_misc_dir $bot_state_dir
8             $bot_data_dir $bot_config_dir $bot_log_dir $bot_run_dir
9             $bot_pid $memusage %param
10 );
11
12 BEGIN {
13     if (@ARGV and -f $ARGV[0]) {
14         # source passed config to allow $bot_*_dir to be set.
15         do $ARGV[0];
16     }
17
18     # set any $bot_*_dir var's that aren't already set
19     $bot_base_dir       ||= '.';
20     $bot_config_dir     ||= 'files/';
21     $bot_data_dir       ||= 'files/';
22     $bot_state_dir      ||= 'files/';
23     $bot_run_dir        ||= '.';
24     $bot_src_dir        ||= "$bot_base_dir/src";
25     $bot_log_dir        ||= "$bot_base_dir/log";
26     $bot_misc_dir       ||= "$bot_base_dir/files";
27
28     $bot_pid            = $$;
29
30     require "$bot_src_dir/logger.pl";
31     require "$bot_src_dir/core.pl";
32     require "$bot_src_dir/modules.pl";
33
34     # load the configuration (params) file.
35     &setupConfig();
36
37     &showProc();        # to get the first value.
38     &status("Initial memory usage: $memusage kB");
39     &loadCoreModules();
40     &loadDBModules();
41     &loadFactoidsModules();
42     &loadIRCModules();
43
44     &status("Memory usage after loading modules: $memusage kB");
45 }
46
47 # prevent duplicate processes of the same bot
48 &duperuncheck();
49
50 # initialize everything
51 &startup();     # first time initialization.
52 &setup();
53
54 if (!&IsParam("Interface") or $param{'Interface'} =~ /IRC/) {
55     # launch the irc event loop
56     &ircloop();
57 } else {
58     &cliloop();
59 }
60
61 exit 0;  # just so you don't look farther down in this file :)
62
63 # --- support routines
64
65 # FIXME: add arguments, basically '-h' and '--help', heh.
66
67 # added by the xk
68 sub duperuncheck {
69     my $pid     = $$;
70     my $file    = $file{PID};
71
72     if ( -f $file) {
73         open(PIDFILE,$file) or die "error: cannot open $file.";
74         my $thispid = <PIDFILE> || "NULL\n";
75         close PIDFILE;
76         chop $thispid;
77
78         if ($thispid =~ /^\D$/) {
79             &staus("warning: pidfile is invalid; wiping out.");
80         } else {
81             if ( -d "/proc/$thispid/") {
82                 &ERROR("bot is already running from this directory.");
83                 &ERROR("if this is incorrect, erase '*.pid'.");
84                 &ERROR("verify with 'ps -axu | grep $thispid'.");
85                 exit 1;
86             } else {
87                 &status("warning: stale $file found; wiping.");
88             }
89         }
90     }
91
92     open(PIDFILE,">$file") or die "error: cannot write to $file.";
93     print PIDFILE "$pid\n";
94     close PIDFILE;
95
96     return 0;
97 }
98
99 1;