Created
March 9, 2014 23:06
-
-
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!
This file contains hidden or 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
#!/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