Class: Pkgr::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/pkgr/installer.rb

Constant Summary collapse

DEFAULT_URL =
"https://github.com/pkgr/installer.git#master"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(installer_url, distribution) ⇒ Installer

Returns a new instance of Installer.



11
12
13
14
15
16
17
# File 'lib/pkgr/installer.rb', line 11

def initialize(installer_url, distribution)
  @installer_url = installer_url
  @installer_url = DEFAULT_URL if @installer_url == true || @installer_url.nil? || @installer_url.empty?
  @url, @branch = @installer_url.split("#", 2)
  @branch ||= "master"
  @distribution = distribution
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



8
9
10
# File 'lib/pkgr/installer.rb', line 8

def branch
  @branch
end

#distributionObject (readonly)

Returns the value of attribute distribution.



9
10
11
# File 'lib/pkgr/installer.rb', line 9

def distribution
  @distribution
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/pkgr/installer.rb', line 8

def url
  @url
end

Instance Method Details

#call(config) ⇒ Object



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
# File 'lib/pkgr/installer.rb', line 28

def call(config)
  Dir.chdir(installer_tmp_dir) do
    config.wizards.each do |addon_group|
      addon_group.each do |addon|
        addon_dir = "addons/#{addon.name}"
        FileUtils.mkdir_p addon_dir
        puts "-----> [wizard] adding #{addon.name} wizard (#{addon.url}##{addon.branch})"
        shell.run!(
          "curl -L --max-redirs 3 --retry 5 -s '#{addon.tarball_url}' | tar xzf - --strip-components=1 -C '#{addon_dir}'")
      end
    end

    shell.stream!(
      "./bin/compile",
      {
        "APP_NAME" => config.name,
        "APP_VERSION" => config.version,
        "APP_ITERATION" => config.iteration,
        "APP_SAFE_NAME" => config.safe_name,
        "APP_USER" => config.user,
        "APP_GROUP" => config.group,
        "APP_WORKSPACE" => config.source_dir,
        # mysql|postgres,apache2|nginx,smtp
        "APP_WIZARDS" => config.wizards.map{|addon_group| addon_group.map(&:name).join("|")}.join(",")
      }
    )
  end

  FileUtils.mv installer_tmp_dir, File.join(config.build_dir, "usr", "share", config.name, "installer")

  config.dependencies.push(*distribution.installer_dependencies)
  config
end

#installer_tmp_dirObject



62
63
64
# File 'lib/pkgr/installer.rb', line 62

def installer_tmp_dir
  @installer_tmp_dir ||= Dir.mktmpdir
end

#setupObject



23
24
25
26
# File 'lib/pkgr/installer.rb', line 23

def setup
  shell.run!("git clone --depth=1 --branch=\"#{branch}\" \"#{url}\" #{installer_tmp_dir}")
  self
end

#shellObject



19
20
21
# File 'lib/pkgr/installer.rb', line 19

def shell
  Command.new(Pkgr.logger)
end