]> git.donarmstrong.com Git - infobot.git/blob - blootbot
Changed $infobot_ to $bot_
[infobot.git] / blootbot
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
8             $bot_pid $memusage %param
9 );
10
11 BEGIN {
12     # set this to the absolute path if you need it; especially
13     # if . is not in your path
14
15     $bot_base_dir       = '.';
16     $bot_src_dir        = "$bot_base_dir/src";
17     $bot_misc_dir       = "$bot_base_dir/files";
18     $bot_pid            = $$;
19
20     require "$bot_src_dir/logger.pl";
21     require "$bot_src_dir/core.pl";
22     require "$bot_src_dir/interface.pl";
23     require "$bot_src_dir/modules.pl";
24
25     # load the configuration (params) file.
26     &setupConfig();
27
28     &showProc();        # to get the first value.
29     &status("Initial memory usage: $memusage kB");
30     &loadCoreModules();
31     &loadDBModules();
32     &loadFactoidsModules();
33     &loadIRCModules();
34
35     &status("Memory usage after loading modules: $memusage kB");
36 }
37
38 # prevent duplicate processes of the same bot
39 &duperuncheck();
40
41 # initialize everything 
42 &startup();     # first time initialization.
43 &setup();
44
45 if (!&IsParam("Interface") or $param{'Interface'} =~ /IRC/) {
46     # launch the irc event loop
47     &ircloop();
48 } else {
49     &cliloop();
50 }
51
52 exit 0;  # just so you don't look farther down in this file :)
53
54 # --- support routines
55
56 # FIXME.
57 #   add arguments, basically '-h' and '--help', heh.
58 #
59
60 # added by the xk
61 sub duperuncheck {
62     my $pid     = $$;
63     my $file    = $file{PID};
64
65     if ( -f $file) {
66         open(PIDFILE,$file) or die "error: cannot open $file.";
67         my $thispid = <PIDFILE> || "NULL\n";
68         close PIDFILE;
69         chop $thispid;
70
71         if ($thispid =~ /^\D$/) {
72             &staus("warning: pidfile is invalid; wiping out.");
73         } else {
74             if ( -d "/proc/$thispid/") {
75                 &ERROR("bot is already running from this directory.");
76                 &ERROR("if this is incorrect, erase '*.pid'.");
77                 &ERROR("verify with 'ps -axu | grep $thispid'.");
78                 exit 1;
79             } else {
80                 &status("warning: stale $file found; wiping.");
81             }
82         }
83     }
84
85     open(PIDFILE,">$file") or die "error: cannot write to $file.";
86     print PIDFILE "$pid\n";
87     close PIDFILE;
88
89     return 0;
90 }
91
92 1;