Class: Houcho::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/houcho/repository.rb

Class Method Summary collapse

Class Method Details

.initObject



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
# File 'lib/houcho/repository.rb', line 6

def self.init
  [
    Houcho::Config::APPROOT,
    Houcho::Config::SPECDIR,
    Houcho::Config::SCRIPTDIR,
    Houcho::Config::OUTERROLESOURCEDIR,
    Houcho::Config::CFYAMLDIR,
    Houcho::Config::LOGDIR
  ].each do |d|
    Dir.mkdir(d) unless Dir.exist?(d)
  end

  File.write("#{Houcho::Config::FILE}", {
    "ukigumo" => { "host" => "", "port" => "" },
    "ikachan" => { "host" => "", "port" => "", "channel" => [] },
    "git" => { "uri" => "" },
  }.to_yaml) unless File.exist?("#{Houcho::Config::FILE}")

  File.write("#{Houcho::Config::SPECDIR}/spec_helper.rb", <<EOD
require "serverspec"
require 'pathname'
require 'net/ssh'
require "json"

include Serverspec::Helper::Ssh
include Serverspec::Helper::DetectOS
include Serverspec::Helper::Attributes

RSpec.configure do |c|
  if ENV['ASK_SUDO_PASSWORD']
require 'highline/import'
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
  else
c.sudo_password = ENV['SUDO_PASSWORD']
  end

  c.ssh.close if c.ssh
  c.host  = ENV['TARGET_HOST']
  options = Net::SSH::Config.for(c.host)
  user    = options[:user] || Etc.getlogin
  c.ssh   = Net::SSH.start(c.host, user, options)

  if ENV['TARGET_HOST_ATTR']
attr_set JSON.parse(ENV['TARGET_HOST_ATTR'], { :symbolize_names => true })
  end
end
EOD
  ) unless File.exist?("#{Houcho::Config::SPECDIR}/spec_helper.rb")

  Houcho::Database.new.create_tables
end