Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "http://rubygems.org"

gemspec

gem 'ruby-debug'
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ $ dpkg --info pkg/git_1.7.5.4-1+github1_amd64.deb
Homepage: http://git-scm.com
Description: The Git DVCS with custom patches and bugfixes for GitHub.
```

## Building on OSX

Some packages can be built on OSX, but you must install the [dpkg](https://raw.github.com/gist/1137917/318569ae4f6748024fa9416271a012bb97e1f6e5/dpkg-homebrew), findutils, and gnu-tar packages from homebrew.
32 changes: 2 additions & 30 deletions bin/brew2deb
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
#!/usr/bin/env ruby
require 'optparse'
require 'fileutils'

formula = ARGV.find{ |arg| arg =~ /\.rb$/ and File.exists?(arg) }
formula ||= 'formula.rb'

unless File.exists?(formula)
STDERR.puts '*** No formula.rb found in the working directory'
exit(1)
end

Dir.chdir File.dirname(File.expand_path(formula))

if ARGV.include? 'clean'
FileUtils.rm_rf %w[ tmp-build tmp-install ], :verbose => true
exit
end

$:.unshift File.expand_path('../../lib', __FILE__)
require 'debian_formula'

Object.__send__ :remove_const, :HOMEBREW_CACHE
HOMEBREW_WORKDIR = Pathname.new(Dir.pwd)
HOMEBREW_CACHE = HOMEBREW_WORKDIR+'src'
FileUtils.mkdir_p(HOMEBREW_CACHE)

$:.unshift File.expand_path('.')
load formula

klass = File.read(formula)[/class (\w+)/, 1]
eval(klass).package!
require 'brew2deb'

Brew2Deb::CLI.run
20 changes: 20 additions & 0 deletions brew2deb.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'date'

Gem::Specification.new do |s|
s.name = 'brew2deb'
s.version = '0.0.0'
s.date = Date.today.to_s

s.summary = "homebrew + fpm = debian packages"
s.description = s.summary

s.authors = ['Aman Gupta']
s.email = 'aman@tmm1.net'
s.homepage = 'http://github.com/tmm1/brew2deb'

s.files = Dir['lib/**/*']
s.bindir = 'bin'
s.default_executable = 'bin/brew2deb'

s.add_dependency 'fpm'
end
2 changes: 1 addition & 1 deletion fpm/lib/fpm/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def generate_md5sums
def checksum(paths)
paths.collect do |path|
next if !File.exists?(path)
%x{find #{path} -type f -printf %P\\\\0 | xargs -0 md5sum}.split("\n")
%x{gfind #{path} -type f -printf %P\\\\0 | xargs -0 md5sum}.split("\n")
end.flatten
end # def checksum
end
4 changes: 2 additions & 2 deletions fpm/lib/fpm/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def tar(output, paths, chdir=".")

files_tar = [ tar_cmd ] \
+ excludes \
+ [ "--owner=root", "--group=root", "-rf", output ] \
+ [ "--owner=root", "-rf", output ] \
+ paths
::Dir.chdir(chdir) do
system(*files_tar)
Expand All @@ -139,7 +139,7 @@ def tar(output, paths, chdir=".")
def tar_cmd
# Rely on gnu tar for solaris.
case %x{uname -s}.chomp
when "SunOS"
when "SunOS", "Darwin"
return "gtar"
else
return "tar"
Expand Down
52 changes: 52 additions & 0 deletions lib/brew2deb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require 'fileutils'
require 'optparse'
require 'ostruct'
require 'tempfile'

require 'fpm'
require "fpm/program"

module Brew2Deb
def self.clean(env)
[env.build_dir, env.install_dir].each do |dir|
FileUtils.rm_rf dir, :verbose => env.verbose
end
end

def self.build(env)
load_hacks!(env)

formula = load_formula(env)

formula.package!(env)
end

def self.load_hacks!(env)
load_homebrew(env)
load_extensions
end

def self.load_homebrew(env)
Kernel.eval("::HOMEBREW_WORKDIR = Pathname.new('#{env.base_dir}')")
Kernel.eval("::HOMEBREW_CACHE = Pathname.new('#{env.cache_dir}')")

$:.unshift(env.homebrew_library_dir)
require 'global'
require 'formula'
end

def self.load_extensions
require 'brew2deb/ext/string'
require 'brew2deb/ext/formula'
require 'brew2deb/ext/debian_formula'
require 'brew2deb/ext/debian_source_formula'
end

def self.load_formula(env)
load env.formula
eval(File.read(env.formula)[/class (\w+)/, 1])
end
end

require 'brew2deb/cli'
require 'brew2deb/env'
72 changes: 72 additions & 0 deletions lib/brew2deb/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
module Brew2Deb
module CLI
def self.run(argv = ARGV)
options = {}

if argv.empty?
options[:formula] = 'formula.rb'
elsif argv.first !~ /^-/
options[:formula] = argv.shift
end

parse(options, argv)

env = Env.new(options)
Brew2Deb.send(env.action, env)
end

def self.parse(options, argv)
optparse = OptionParser.new do |opts|
opts.on('-a', '--architecture', 'i386 or amd64') do |arch|
options[:architecture] = arch
end

opts.on('-b', '--build', 'Build the formula (DEFAULT)') do
options[:action] = :build
end

opts.on('-c', '--clean', 'Clean the package.') do
options[:action] = :clean
end

opts.on('-d', '--dir DIR', 'Working directory. Defaults to pwd.') do |dir|
options[:base_dir] = Pathname.new(dir)
end

opts.on('-e', '--cache-dir DIR', 'Cache directory. Defaults to pwd/tmp-cache.') do |dir|
options[:cache_dir] = Pathname.new(dir)
end

opts.on('-f', '--formula FILE', 'The homebrew formula file.') do |file|
options[:formula] = file
end

opts.on('-i', '--install-dir DIR', 'Build directory. Defaults to pwd/tmp-install.') do |dir|
options[:install_dir] = Pathname.new(dir)
end

opts.on('-o', '--homebrew-dir DIR', 'Homebrew installation dir.') do |dir|
options[:homebrew_dir] = Pathname.new(dir)
end

opts.on('-p', '--package-dir DIR', 'Package directory. Defaults to pwd/pkg.') do |dir|
options[:package_dir] = Pathname.new(dir)
end

opts.on('-u', '--build-dir DIR', 'Build directory. Defaults to pwd/tmp-build.') do |dir|
options[:build_dir] = Pathname.new(dir)
end

opts.on('-t', '--output-dir DIR', 'Output directory. Defaults to pwd.') do |dir|
options[:output_dir] = Pathname.new(dir)
end

opts.on('-v', '--verbose') do
options[:verbose] = true
end
end

optparse.parse(argv)
end
end
end
42 changes: 42 additions & 0 deletions lib/brew2deb/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module Brew2Deb
class Env < OpenStruct
def self.defaults
{
:action => :build,
:architecture => 'i386',
:base_dir => Pathname.new(Dir.pwd),
:homebrew_dir => Pathname.new(File.dirname(__FILE__)) + 'vendor' + 'homebrew',
}
end

def self.new(attrs = {})
super(defaults.merge(attrs))
end

def build_dir
super || begin
base_dir + 'tmp-build'
end
end

def install_dir
super || begin
base_dir + 'tmp-install'
end
end

def homebrew_library_dir
homebrew_dir + 'Library/Homebrew'
end

def package_dir
super || begin
base_dir + 'pkg'
end
end

def output_dir
super || base_dir
end
end
end
Loading