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