gaffer 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.
@@ -0,0 +1,23 @@
1
+ require 'jeweler'
2
+
3
+ Jeweler::Tasks.new do |s|
4
+ s.name = "gaffer"
5
+ s.description = "Duct tape together some debian packages"
6
+ s.summary = s.description
7
+ s.author = "Orion Henry"
8
+ s.email = "orion@heroku.com"
9
+ s.homepage = "http://github.com/orionz/gaffer"
10
+ s.files = FileList["[A-Z]*", "{bin,default,lib,spec}/**/*"]
11
+ s.executables = %w(gaffer)
12
+ s.add_dependency "git"
13
+ end
14
+
15
+ #Jeweler::RubyforgeTasks.new
16
+
17
+ #desc 'Run specs'
18
+ #task :spec do
19
+ # sh 'bacon -s spec/*_spec.rb'
20
+ #end
21
+
22
+ task :default => :spec
23
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.dirname(__FILE__) + '/../lib/gaffer'
4
+
5
+ require 'optparse'
6
+
7
+ options = { }
8
+
9
+ optparse = OptionParser.new do|opts|
10
+ opts.banner = <<banner
11
+ Usage: gaffer [options] ...
12
+ banner
13
+
14
+ opts.on( '-p', '--project NAME', 'Specify a project name. Default is $DIR.' ) do |project|
15
+ options[:project] = project
16
+ end
17
+
18
+ opts.on( '-P', '--prefix PREFIX', 'Install prefix. Default is /opt/$PROJECT/' ) do |prefix|
19
+ options[:prefix] = prefix
20
+ end
21
+
22
+ opts.on( '-v', '--version VERSION', 'Specify a project name. Default is $DIR/VERSION' ) do |version|
23
+ options[:version] = version
24
+ end
25
+
26
+ opts.on( '-h', '--help', 'Display this screen' ) do
27
+ puts opts
28
+ exit
29
+ end
30
+ end
31
+
32
+ optparse.parse!
33
+
34
+ Gaffer::Base.new(options).compile
35
+
@@ -0,0 +1,4 @@
1
+ require 'tmpdir'
2
+ require 'git'
3
+ require File.dirname(__FILE__) + '/gaffer/base'
4
+ require File.dirname(__FILE__) + '/gaffer/deb'
@@ -0,0 +1,35 @@
1
+ module Gaffer
2
+ class Base
3
+ attr_accessor :dir, :git, :project, :readme, :depends, :version, :prefix, :maintainer, :build
4
+
5
+ def initialize(options)
6
+ @dir = options[:dir] || Dir.pwd
7
+ @git = Git.open(@dir)
8
+ @version = options[:version]
9
+ @project = options[:project] || File.basename(File.dirname(@git.repo.path))
10
+ @maintainer = "#{@git.config["user.name"]} <#{@git.config["user.email"]}>"
11
+ @prefix = options[:prefix] || "opt/#{@project}"
12
+
13
+ @git.chdir do
14
+ @readme = File.read("README") rescue "no README file"
15
+ @depends = File.read("DEPENDS").chomp rescue "libc6 (>= 2.10)"
16
+ @version ||= File.read("VERSION").chomp
17
+ end
18
+
19
+ puts "======> #{@version.inspect}"
20
+ build_id = @git.tags.map { |a| a.name =~ /^#{@version}-(.+)/; $1.to_i }.sort.last.to_i + 1
21
+ @build = "#{@version}-#{build_id}"
22
+
23
+ raise "Bad version #{@version}" unless @version =~ /^\d+[.]\d+[.]\d+$/
24
+ end
25
+
26
+ def compile
27
+ @git.add_tag(@build)
28
+ ## check version - tag repo
29
+ [ "i386", "amd64" ].each do |arch|
30
+ Gaffer::Deb.new(self, arch, project, depends).compile
31
+ Gaffer::Deb.new(self, arch, "#{project}-dev", "#{project} (>= #{@version})").compile
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,67 @@
1
+ module Gaffer
2
+ class Deb
3
+ def initialize(base, arch, package, depends)
4
+ @git = base.git
5
+ @base = base
6
+ @arch = arch
7
+ @package = package
8
+ @depends = depends
9
+ @dev = !!(@package =~ /-dev$/)
10
+ end
11
+
12
+ def compile
13
+ puts self.inspect
14
+ Dir.mktmpdir do |dir|
15
+ install_dir = "#{dir}/#{@base.prefix}"
16
+ Git.clone(@base.dir, install_dir)
17
+ system "mkdir #{dir}/DEBIAN"
18
+ puts control
19
+ File.open("#{dir}/DEBIAN/control", "w") do |f|
20
+ f.write(control)
21
+ end
22
+ if @dev
23
+ system "find #{install_dir} | grep -v [.]git | grep -v #{install_dir}$ | xargs rm -rf"
24
+ else
25
+ system "rm -rf #{install_dir}/.git"
26
+ [ "preinst", "postinst", "prerm", "postrm" ].each do |script|
27
+ system "cp #{@base.dir}/#{script} #{dir}/DEBIAN/" if File.exists?("#{@base.dir}/#{script}")
28
+ end
29
+ if File.exists?("#{@base.dir}/init.conf")
30
+ puts "INSTALLING init.conf"
31
+ system "mkdir -p #{dir}/etc/init"
32
+ system "cp #{@base.dir}/init.conf #{dir}/etc/init/#{project}.conf"
33
+ end
34
+ end
35
+ system "dpkg-deb -b #{dir} ./#{filebase}.deb"
36
+ end
37
+ end
38
+
39
+ def origin_url
40
+ @base.git.remotes.select { |r| r.name == "origin" }.map { |r| r.url }.first
41
+ end
42
+
43
+ def description
44
+ "Gaffer package #{@package} #{@base.build}"
45
+ end
46
+
47
+ def filebase
48
+ "#{@package}_#{@base.build}_#{@arch}"
49
+ end
50
+
51
+ def control
52
+ <<CONTROL
53
+ Source: #{@package}
54
+ Section: unknown
55
+ Priority: extra
56
+ Maintainer: #{@base.maintainer}
57
+ Version: #{@base.build}
58
+ Homepage: #{origin_url}
59
+ Package: #{@package}
60
+ Architecture: #{@arch}
61
+ Depends: #{@depends}
62
+ Description: #{description}
63
+ #{@readme}
64
+ CONTROL
65
+ end
66
+ end
67
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gaffer
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Orion Henry
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-11-01 00:00:00 -07:00
19
+ default_executable: gaffer
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: git
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Duct tape together some debian packages
36
+ email: orion@heroku.com
37
+ executables:
38
+ - gaffer
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - Rakefile
45
+ - VERSION
46
+ - bin/gaffer
47
+ - lib/gaffer.rb
48
+ - lib/gaffer/base.rb
49
+ - lib/gaffer/deb.rb
50
+ has_rdoc: true
51
+ homepage: http://github.com/orionz/gaffer
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options:
56
+ - --charset=UTF-8
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.3.7
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Duct tape together some debian packages
84
+ test_files: []
85
+