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