Class: Gaffer::Deb

Inherits:
Object
  • Object
show all
Defined in:
lib/gaffer/deb.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, _package, _depends) ⇒ Deb

Returns a new instance of Deb.



5
6
7
8
9
10
11
# File 'lib/gaffer/deb.rb', line 5

def initialize(base, _package, _depends)
  @base = base
  @arch = "all"
  @package = _package
  @depends = _depends
  @dev = !!(@package =~ /-dev$/)
end

Instance Attribute Details

#archObject

Returns the value of attribute arch.



3
4
5
# File 'lib/gaffer/deb.rb', line 3

def arch
  @arch
end

#dependsObject

Returns the value of attribute depends.



3
4
5
# File 'lib/gaffer/deb.rb', line 3

def depends
  @depends
end

#packageObject

Returns the value of attribute package.



3
4
5
# File 'lib/gaffer/deb.rb', line 3

def package
  @package
end

#readmeObject

Returns the value of attribute readme.



3
4
5
# File 'lib/gaffer/deb.rb', line 3

def readme
  @readme
end

Instance Method Details

#buildObject



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
# File 'lib/gaffer/deb.rb', line 13

def build
  Dir.mktmpdir do |dir|
    install_dir = "#{dir}/#{@base.prefix}"
    Git.clone(@base.dir, install_dir)
    Rush.bash "mkdir #{dir}/DEBIAN"
    File.open("#{dir}/DEBIAN/control", "w") do |f|
      f.write(control)
    end
    puts control
    if @dev
      Rush.bash "find #{install_dir} | grep -v [.]git | grep -v #{install_dir}$ | xargs rm -rf"
    else
      Rush.bash "find #{install_dir} | grep    [.]git | grep -v #{install_dir}$ | xargs rm -rf"
#          [ :preinst, :postinst, :prerm, :postrm ].each do |script|
#            file = File.open("#{dir}/DEBIAN/#{script}","w")
#            file.chmod(0755)
#            file.write(template(script))
#            file.close
#          end
      if has_init?
        puts "INSTALLING init.conf"
        Rush.bash "mkdir -p #{dir}/etc/init"
        Rush.bash "cp #{@base.dir}/init.conf #{dir}/etc/init/#{@base.project}.conf"
      end
      if File.exists?("#{@base.dir}/Gemfile")
        Dir.chdir(@base.dir) do
          # TODO this can break in strange ways - STDOUT/STDERR is a mess
          if Rush.bash('bundle install --deployment').match(/native extensions/)
            @arch = Rush.bash "dpkg --print-architecture"
          end
        end
      end
    end
    Rush.bash "dpkg-deb -b #{dir} ./#{filebase}.deb"
    File.expand_path("./#{filebase}.deb")
  end
end

#build_nameObject



75
76
77
# File 'lib/gaffer/deb.rb', line 75

def build_name
  @base.build_name
end

#controlObject



79
80
81
# File 'lib/gaffer/deb.rb', line 79

def control
  template(:control)
end

#descriptionObject



59
60
61
# File 'lib/gaffer/deb.rb', line 59

def description
  "Gaffer package #{package} #{build_name}"
end

#filebaseObject



63
64
65
# File 'lib/gaffer/deb.rb', line 63

def filebase
    "#{package}_#{build_name}_#{@arch}"
end

#has_init?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/gaffer/deb.rb', line 51

def has_init?
  File.exists?("#{@base.dir}/init.conf")
end

#maintainerObject



71
72
73
# File 'lib/gaffer/deb.rb', line 71

def maintainer
  @base.maintainer
end

#origin_urlObject



55
56
57
# File 'lib/gaffer/deb.rb', line 55

def origin_url
  @base.git.remotes.select { |r| r.name == "origin" }.map { |r| r.url }.first
end

#template(type) ⇒ Object



67
68
69
# File 'lib/gaffer/deb.rb', line 67

def template(type)
  ERB.new(File.read("#{File.dirname(__FILE__)}/../../templates/#{type}.erb")).result(binding)
end