]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blob - bin/rbot
* directory independent launch_here.rb: 3rd attempt
[user/henk/code/ruby/rbot.git] / bin / rbot
1 #!/usr/bin/env ruby
2
3 =begin rdoc
4
5 = rbot main executable
6
7 Usage:
8
9   % rbot [options] [config directory]
10
11 == Options
12
13 [-h, --help]
14     display a help message and exit
15 [-v, --version]
16     display version information and exit
17 [-d, --debug]
18     enable debug messages
19 [-l, --loglevel _level_]
20     sets the minimum log level verbosity
21 [-b, --background]
22     background (daemonize) the bot
23 [-p, --pidfile _filename_]
24     write the bot pid to _filename_
25
26 The default config directory is <tt>~/.rbot</tt>.
27
28 The default pidfile is <tt><i>botdir</i>/rbot.pid</tt>.
29
30 The logfile is located at <tt><i>botdir</i>/<i>botname</i>.log</tt>, and
31 the default loglevel is 1 (INFO messages). Possible values for the loglevel
32 are 0 (DEBUG), 1 (INFO), 2 (WARN), 3 (ERROR), 4 (FATAL).
33
34 Please note that the logfile doesn't contain IRC logs (which are located at
35 <tt><i>botdir</i>/logs/*</tt>, but only rbot diagnostic messages.
36
37 =end
38
39 # Copyright (C) 2002-2006 Tom Gilbert.
40 # Copyright (C) 2007-2008 Giuseppe Bilotta and the rbot development team
41 #
42 # This is free software, see COPYING for licensing details
43
44 $VERBOSE=true
45
46 require 'etc'
47 require 'getoptlong'
48 require 'fileutils'
49
50 $version ||= "0.9.11-git"
51 $opts = Hash.new
52
53 orig_opts = ARGV.dup
54
55 opts = GetoptLong.new(
56   ["--background", "-b", GetoptLong::NO_ARGUMENT],
57   ["--debug", "-d", GetoptLong::NO_ARGUMENT],
58   ["--help",  "-h", GetoptLong::NO_ARGUMENT],
59   ["--loglevel",  "-l", GetoptLong::REQUIRED_ARGUMENT],
60   ["--trace",  "-t", GetoptLong::REQUIRED_ARGUMENT],
61   ["--pidfile", "-p", GetoptLong::REQUIRED_ARGUMENT],
62   ["--version", "-v", GetoptLong::NO_ARGUMENT]
63 )
64
65 $debug = $DEBUG
66 $daemonize = false
67
68 opts.each {|opt, arg|
69   $debug = true if(opt == "--debug")
70   $daemonize = true if(opt == "--background")
71   $opts[opt.sub(/^-+/, "")] = arg
72 }
73
74 $cl_loglevel = $opts["loglevel"].to_i if $opts["loglevel"]
75
76 if ($opts["trace"])
77   set_trace_func proc { |event, file, line, id, binding, classname|
78     if classname.to_s == $opts["trace"]
79       printf "TRACE: %8s %s:%-2d %10s %8s\n", event, File.basename(file), line, id, classname
80     end
81   }
82 end
83
84 defaultlib = File.expand_path(File.dirname($0) + '/../lib')
85
86 if File.directory? "#{defaultlib}/rbot"
87   unless $:.include? defaultlib
88     $:.unshift defaultlib
89   end
90 end
91   
92 begin
93   require 'rbot/ircbot'
94 rescue LoadError => e
95   puts "Error: couldn't find the rbot/ircbot module (or one of its dependencies)\n"
96   puts e
97   exit 2
98 end
99
100 if ($opts["version"])
101   puts "rbot #{$version}"
102   exit 0
103 end
104
105 if ($opts["help"])
106   puts "usage: rbot [options] [config directory]"
107   puts "  -h, --help         this message"
108   puts "  -v, --version      version information"
109   puts "  -d, --debug        enable debug messages"
110   puts "  -l, --loglevel     sets the log level verbosity"
111   puts "  -b, --background   background (daemonize) the bot"
112   puts "  -p, --pidfile      write the bot pid to file"
113   puts "config directory defaults to ~/.rbot"
114   exit 0
115 end
116
117 if(bot = Irc::Bot.new(ARGV.shift, :argv => orig_opts))
118   # just run the bot
119   bot.mainloop
120 end
121