Skip to content

Instantly share code, notes, and snippets.

@penguinpowernz
Last active August 29, 2015 14:09
Show Gist options
  • Save penguinpowernz/7f7706de4f00e7cc5b32 to your computer and use it in GitHub Desktop.
Save penguinpowernz/7f7706de4f00e7cc5b32 to your computer and use it in GitHub Desktop.
Convert a folder of source ruby gems into debs
# When in a folder with ruby gem source folders underneath it, running this will
# build each gem, install it and it's dependencies to a temporary folder and finally
# convert the gems and all it's dependencies into debian packages.
GEM_PREFIX = "/usr/lib/gems/2.1.4"
GEMS = ["redis_alerting", "rackdis"]
namespace :gems do
task :pkg do
puts "Building and install required gems to temp folder".bold.blue
FileUtils.rm_rf "/tmp/gems"
FileUtils.mkdir "/tmp/gems"
GEMS.each do |dir|
gemname = ""
FileUtils.chdir dir do
gemname = `rake build`.chomp.split("/").last[0..-2]
abort "Building #{dir} failed...".bold.red unless $?.success?
system "rake install >/dev/null"
abort "Installing #{dir} locally failed...".bold.red unless $?.success?
end
gempkg = "./#{dir}/pkg/#{gemname}"
abort "Couldn't find #{gempkg}!".bold.red unless File.exist? gempkg
system "gem install --no-ri --no-rdoc --install-dir /tmp/gems #{gempkg}"
abort "Installing gem to temp folder failed...".bold.red unless $?.success?
puts "* Built and installed #{dir} to tmp folder".bold.green
end
puts "\nConverting gems to debian packages...".bold.blue
Dir["/tmp/gems/cache/*.gem"].each do |pkg|
system "fpm --log error -f -a all -d ruby --prefix #{GEM_PREFIX} -s gem -t deb #{pkg} >/dev/null"
puts "* #{File.basename(pkg)} converted to debian package".bold.green if $?.success?
end
puts ""
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment