Skip to content

Commit

Permalink
Workaround for buggy apt-cache search output.
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnall committed Oct 12, 2011
1 parent 75c8512 commit 2b6228a
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
v0.6.102. Workaround for buggy apt-cache search output.

v0.6.101. Install MRI 1.9.2+ instead of 1.8.7+ when available.

v0.6.100. Nginx configuration for Rails 3.1 asset pipeline.
Expand Down
4 changes: 2 additions & 2 deletions README
Expand Up @@ -26,10 +26,10 @@ application.
Life with +rails_pwnerer+:

1) Install a bootstrap version of ruby and rubygems (yes the order is correct):
sudo apt-get -y install rubygems ruby
sudo apt-get -y install ruby1.9.1

2) Install +rails_pwnerer+:
sudo gem install rails_pwnerer
sudo gem install rails_pwnerer make
(if it says gem not found, retry a couple of times)

3) Get your server production-ready:
Expand Down
5 changes: 3 additions & 2 deletions ext/rpwn_setup_notice/extconf.rb
Expand Up @@ -32,9 +32,10 @@ def openup(path)
openup base_path

# We really shouldn't be abusing rubygems' root. Then again, the Debian
# maintaines shouldn't be abusing the patience of Ruby developers.
# maintainers shouldn't be abusing the patience of Ruby developers.

# Now trick rubygems and echoe into believeing that a gem got installed is good.
# Now trick rubygems and echoe into believing that a gem got installed and
# everything is good.
ext_binary = 'rpwn_setup_notice' + (Gem.win_platform? ? '.dll' : '.so')
File.open(ext_binary, 'w') { |f| }
File.open('Makefile', 'w') do |f|
Expand Down
Empty file modified lib/rails_pwnerer/app/assets.rb 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion lib/rails_pwnerer/base/dirs.rb
Expand Up @@ -32,7 +32,7 @@ def current_user
# executes a block in a temporary directory
def with_temp_dir(options = {})
base_dir = if options[:root]
File.exists?('/tmp') ? '/tmp' : '/'
File.exists?('/tmp') ? '/tmp/' : '/'
else
'./'
end
Expand Down
23 changes: 18 additions & 5 deletions lib/rails_pwnerer/base/packages.rb
Expand Up @@ -200,9 +200,19 @@ def best_package_matching(patterns)
# Returns a hash where the keys are matching package names, and the values
# are version numbers.
def search_packages(pattern)
Hash[*(RailsPwnerer::Base.all_packages.select { |key, value|
packages = RailsPwnerer::Base.all_packages
Hash[packages.select { |key, value|
pattern.kind_of?(Regexp) ? (pattern =~ key) : key.index(pattern)
}.flatten)]
}.map { |key, value|
# apt-cache search sometimes leaves version numbers out
# Update the cache with version numbers.
if value.nil?
info = RailsPwnerer::Base.package_info_hash(
Kernel.`("apt-cache show #{key}"))
packages[key] = value = info['Version']
end
[key, value]
}]
end

# A hash of all the packages in the system, associated with their versions.
Expand All @@ -217,14 +227,17 @@ def self.all_packages
def self.all_packages_without_caching
output = Kernel.` "apt-cache search --full ."
versions = output.split("\n\n").map(&:strip).reject(&:empty?).map { |info|
info_hash = Hash[*(info.split(/\n(?=\w)/).
map { |s| s.split(': ', 2) }.
select { |kvp| kvp.length == 2 }.flatten)]
info_hash = package_info_hash info
[info_hash['Package'], info_hash['Version']]
}
Hash[*(versions.flatten)]
end

def self.package_info_hash(output)
Hash[output.split(/\n(?=\w)/m).map { |s| s.split(': ', 2) }.
select { |kvp| kvp.length == 2 }]
end

# Upgrades a package to the latest version.
def upgrade_package(package_name, options = {})
return install_package(package_name, options) if options[:source]
Expand Down
4 changes: 2 additions & 2 deletions test/base_package_test.rb
Expand Up @@ -15,7 +15,7 @@ def test_search_packages_with_string
def test_search_packages_with_regexp
packages = @base.search_packages /ruby.*\-dev/
assert_operator packages, :has_key?, 'ruby1.8-dev'
assert_operator packages, :has_key?, 'ruby1.9-dev'
assert_operator packages, :has_key?, 'ruby1.9.1-dev'
end

def test_best_package_matching
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_with_package_source
"Found package that no test system should have (#{package})"

source = 'http://ppa.launchpad.net/mactel-support/ppa/ubuntu'
repos = ['lucid', 'main']
repos = ['oneiric', 'main']
@base.with_package_source(source, repos) do
assert !(@base.search_packages(package).empty?),
"with_new_package_source didn't integrate the new source"
Expand Down

0 comments on commit 2b6228a

Please sign in to comment.