Class: Ploy::LocalPackage::DebBuilder
- Inherits:
-
Object
- Object
- Ploy::LocalPackage::DebBuilder
- Defined in:
- lib/ploy/localpackage/debbuilder.rb
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#dist_dir ⇒ Object
Returns the value of attribute dist_dir.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#sha ⇒ Object
Returns the value of attribute sha.
-
#timestamp ⇒ Object
Returns the value of attribute timestamp.
-
#upstart_files ⇒ Object
Returns the value of attribute upstart_files.
Instance Method Summary collapse
- #build_deb ⇒ Object
- #fpm_optlist(dir) ⇒ Object
-
#initialize(opts = {}) ⇒ DebBuilder
constructor
A new instance of DebBuilder.
- #mirror_dist(dir) ⇒ Object
- #mirror_dist_target(topdir) ⇒ Object
- #safeversion(txt) ⇒ Object
- #write_after_install_script(file) ⇒ Object
- #write_metadata(dir) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ DebBuilder
16 17 18 19 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 16 def initialize(opts = {}) = "/etc/ploy/metadata.d" opts.each { |k,v| instance_variable_set("@#{k}", v) } # maybe? end |
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
10 11 12 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 10 def branch @branch end |
#dist_dir ⇒ Object
Returns the value of attribute dist_dir.
13 14 15 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 13 def dist_dir @dist_dir end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 8 def name @name end |
#prefix ⇒ Object
Returns the value of attribute prefix.
14 15 16 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 14 def prefix @prefix end |
#sha ⇒ Object
Returns the value of attribute sha.
9 10 11 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 9 def sha @sha end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
11 12 13 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 11 def end |
#upstart_files ⇒ Object
Returns the value of attribute upstart_files.
12 13 14 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 12 def upstart_files @upstart_files end |
Instance Method Details
#build_deb ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 21 def build_deb info = nil Dir.mktmpdir do |dir| mirror_dist(dir) (dir) Tempfile.open(['postinst', 'sh']) do |file| write_after_install_script(file) ol = fpm_optlist(dir) ol.add("--after-install", file.path) puts "debug: fpm #{ol.as_string} ." info = eval(`fpm #{ol.as_string} .`) end end return info[:path] end |
#fpm_optlist(dir) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 37 def fpm_optlist(dir) optlist = Ploy::LocalPackage::DebBuilderOptlist.new [ { "-n" => @name }, { "-s" => "dir" }, { "-t" => "deb" }, { "-a" => "all" }, { "-C" => dir }, { "--deb-field" => "'gitrev: #{@sha}'" }, "-f", { "-v" => safeversion( + '.' + @branch) }, ] if @upstart_files then @upstart_files.each do | upstart | optlist.add("--deb-upstart", upstart) end end return optlist end |
#mirror_dist(dir) ⇒ Object
62 63 64 65 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 62 def mirror_dist(dir) FileUtils.mkpath mirror_dist_target(dir) system("rsync -aC #{@dist_dir}/* #{mirror_dist_target(dir)}") end |
#mirror_dist_target(topdir) ⇒ Object
67 68 69 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 67 def mirror_dist_target(topdir) return @prefix ? File.join(topdir, @prefix) : topdir end |
#safeversion(txt) ⇒ Object
58 59 60 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 58 def safeversion(txt) return txt.gsub(/[^A-Za-z0-9\.\+]/, '') end |
#write_after_install_script(file) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 71 def write_after_install_script(file) file.write "#!/bin/bash\n\n# this is awful\ncheck_upstart_service(){\n status $1 | grep -q \"^$1 start\" > /dev/null\n return $?\n}\n" @upstart_files.each do | upstart | service = File.basename(upstart) file.write " if check_upstart_service \#{service}; then\n restart \#{service}\n else\n start \#{service}\n fi\n" end file.flush end |
#write_metadata(dir) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ploy/localpackage/debbuilder.rb', line 94 def (dir) base = File.join(dir, ) FileUtils.mkpath(base) path = File.join(base, "#{@name}.yml") info = { "name" => @name, "sha" => @sha, "timestamp" => , "branch" => @branch, } File.open(path, 'w') do | out | YAML.dump(info, out) end end |