Created
July 4, 2013 02:39
-
-
Save claudijd/5924521 to your computer and use it in GitHub Desktop.
A quick and dirty tool for turning standalone scripts into a .deb package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helper for building Debian Packages on Ubuntu/Debian systems | |
require 'fileutils' | |
class DebPackager | |
def initialize(opts = {}) | |
@package_name = opts[:package_name] | |
@version = opts[:version] | |
@section = opts[:base] || "base" | |
@priority = opts[:priority] || "optional" | |
@arch = opts[:arch] || "all" | |
@maintainer = opts[:maintainer] || "Admin <admin@project.com>" | |
@description = opts[:description] | |
@files = opts[:files] | |
end | |
def build_root_exists? | |
Dir.exists?("debian") | |
end | |
def clean_build_root | |
FileUtils.rm_rf("debian") | |
end | |
def make_build_root | |
if build_root_exists? | |
return false | |
else | |
FileUtils.mkdir_p "./debian/usr/bin" | |
return true | |
end | |
end | |
def copy_files | |
@files.each do |file| | |
FileUtils.cp "#{file}", "./debian/usr/bin/#{file}" | |
end | |
end | |
def generate_control_file | |
"Package: #{@package_name}\n" + | |
"Version: #{@version}\n" + | |
"Section: #{@section}\n" + | |
"Priority: #{@priority}\n" + | |
"Architecture: #{@arch}\n" + | |
"Maintainer: #{@maintainer}\n" + | |
"Description: #{@description}" | |
end | |
def build_control_file | |
FileUtils.mkdir_p("./debian/DEBIAN") | |
ctrl_file = File.open("./debian/DEBIAN/control") | |
ctrl_file.write(generate_control_file) | |
end | |
def build_project | |
puts `fakeroot dpkg-deb --build debian` | |
FileUtils.mv "debian.rb" "#{@package_name}_#{@version}_all.deb" | |
end | |
end | |
dp = DebPackager.new( | |
:package_name => "testy", | |
:version => "1.1-1", | |
:description => "A test debian package" | |
:files => ["testy"] | |
) | |
dp.clean_build_root | |
dp.make_build_root | |
dp.copy_files | |
dp.build_control_file | |
dp.build_project |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment