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