debra 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Debra: Make Debian packages with Ruby
2
+
3
+ ## Why?
4
+
5
+ Because I found the process of making Debian packages a little long winded. It does seem to work well for my use case: building binary packages of web applications on a CI server.
6
+
7
+ Also, I'm still learning the Debian packaging system so wouldn't recommend this for serious use, just your own packages.
8
+
9
+ ## How?
10
+
11
+ Install
12
+
13
+ $: sudo gem install debra
14
+
15
+ Create a Defile in your projects directory
16
+
17
+ # Defile
18
+ Debra do
19
+
20
+ # Specify the files to be included (just a Rake::FileList delegate)
21
+ files "etc/**/*"
22
+
23
+ # Specify your control file fields
24
+ # See http://www.debian.org/doc/debian-policy/ch-controlfields.html
25
+ control do
26
+ package "my-package"
27
+ version "0.1"
28
+ section "base"
29
+ priority "optional"
30
+ architecture "all"
31
+ depends "apache2, apache2-dev"
32
+ maintainer "My Name <me@example.com>"
33
+ description %q{My Pacakge Title
34
+ Extended description goes here ...
35
+ }
36
+ end
37
+
38
+ # Specify preinst, postinst, prerm, postrm files like this
39
+ postinst %q{#!/bin/bash
40
+
41
+ service apache restart
42
+
43
+ }
44
+
45
+ end
46
+
47
+ Build your file
48
+
49
+ $: sudo debra
50
+
51
+ ## Command line options
52
+
53
+ Usage: debra [options]
54
+ -h, --help Show this message
55
+ -v, --verbose Run verbosely
56
+ -f, --file file Load a specific Debfile
57
+ --version Show version
58
+
59
+ License
60
+
61
+ License:
62
+
63
+ (GPLv3)
64
+
65
+ ## Examples
66
+
67
+ See the examples directory
68
+
69
+ ## License
70
+
71
+ Copyright (C) 2009 Matt Haynes
72
+
73
+ This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
74
+
75
+ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
76
+
77
+ You should have received a copy of the GNU General Public License along with this program. If not, see <w
data/bin/debra ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.push(File.dirname(__FILE__) + "/../lib")
4
+
5
+ require "debra"
6
+
7
+ Debra.exec
data/lib/debra/cli.rb ADDED
@@ -0,0 +1,69 @@
1
+ require 'optparse'
2
+ require 'ostruct'
3
+
4
+ module Debra
5
+
6
+ DEBFILES = ['Debfile', 'debfile'].freeze
7
+
8
+ module Cli
9
+
10
+ def exec
11
+
12
+ options = OpenStruct.new
13
+
14
+ OptionParser.new do |opts|
15
+
16
+ opts.banner = 'Usage: debra [options]'
17
+ opts.on("-h", "--help", "Show this message") {|h| options.help = h}
18
+ opts.on("-v", "--verbose", "Run verbosely") {|v| options.verbose = v}
19
+ opts.on("-ffile", "--file file", String, "Load a specific Debfile") {|f| options.file = f}
20
+ opts.on("--version", "Show version") do
21
+ puts "Debra " + Debra::VERSION.join('.')
22
+ exit
23
+ end
24
+
25
+ begin
26
+ opts.parse!
27
+ rescue OptionParser::MissingArgument,
28
+ OptionParser::InvalidOption,
29
+ OptionParser::InvalidArgument => e
30
+ puts e.message + ', use --help for more details'
31
+ exit 1
32
+ end
33
+
34
+ if !options.file.nil? && !File.exists?(options.file)
35
+ puts "Cannot find file #{options.file}"
36
+ exit 1
37
+ end
38
+
39
+ if options.help
40
+ puts opts
41
+ exit 1
42
+ end
43
+
44
+ end
45
+
46
+ options.file = options.file || find_debfile
47
+
48
+ run options
49
+
50
+ end
51
+
52
+ def find_debfile
53
+
54
+ DEBFILES.each do |filename|
55
+ file = Dir.pwd + "/#{filename}"
56
+ if File.exists? file
57
+ return file
58
+ end
59
+ end
60
+
61
+ puts "Cannot find a valid debfile, searched current working directory for #{DEBFILES.join(",")}"
62
+ puts "Please add a valid debfile or use the --file argument"
63
+ exit 1
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -0,0 +1,91 @@
1
+ module Debra
2
+
3
+ module Execute
4
+
5
+ def run(options)
6
+
7
+ @@options = options
8
+ @@control = {}
9
+ @@files = []
10
+ @@generate = {}
11
+
12
+ puts "Loading #{options.file}" if options.verbose
13
+ load_file
14
+
15
+ puts "Creating temp files" if options.verbose
16
+ tmp_dir = "/tmp/debra_" + Process.pid.to_s
17
+
18
+ Dir.mkdir tmp_dir
19
+ Dir.mkdir tmp_dir + "/DEBIAN"
20
+
21
+ write tmp_dir + "/DEBIAN/control", generate_control_text
22
+
23
+ @@generate.each_pair do |name, contents|
24
+ write tmp_dir + "/DEBIAN/#{name.to_s}", contents
25
+ File.chmod 0755, tmp_dir + "/DEBIAN/#{name.to_s}"
26
+ end
27
+
28
+ @@files.resolve.each do |file|
29
+ FileUtils.cp_r file, tmp_dir
30
+ end
31
+
32
+ puts "Generating debian package" if options.verbose
33
+ `dpkg --build #{tmp_dir} #{package_name}`
34
+
35
+ if $? != 0
36
+ puts "Error running dpkg, exiting"
37
+ FileUtils.rm_rf tmp_dir
38
+ exit 1
39
+ end
40
+
41
+ puts "Removing temp files" if options.verbose
42
+ FileUtils.rm_rf tmp_dir
43
+
44
+ puts "Created package: #{package_name}"
45
+
46
+ end
47
+
48
+ def package_name
49
+ "#{@@control[:package]}-#{@@control[:version]}-#{@@control[:architecture]}.deb"
50
+ end
51
+
52
+ def write(file, str)
53
+ file = File.new(file, "w")
54
+ file.write(str + "\n")
55
+ file.close
56
+ end
57
+
58
+ def method_missing(sym, *args)
59
+ @@control[sym] = args[0]
60
+ end
61
+
62
+ def files(*args, &block)
63
+ @@files = Rake::FileList.new *args, &block
64
+ end
65
+
66
+ def generate_control_text
67
+ @@control.to_a.map do |item|
68
+ key = item[0].to_s.split("_").map{|v| v.capitalize}.join("-")
69
+ "#{key}: #{item[1]}"
70
+ end.join("\n")
71
+ end
72
+
73
+ def control
74
+ yield
75
+ end
76
+
77
+ [:preinst, :postinst, :prerm, :postrm].each do |method|
78
+ class_eval <<-EVAL
79
+ def #{method.to_s}(str)
80
+ @@generate[:#{method.to_s}] = str
81
+ end
82
+ EVAL
83
+ end
84
+
85
+ def load_file
86
+ class_eval "load '#{@@options.file}'"
87
+ end
88
+
89
+ end
90
+
91
+ end
data/lib/debra.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "debra/cli"
2
+ require "debra/execute"
3
+ require 'rubygems'
4
+ require 'rake'
5
+
6
+ module Debra
7
+
8
+ include Cli
9
+ include Execute
10
+
11
+ VERSION = [0,0,1]
12
+
13
+ module_function :exec, :find_debfile, :run, :load_file
14
+
15
+ end
16
+
17
+ def Debra
18
+ include Debra
19
+ yield
20
+ end
21
+
22
+
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: debra
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Matt Haynes
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-21 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rake
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Debra is an DSL for creating debian binary package files, still in the experimental stage but should work!
34
+ email: matt@matthaynes.net
35
+ executables:
36
+ - debra
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - lib/debra/cli.rb
43
+ - lib/debra/execute.rb
44
+ - lib/debra.rb
45
+ - README.md
46
+ - bin/debra
47
+ has_rdoc: false
48
+ homepage: http://github.com/matth/debra/tree/master
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 0
71
+ version: "0"
72
+ requirements: []
73
+
74
+ rubyforge_project:
75
+ rubygems_version: 1.3.7
76
+ signing_key:
77
+ specification_version: 3
78
+ summary: A little DSL for creating debian packages (experimental)
79
+ test_files: []
80
+