Skip to content

Instantly share code, notes, and snippets.

@natesymer
Created March 9, 2014 23:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natesymer/9456332 to your computer and use it in GitHub Desktop.
Save natesymer/9456332 to your computer and use it in GitHub Desktop.
A ruby rewrite of dpkg-scanpackages. It's faster, has no dependencies, and you can embed it into your Rails/Sinatra app!
#!/usr/bin/env ruby
require "digest/md5"
module DPKG
def self.control(deb_package_path)
return `ar p #{deb_package_path} control.tar.gz | tar -xzO`
end
class ScanPackages
def self.scan(path)
packages = Dir.entries(path).select{ |filename| filename =~ /.*\.deb/ }
controls = []
packages.each do |filename|
filepath = (path.length > 0 && path[-1] == "/" ? path : path+"/")+filename
control = DPKG.control(filepath)
control << "MD5sum: #{Digest::MD5.file(filepath)}\n"
control << "Size: #{File.size(filepath)}\n"
control << "Filename: #{filepath}\n"
controls << control
end
return controls.join("\n")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment