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