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