summaryrefslogtreecommitdiff
path: root/launch_here.rb
blob: 7bc21c805ad0227c0941545feb2ddf163c457e5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/ruby
#
# Load rbot from this directory. (No need to install it with setup.rb)
#

SCM_DIR = File.expand_path File.dirname(__FILE__)
puts "Running from #{SCM_DIR}"

$:.unshift File.join(SCM_DIR, 'lib')

$version = '0.9.15-git'

pwd = Dir.pwd
begin
  Dir.chdir SCM_DIR

  if File.exists? '.git'
    begin
      git_out = `git log -1 --pretty=format:"%H%n%s%n%ct" | git name-rev --stdin`.split("\n")
      $version_timestamp = git_out.last.to_i
      subject = git_out[1].strip
      subject[77..-1] = "..." if subject.length > 80
      commit, branch_spec = git_out.first.scan(/^(\S+)(?: \((\S+)\))?$/).first
      rev = "revision #{commit[0,7]}"
      rev << " [#{subject}]" unless subject.empty?
      changes = `git diff --shortstat HEAD`.split(", ").first
      rev << ", #{changes.strip}" if changes
      if branch_spec
        tag, branch, offset = branch_spec.scan(/^(?:(tag)s\/)?(\S+?)(?:^0)?(?:~(\d+))?$/).first
        tag ||= "branch"
        branch << " #{tag}"
        branch << "-#{offset}" if offset
      else
        branch = "unknown branch"
      end
    rescue => e
      puts e.inspect
      branch = "unknown branch"
      rev = "unknown revision"
    end
    $version << " (#{branch}, #{rev})"
  elsif File.directory? File.join(SCM_DIR, '.svn')
    rev = " (unknown revision)"
    begin
      svn_out = `svn info`
      rev = " (revision #{$1}" if svn_out =~ /Last Changed Rev: (\d+)/
      svn_st = `svn st #{SCM_DIR}`
      rev << ", local changes" if svn_st =~ /^[MDA] /
      rev << ")"
    rescue => e
      puts e.inspect
    end
    $version += rev
  end
ensure
  Dir.chdir pwd
end

module Irc
class Bot
  module Config
    @@datadir = File.join SCM_DIR, 'data/rbot'
    @@coredir = File.join SCM_DIR, 'lib/rbot/core'
  end
end
end

load File.join(SCM_DIR, 'bin/rbot')