public
Description: Don't mind this, go to http://github.com/integrity/integrity
Homepage: http://integrityapp.com
Clone URL: git://github.com/foca/integrity.git
integrity / bin / integrity
100755 83 lines (69 sloc) 2.332 kb
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env ruby
require "rubygems"
require "thor"
 
require File.dirname(__FILE__) + "/../lib/integrity"
 
class WithIntegrity < Thor
  include FileUtils
 
  desc "install [PATH]",
       "Copy template files to PATH. Next, go there and edit them."
  def install(path)
    @root = File.expand_path(path)
 
    create_dir_structure
    copy_template_files
    edit_template_files
    create_db(root / 'config.yml')
    after_setup_message
  end
 
  desc "create_db [CONFIG]",
       "Checks the `database_uri` in CONFIG and creates and bootstraps a database for integrity"
  def create_db(config)
    Integrity.new(config)
    DataMapper.auto_migrate!
  end
 
  private
    attr_reader :root
 
    def create_dir_structure
      mkdir_p root
      mkdir_p root / "builds"
      mkdir_p root / "log"
    end
 
    def copy_template_files
      cp Integrity.root / "config" / "config.sample.ru", root / "config.ru"
      cp Integrity.root / "config" / "config.sample.yml", root / "config.yml"
      cp Integrity.root / "config" / "thin.sample.yml", root / "thin.yml"
    end
 
    def edit_template_files
      edit_integrity_configuration
      edit_thin_configuration
    end
 
    def edit_integrity_configuration
      config = File.read(root / "config.yml")
      config.gsub!(%r(sqlite3:///var/integrity.db), "sqlite3://#{root}/integrity.db")
      config.gsub!(%r(/path/to/scm/exports), "#{root}/builds")
      config.gsub!(%r(/var/log), "#{root}/log")
      File.open(root / "config.yml", "w") {|f| f.puts config }
    end
 
    def edit_thin_configuration
      config = File.read(root / 'thin.yml')
      config.gsub!(%r(/apps/integrity), root)
      File.open(root / 'thin.yml', 'w') { |f| f.puts config }
    end
 
    def after_setup_message
      puts
      puts %Q(Awesome! Integrity was installed successfully!)
      puts
      puts %Q(If you want to enable notifiers, install the gems and then require them)
      puts %Q(in #{root}/config.ru)
      puts
      puts %Q(For example:)
      puts
      puts %Q( sudo gem install -s http://gems.github.com foca-integrity-email)
      puts
      puts %Q(And then in #{root}/config.ru add:)
      puts
      puts %Q( require "notifier/email")
      puts
      puts %Q(Don't forget to tweak #{root / "config.yml"} to your needs.)
    end
end
 
WithIntegrity.start